1755056 Members
2809 Online
108829 Solutions
New Discussion юеВ

Directory Listing

 
SOLVED
Go to solution
oscar munoz_1
Occasional Contributor

Directory Listing

We want to list all files in a directory or file system by user and group. How do you do this?
5 REPLIES 5
RAC_1
Honored Contributor

Re: Directory Listing

find /dir_to_look_for -type f -user "user_name" -exec ll {} \;

find /dir_to_look_for -type f -group "group_name" -exec ll {} \;

Crude method

ll -R /dir|grep "user/group"

Anil
There is no substitute to HARDWORK
A. Clay Stephenson
Acclaimed Contributor

Re: Directory Listing

cd to the desired directory.

find . -user uname -print
OR
find . -group gname -print

If you need more detailed listings then your the -exec option.

e.g.

find . -user uname -type f -exec ls -l {} \;

This will recursively descend a file tree from the current directory and list the files.

Man find for details.
If it ain't broke, I can fix that.
G. Vrijhoeven
Honored Contributor
Solution

Re: Directory Listing

Hi,

You could use ls -als in combination with sort -k.
# ls -als /dir | sort -k


HTH,

Gideon
oscar munoz_1
Occasional Contributor

Re: Directory Listing

Gideon:
Your command is almost working but I get some users out of the group sort. I need the out put to be sorted by group as first priority and username by second priority.

I did a ls -als to the directory and looked at the out put and noticed the 5th field was group.
so I typed ls -als /dir |sort -k 5,5
USer name is 4th field.
G. Vrijhoeven
Honored Contributor

Re: Directory Listing

Hi again,

I do not have a UX box online to test it (so i am not sure if this works), but if you want to sort is first on user 4 Colomn and second on group 5 Colomn ( 1st prio) , you are allowed to use multiple -k strings:

ls -als /dir | sort -k 5,5 -k 4,4

Regards,

Gideon