Originally Posted by FromFPan2Fire
For another example, I know I have files in a subdirectory beginning with W; But when I do "ls -R W* " it says No Such File or Directory; If I do ls -R then I can see files starting with W.
Actually, it's the shell (ie Bash) that expands the "W*" to the names of all files/directories in the current
directory that start with "W", prior to passing the expansion result to "ls".
So, let's say I have, in my current directory:
W3 - a subdirectory
Than, "ls W*", will actually be performed as "ls W1.txt W2.txt W3" ("ls" gets 3 input parameters, not just the 'W*').
Following this idea, then you can't locate files with names starting with W in all subdirectories by
As this is performed as follows:
1. The shell expands "W*" to all names of files/directories IN THE CURRENT DIRECTORY that have names starting with "W". If there aren't any, you'll get "No such file or directory".
2. If the shell did find some files/directories with W, it'll pass them all to "ls" as input parameters.
3. "ls -R" is performed for each of the parameters "ls" gets from the shell (if there are any).
To find all files starting with W in a recursive way (ie in the current directory and all subdirectories), you
need to use "find", not "ls". Example:
You may add "-type f" option to find to restrict the output to regular files (ie no directories, symbolic links, fifo pipes, device files, etc).
"-maxdepth n" restricts the number of recursively searched levels to "n".
For more details on "find" and "ls", please read their respective man pages.