1754973 Members
3402 Online
108828 Solutions
New Discussion юеВ

ls -l with AWK/grep

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

ls -l with AWK/grep

Hi,

I'm wanting to obtain the list of files/directories within several filesystems, i.e traversing just 1 level into the paths of these filesystems, and getting only the files/directories belonging to a particular project group within these filesystems.

Could anyone help me on this matter? I tried doing:
df -k|grep wmt

which only list filesystems having wmt within the file name.
I also did :
ls -l|grep wmt

which also list filesystems having wmt within the file name.

I would like to list the names of the files within a filesystem belonging to the group owner "wmt", not files having "wmt" as its substring.

Could some one help me out?
Thanks.


4 REPLIES 4
Rainer von Bongartz
Honored Contributor
Solution

Re: ls -l with AWK/grep


What about:

find . -group -exec ls -l {} \;

Regards
Rainer
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Frederic Sevestre
Honored Contributor

Re: ls -l with AWK/grep

Hi,

You should use find :

# cd
# find . -type f -group wmt -exec ls -l {} \;

Fr??d??ric
Crime doesn't pay...does that mean that my job is a crime ?
Frederic Sevestre
Honored Contributor

Re: ls -l with AWK/grep

Hi,

In addition, if you want to search within a filesystem :

# find . -type f -group wmt -xdev -exec ls -l {} \;

The xdev option will causes find to avoid crossing any file system mount points.

Fr??d??ric



Crime doesn't pay...does that mean that my job is a crime ?
Jonathan Baker
Advisor

Re: ls -l with AWK/grep

If you really want to just go down 1 level only, a script like the following might help.
for i in `ls`
do
if [ -d $i ]; then
ls -l $i | awk '{if ( $3 ~ /owner/ ) {print}}'
fi
done

You can substitute the `ls` for a list of directories if you wish. The script as above will list all files owned by owner. If you used $4, it will list by group