LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ls not working?? (https://www.linuxquestions.org/questions/linux-newbie-8/ls-not-working-189582/)

samills70 06-04-2004 04:37 AM

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?

btmiller 06-04-2004 05:02 AM

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 }'

samills70 06-04-2004 05:12 AM

Thanks
 
Thanks, but that seems long winded. Is there another simple command that I can use to just display directories within a directory?

Vlad-A 06-04-2004 10:52 AM

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.

samills70 06-09-2004 07:27 AM

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 08:42 AM.