I am trying to get a list of paths of all subdirectories (recursively) which have some specified name, e.g. "bin"
. The problem is that if current directory contains subdirectory of that name, DIR command will be executed only within that subdirectory, ignoring other subdirectories.
Example:
C:\DEVELOPMENT\RESEARCH>ver
Microsoft Windows [Version 6.1.7601]
C:\DEVELOPMENT\RESEARCH>dir *bin* /ad /s /b
C:\DEVELOPMENT\RESEARCH\bin
C:\DEVELOPMENT\RESEARCH\Apache\2bin
C:\DEVELOPMENT\RESEARCH\Apache\bin
C:\DEVELOPMENT\RESEARCH\Apache\bin1
C:\DEVELOPMENT\RESEARCH\C#\ConsoleApps\MiscTests\bin
C:\DEVELOPMENT\RESEARCH>dir bin* /ad /s /b
C:\DEVELOPMENT\RESEARCH\bin
C:\DEVELOPMENT\RESEARCH\Apache\bin
C:\DEVELOPMENT\RESEARCH\Apache\bin1
C:\DEVELOPMENT\RESEARCH\C#\ConsoleApps\MiscTests\bin
C:\DEVELOPMENT\RESEARCH>dir bin /ad /s /b
C:\DEVELOPMENT\RESEARCH\bin\test
C:\DEVELOPMENT\RESEARCH>rmdir bin /s /q
C:\DEVELOPMENT\RESEARCH>dir bin /ad /s /b
C:\DEVELOPMENT\RESEARCH\Apache\bin
C:\DEVELOPMENT\RESEARCH\C#\ConsoleApps\MiscTests\bin
C:\DEVELOPMENT\RESEARCH>
dir *bin* /ad /s /b
outputs all subdirectories that have bin
in their name. And this output is ok. Same with dir bin* /ad /s /b
which outputs all subdirectories which name begins with bin
. But dir bin /ad /s /b
outputs only the content of the first child of the current directory which has name bin
. Desired output is:
C:\DEVELOPMENT\RESEARCH\bin
C:\DEVELOPMENT\RESEARCH\Apache\bin
C:\DEVELOPMENT\RESEARCH\C#\ConsoleApps\MiscTests\bin
How can I achieve this?
NOTE: If current directory does not contain bin
child, output is as expected. (I deleted bin
child to show this)
By default, ls lists just one directory. If you name one or more directories on the command line, ls will list each one. The -R (uppercase R) option lists all subdirectories, recursively.
Try any one of the following commands to see recursive directory listing: ls -R : Use the ls command to get recursive directory listing on Linux. find /dir/ -print : Run the find command to see recursive directory listing in Linux. du -a . : Execute the du command to view recursive directory listing on Unix.
To Search Subdirectories To include all subdirectories in a search, add the -r operator to the grep command. This command prints the matches for all files in the current directory, subdirectories, and the exact path with the filename.
This should work:
for /R /D %A in (*bin*) do echo %A
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With