3 ms·
As others have noted, awk is great for one-liners. Just minutes ago, I wanted to find out what users and groups own all of the files within a certain deep dire
by rootbear 12y ago
As others have noted, awk is great for one-liners. Just minutes ago, I wanted to find out what users and groups own all of the files within a certain deep directory tree (on linux). I did this:
$ ls -lR | awk '{ print $3, $4 }' | sort -u > user_group_list
and got the list I wanted. (Yes, it's sloppy but I don't care, as it's just a one-off.)
- a3_nm 12y agoI also do this, but the right way to parse the output of ls would really be to remember the syntax of stat(1). That way you avoid any trouble with spaces and other such problems, and the command is not much longer: $ find -print0 | xargs -0 stat -c "%U %G" | sort -u > user_group_list
- rootbear 12y agoNice! I though for a minute about using find, but I didn't know about those options to stat, and I just punted and used ls. I need to study the stat man page, apparently.
- babarock 12y agoYou kinda alluded to it, but I'm going to leave this here for reference. Here's a good explanation of why you should avoid parsing the output of `ls`: http://mywiki.wooledge.org/ParsingLs http://mywiki.wooledge.org/ParsingLs
- Erwin 12y agofind (or maybe just GNU find) has the equivalent of stat built in so you can even do: find -printf "%u %g\n"|sort|uniq -c