LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-04-2004, 05:37 AM   #1
samills70
Member
 
Registered: May 2004
Posts: 32

Rep: Reputation: 15
Question 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?
 
Old 06-04-2004, 06:02 AM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,275

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
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 }'
 
Old 06-04-2004, 06:12 AM   #3
samills70
Member
 
Registered: May 2004
Posts: 32

Original Poster
Rep: Reputation: 15
Thanks

Thanks, but that seems long winded. Is there another simple command that I can use to just display directories within a directory?
 
Old 06-04-2004, 11:52 AM   #4
Vlad-A
Member
 
Registered: May 2004
Location: Vienna, Austria
Distribution: Open SuSE 11, Mac OS X 10.5
Posts: 299

Rep: Reputation: 33
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.
 
Old 06-09-2004, 08:27 AM   #5
samills70
Member
 
Registered: May 2004
Posts: 32

Original Poster
Rep: Reputation: 15
thanks

Thanks for the replies,

I liked the vlad-a idea of ls etc... it works the best.

Last edited by samills70; 06-09-2004 at 08:29 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Intel sound not working, usb modem not working. siriusb Linux - Hardware 8 03-04-2006 11:16 PM
After Online update: Hard drive working and working dacosta SUSE / openSUSE 6 11-06-2004 01:14 AM
F1 - F10 not working when F13 - F20 working in Linux haivinay Linux - General 0 09-20-2004 08:31 AM
Link/Applet not working in all Linux browsers, but working in IE MasterPatricko Linux - Software 6 09-04-2004 04:39 AM
cannot download files in mozilla -save dialog not working, galeon not working cmisip Linux - General 0 08-03-2003 04:25 PM


All times are GMT -5. The time now is 07:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration