The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Want to Get List of All directories niceboykunal123 Shell Programming and Scripting 6 05-06-2008 11:58 AM
help with script to list directories chassis Shell Programming and Scripting 2 09-13-2006 10:17 AM
how to list directories only yodadbl07 UNIX for Dummies Questions & Answers 3 04-26-2006 01:48 AM
How to list only directories? videsh77 UNIX for Dummies Questions & Answers 4 01-09-2006 06:10 AM
List directories malaymaru UNIX for Dummies Questions & Answers 3 09-25-2005 06:54 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-17-2005
Registered User
 

Join Date: Mar 2005
Posts: 11
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
list only directories in commandline.

I want to list only directories in the command line using ls command. Can anyone please help me.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-17-2005
Registered User
 

Join Date: Jan 2005
Posts: 678
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
ls -l | grep ^d
Reply With Quote
  #3 (permalink)  
Old 03-17-2005
Registered User
 

Join Date: Mar 2005
Posts: 11
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Thanks. Please find the display below.

/home/gsk/prod> ls -l | grep ^d

drwxrwxr-x 2 gsk stage 96 Mar 17 14:01 0010
drwxrwxr-x 2 gsk stage 96 Mar 17 14:01 0011
drwxrwxr-x 2 gsk stage 96 Mar 17 14:01 0014

But i need to extract only the last column i.e. only the folder names. Please let me know what i need to do. I used cut utility but i can't able to locate the column. Is there any utility which will extract the last column of the display.

TIA.
Reply With Quote
  #4 (permalink)  
Old 03-17-2005
Registered User
 

Join Date: Jan 2005
Posts: 678
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by jhmr7
But i need to extract only the last column i.e. only the folder names. Please let me know what i need to do. I used cut utility but i can't able to locate the column. Is there any utility which will extract the last column of the display.
Code:
ls -l | grep ^d | awk '{print $9}'
Reply With Quote
  #5 (permalink)  
Old 03-17-2005
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,407
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
or
Code:
ls -l | awk '/^d/ {print $9}'
Reply With Quote
  #6 (permalink)  
Old 03-17-2005
Registered User
 

Join Date: Mar 2005
Posts: 11
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Thanks a lot guys. Your help is much appreciated.
Reply With Quote
  #7 (permalink)  
Old 03-18-2005
Registered User
 

Join Date: Mar 2005
Posts: 63
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
How about as an alias in .cshrc ?

I've put this line as an alias in .cshrc:

alias dirlist ls -l | awk '/^d/ {print $9}'

but I get this:

netmin@kenny:/home/netmin-->> dirlist
drwx------ 5 netmin netmin 512 Mar 13 04:26 Maildir
drwxr-xr-x 2 netmin netmin 512 Mar 15 18:30 bin
drwxr-xr-x 2 netmin netmin 512 Mar 15 18:00 cdrom
drwxr-xr-x 2 netmin netmin 512 Mar 15 07:37 conf
drwxr-xr-x 2 netmin netmin 512 Mar 12 09:50 doc
drwx------ 2 netmin netmin 512 Mar 13 12:43 mail
drwxr-xr-x 4 netmin netmin 512 Mar 13 20:16 mailconf

What do I need to do to get the {print $9} to take ?
Thanks in advance.

Jolok
Reply With Quote
  #8 (permalink)  
Old 03-18-2005
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,407
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
alias dirlist ls -l \| awk \'\/\^d\/\{print\ \$9\}\'
Reply With Quote
  #9 (permalink)  
Old 03-18-2005
Registered User
 

Join Date: Mar 2005
Posts: 63
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Ah, character escapes....

That's great! Thanks for the solution!

Jolok
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101