Xcrowzz
Xcrowzz

Reputation: 192

Combining find and ls

I'm trying to use find or grep onto the LS output.

for now, ls -l is printing tons of informations. But I only want the user associated to a filename. And the filename might be greped

Upvotes: 0

Views: 2536

Answers (4)

Xcrowzz
Xcrowzz

Reputation: 192

I found the answer by myself but my way seems way more tricky. I was using :

tr -s ' ' | cut -d ' ' -f3,9 | grep " $1.*"  

But yours seems good. The thing is that the

find . -name "M*" -printf "%u %f\n"

also shows .git files. The topic is solved I guess, thanks for your consideration !

Upvotes: 0

rici
rici

Reputation: 241701

Most systems offer a stat command, which can easily produce whatever information you want about a file (or list of files). Unfortunately, the stat command is not standardized and the set of options vary considerably. For more information, read man 1 stat on your system.

On Linux, with GNU stat, you can use

stat -c%U file...

On BSD (including Mac OS X), you should be able to use

stat -f%Su file ...

(If you wanted the uid instead of the username, you would use -c%u or -f%u, respectively.)

Upvotes: 3

Gvim-Louu
Gvim-Louu

Reputation: 13

Consider adding a perl oneliner like this:

ll | grep user_u | perl -lane 'print "$F[2] $F[8]"'

-lane allow to slice the output using the space as separator, $F[2] and $F[8] are the slices of interest (first slice is $F[0])

Upvotes: -2

arco444
arco444

Reputation: 22821

Use find with the -printf flag:

find . -name "a*" -printf "%u %f\n"
find . -name "M*" -printf "%u %f\n"

From man find:

-printf format

%u File's user name, or numeric user ID if the user has no name

%f File's name with any leading directories removed (only the last element).

Upvotes: 6

Related Questions