ls not working??
Hi everyone,
I'm trying to get the ls command to echo out the directories in a directory while I'm working but I can't seem to get it right. For instance I'll be in /etc and I'll type ls -d and all I'll get is a "." . Then when I try ls -d /etc (which I don't want to do because I want to use it in whichever directory I am in) it just echo's the /etc directory. What am I doing wrong? |
The -d switch tells ls to print directories like regular files, not only print directories. I don't know offhand how to do that with ls, but one hackey way I came up with is:
ls -la | grep "^d" | awk '{ print $9 }' |
Thanks
Thanks, but that seems long winded. Is there another simple command that I can use to just display directories within a directory?
|
I am not aware of any ls option, that will list only directories.
You may consider following: ls -F | grep / -F inicates all directories with a slash as suffix also find . -type d -maxdepth 1 will list all directories if this is too much typing, then you can define an alias. e.g. alias lsdir=´ls -f|grep /´ so lsdir will list all subdirectories within the working directory. |
thanks
Thanks for the replies,
I liked the vlad-a idea of ls etc... it works the best. |
All times are GMT -5. The time now is 05:43 PM. |