Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit depth for recursive file list?

Tags:

linux

bash

Is there a way to limit the depth of a recursive file listing in linux?

The command I'm using at the moment is:

ls -laR > dirlist.txt 

But I've got about 200 directories and each of them have 10's of directories. So it's just going to take far too long and hog too many system resources.

All I'm really interested in is the ownership and permissions information for the first level subdirectories:

drwxr-xr-x 14 root   root  1234 Dec 22 13:19 /var/www/vhosts/domain1.co.uk   drwxr--r-- 14 jon    root  1234 Dec 22 13:19 /var/www/vhosts/domain1.co.uk/htdocs   drwxr--r-- 14 jon    root  1234 Dec 22 13:19 /var/www/vhosts/domain1.co.uk/cgi-bin   drwxr-xr-x 14 root   root  1234 Dec 22 13:19 /var/www/vhosts/domain2.co.uk   drwxr-xrwx 14 proftp root  1234 Dec 22 13:19 /var/www/vhosts/domain2.co.uk/htdocs   drwxr-xrwx 14 proftp root  1234 Dec 22 13:19 /var/www/vhosts/domain2.co.uk/cgi-bin   drwxr-xr-x 14 root   root  1234 Dec 22 13:19 /var/www/vhosts/domain3.co.uk   drwxr-xr-- 14 jon    root  1234 Dec 22 13:19 /var/www/vhosts/domain3.co.uk/htdocs   drwxr-xr-- 14 jon    root  1234 Dec 22 13:19 /var/www/vhosts/domain3.co.uk/cgi-bin   drwxr-xr-x 14 root   root  1234 Dec 22 13:19 /var/www/vhosts/domain4.co.uk   drwxr-xr-- 14 jon    root  1234 Dec 22 13:19 /var/www/vhosts/domain4.co.uk/htdocs drwxr-xr-- 14 jon    root  1234 Dec 22 13:19 /var/www/vhosts/domain4.co.uk/cgi-bin 

EDIT:

Final choice of command:

find -maxdepth 2 -type d -ls >dirlist 
like image 206
Jon Avatar asked Dec 22 '10 13:12

Jon


1 Answers

Checkout the -maxdepth flag of find

find . -maxdepth 1 -type d -exec ls -ld "{}" \; 

Here I used 1 as max level depth, -type d means find only directories, which then ls -ld lists contents of, in long format.

like image 101
Alberto Zaccagni Avatar answered Oct 20 '22 08:10

Alberto Zaccagni