How To View Or List Only Directories In Linux?


How to view/list only directories in Linux?
Ans :
This can be achieved in two ways
1. Through ls command
2. Through find command

With ls we have to use grep to get the directory listings.
Ls –l grep ^d

Example :
[root@test surendra_a]# ls -l grep ^d
d--------- 2 surendra_a surendra_a 4096 Sep 8 09:54 HTWFAIP
drwxrwxr-x 2 surendra_a root 4096 Nov 27 12:30 LinuxCBT - RHEL5
drwxrwxr-x 2 surendra_a root 4096 Oct 12 16:40 Software
[root@test surendra_a]#

With find we can have more controle on how to display only directories.

A. To display all the directories and sub-directories in present directory
#find . -type d

B. Displaying only directories in present directory
#find /root/ -type d –maxdepth 1

C. Displaying just directories in present directry and its sub-directories
#find /root/ -type d –maxdepth 2

  • Like the post? Please Subscribe to free RSS feed to get updates
  • Related Posts by Categories



    0 comments:

    Archive

    Translate this page

     

    The Linux Juggernaut | Copyright 2006-2009 Surendra Kumar Anne | Surendra's Home Page | Give us feedback how we are doing, Click here