There must be a simple command that asks for a list of all the subdirectories of whatever directory you are in, but I don’t know it or how to find it. I can get a listing of all the files but I cannot tell which of them (if any) is a subdirectory.
Would “ls -l . | grep ^d” work for what you need?
Missed edit window, but if you want just the names and not the rest of the ls -l output, you can append “| awk ‘{print $NF}’” to that.
ls -d */
Only if you want to do it the easy way. :smack:
That is a good one. It will find all of the non-hidden directories (ones that don’t start with a “.”). A more general solution might be
find ./ -type d
which will show all of the subdirectories and subdirectories of subdirectories. Verbosly: find all files of the type directory (in Unix, everything is a file) starting at the current directory “./”. You can leave out the “./”, as starting at the current directory is default, but my fingers automatically type it, because they learned the command on a system where it was required.
To only show the first level of subdirectories, you can use
find ./ -maxdepth 1 -type d
“find” is incredibly useful and powerful, but with great power comes great complexity.
If you only want to be able to distinguish between regular files and directories, then here are a couple good options:
ls -CF
ls -l
The first will just list names, but it will show directory names with a “/” after them. The second will list more details, such as permissions and owners. Directories will have a “d” as the first letter in the first column.
In general, if you know the generic command, ls in this case, man’ing that command will often give you the way to do what you want. You’re hardly the first person to want to see directories only. The same goes for nearly anything you’d want to do as a novice.
If not, you can strong a couple of commands together to do it.
Color-coded ls is nice if your operating system and terminal support it. For example, under Linux “ls --color” (or ls -Fa --color", etc) will list all files color-coded by type.
Thanks. Worked fine. No need for more complicated solutions.
TSD scores again!