GagA// 0n D nEt

It is currently Tue Aug 21, 2018 10:15 pm

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Linux: List directories only
PostPosted: Fri Jun 26, 2009 5:32 am 

Joined: Wed Jul 18, 2007 1:14 am
Posts: 181
There are times when you need to list directories in a certain directory which contains thousands of files.

We end up using the long list option of the ls command with some tweaking courtesy grep. Something like the following:
[[email protected] public_html]# ls -l | grep ^d

This gives us the output of the folder list but in a long listig format. We again have to tweak the command further using awk if we wish to get the output in the form of folder names only.

I could find an option for that using the -d option for the ls command.

The following is what can get the desired output for you:
[[email protected] public_html]# ls -d */

Documents/   Music/   Nagios/   Pictures/   Templates/   Videos/   JBoss/   mv/   Photos/   Public/   Temp/

You can also get the list of hidden folders (the one starting with ".") using the above command but with some modifications:
[[email protected] public_html]# ls -d .*/

You can combine the -1 option with the above commands in case you want the output in per line format.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group