Skip to main content
deleted 500 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
find Test -type d -name '???' -exec basename {} \;

This would find all directories in or under Test that has names consisting of exactly three characters. For each such directory, basename is called to compute the filename portion of the pathname. Add -maxdepth 1 if you want to avoid going into deeper subdirectories (note that I don't know whether find on AIX supports this option).

AnotherA simple shell loop solution would be to simply do

for pathname in Test/???/; do
    printf '%s\n' "$( basename "$pathname" )"
done

This would print each subdirectory name that matches the given pattern (or names of symbolic links to subdirectories).

Depending on what you then want to do to these names, you would use either of these solutions, but ifIf you want to do anything other than listing the names, then you would do something like

for pathname in Test/???/; do
    # some code using "$pathname" here
done

I.e., you would not first generate the list and then iterate over it.

find Test -type d -name '???' -exec basename {} \;

This would find all directories in or under Test that has names consisting of exactly three characters. For each such directory, basename is called to compute the filename portion of the pathname. Add -maxdepth 1 if you want to avoid going into deeper subdirectories (note that I don't know whether find on AIX supports this option).

Another solution would be to simply do

for pathname in Test/???/; do
    printf '%s\n' "$( basename "$pathname" )"
done

This would print each subdirectory name that matches the given pattern (or names of symbolic links to subdirectories).

Depending on what you then want to do to these names, you would use either of these solutions, but if you want to do anything other than listing the names, then you would do something like

for pathname in Test/???/; do
    # some code using "$pathname" here
done

I.e., you would not first generate the list and then iterate over it.

A simple shell loop solution would be to do

for pathname in Test/???/; do
    printf '%s\n' "$( basename "$pathname" )"
done

This would print each subdirectory name that matches the given pattern (or names of symbolic links to subdirectories).

If you want to do anything other than listing the names, then you would do something like

for pathname in Test/???/; do
    # some code using "$pathname" here
done

I.e., you would not first generate the list and then iterate over it.

added 21 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
find Test -type d -name '???' -exec basename {} \;

This would find all directories in or under Test that has names consisting of exactly three characters. Add For each such directory, basename is called to compute the filename portion of the pathname. Add -maxdepth 1 if you want to avoid going into deeper subdirectories (note that I don't know whether find on AIX supports this option).

Another solution would be to simply do

for pathname in Test/???/; do
    printf '%s\n' "$( basename "$pathname" )"
done

This would print each subdirectory name that matches the given pattern (or names of symbolic links to subdirectories).

Depending on what you then want to do to these names, you would use either of these solutions, but if you want to do anything other than listing the names, then you would do something like

for pathname in Test/???/; do
    # some code using "$pathname" here
done

I.e., you would not first generate the list and then iterate over it.

find Test -type d -name '???'

This would find all directories in or under Test that has names consisting of exactly three characters. Add -maxdepth 1 if you want to avoid going into deeper subdirectories (note that I don't know whether find on AIX supports this option).

Another solution would be to simply do

for pathname in Test/???/; do
    printf '%s\n' "$( basename "$pathname" )"
done

This would print each subdirectory name that matches the given pattern (or names of symbolic links to subdirectories).

Depending on what you then want to do to these names, you would use either of these solutions, but if you want to do anything other than listing the names, then you would do something like

for pathname in Test/???/; do
    # some code using "$pathname" here
done

I.e., you would not first generate the list and then iterate over it.

find Test -type d -name '???' -exec basename {} \;

This would find all directories in or under Test that has names consisting of exactly three characters. For each such directory, basename is called to compute the filename portion of the pathname. Add -maxdepth 1 if you want to avoid going into deeper subdirectories (note that I don't know whether find on AIX supports this option).

Another solution would be to simply do

for pathname in Test/???/; do
    printf '%s\n' "$( basename "$pathname" )"
done

This would print each subdirectory name that matches the given pattern (or names of symbolic links to subdirectories).

Depending on what you then want to do to these names, you would use either of these solutions, but if you want to do anything other than listing the names, then you would do something like

for pathname in Test/???/; do
    # some code using "$pathname" here
done

I.e., you would not first generate the list and then iterate over it.

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

find Test -type d -name '???'

This would find all directories in or under Test that has names consisting of exactly three characters. Add -maxdepth 1 if you want to avoid going into deeper subdirectories (note that I don't know whether find on AIX supports this option).

Another solution would be to simply do

for pathname in Test/???/; do
    printf '%s\n' "$( basename "$pathname" )"
done

This would print each subdirectory name that matches the given pattern (or names of symbolic links to subdirectories).

Depending on what you then want to do to these names, you would use either of these solutions, but if you want to do anything other than listing the names, then you would do something like

for pathname in Test/???/; do
    # some code using "$pathname" here
done

I.e., you would not first generate the list and then iterate over it.