I want to grep the output of my
ls -l command:
-rw-r--r-- 1 root root 1866 Feb 14 07:47 rahmu.file -rw-r--r-- 1 rahmu user 95653 Feb 14 07:47 foo.file -rw-r--r-- 1 rahmu user 1073822 Feb 14 21:01 bar.file
I want to run
grep rahmu on column $3 only, so the output of my
grep command should look like this:
-rw-r--r-- 1 rahmu user 95653 Feb 14 07:47 foo.file -rw-r--r-- 1 rahmu user 1073822 Feb 14 21:01 bar.file
What's the simplest way to do it? The answer must be portable across many Unices, preferably focusing on Linux and Solaris.
NB: I'm not looking for a way to find all the files belonging to a given user. This example was only given to make my question clearer.
lsis inherently fragile (think what happens if a user name contains whitespace — and yes, this happens on some platforms). Use
statmay come in handy in places where you might otherwise consider parsing
ls. But usually,
findis what you want (as @Gilles mentioned).