ls to view directories only
Hi. I realise that the answer to this question is probably in the man page, but I seem to be incapable of finding it!
I would like to use the 'ls' command to display directories only. (Equivalent of MSDOS 'dir /ad') I've tried: ls -d * ls --directory * ls -ldR * together with various combinations of the above. Nothing I have tried seems to give me what I want, and I am starting to get a little frustrated. Please put me out of my misery!... |
What is your current working directory? Are there any subdirectories in the current working directory?
Have you tried the command without the * |
|
Thanks for replying. I'm in my home directory, and I do have sub-directories. I've tried with and without the '*'.
The only results I seem to be able to get are either a complete listing including subdirectories and files, or just the current directory, '.' ls -d ls -dR ls -dr ls --directory -R ls --directory -r ls --directory all just return '.' |
Thanks, LinuxLaLa. I appear to have been mixing up directories with directory entries...
For anybody else who may be interested, tree -d gives the same results. A bit simpler than all that 'grep' malarky! |
Cool. Thanks for sharing with us all.
Cheers. |
is this what you want?
Code:
ls -d */ |
Code:
|
you can put loads of "*/" together like so to go deeper:
Code:
> ls -1d ileaf/*/*/ billy |
Spot on. Thanks, bigearsbilly.
|
The problem is that is gives the full path of the folder with ls -d1
:( Quote:
:( |
confused
Quote:
[norm@localhost ~]$ ls -d */ bin// Dropbox// Movies// playground// tmp// Desktop// FAH6.02-Linux// MP3// pyNeighborhood// Videos// Documents// Linux Cookbook - allfreeebook.tk// Music// smb4k// work// Downloads// lmms// Pictures// Templates// then cd MP3 [norm@localhost MP3]$ ls -d */ ls: invalid option -- '=' Try `ls --help' for more information. [norm@localhost MP3]$ |
Keep in mind that it's really your shell that is expanding that "*/" to a list of directories that is then seen by ls. What is probably happening is that your MP3 directory has a subdirectory with a name beginning with '-', and ls tries to process that entire name as a set of flag arguments. Try this:
Code:
ls -d -- */ |
Quote:
The offending directory is appropriate -----> -=A3-Sopranos Soundtrack=-// You're absolutely right! Do I understand you to mean [norm@linux-2 ~]$ ls -l -a # aaaah! I see how the -=A3Sopranos would get expanded by bash total 10492 drwx------ 79 norm norm 4096 Jul 17 14:06 ./ ls -d */ shell expands */ to all lines ending in / then passes it all to ls -d -=A3Sopranos BUT -=A3Sopranos is not the first entry so ls must be checking to see if it can list EVERYTHING without errors before ANYTHING is sent to stdout ie display. Is that right? HOWTO Train Brain to expand like Bash! |
As rknichols said, when you type that cmd, bash is expanding the wildcard, then passing to ls.
The only way to think like bash is practice... ;) Try these for ref http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
All times are GMT -5. The time now is 10:54 AM. |