4

Is there a way to display all the information that -l does in ls (permissions, dates, etc.) when using the locate or find commands?

4 Answers4

7

Not just for "ls -l" but for whatever action you'd want to perform to your locate or find results you can use xargs or in the case of find the -exec flag. Here are examples to achieve what you want to do:

In the case of locate you can use xargs:

locate something | xargs ls -l

Xargs can be used for find too, but find has the -exec flag that allow to optimize further actions with find results; for example

find . -iname something -exec ls -l '{}' \;
hmontoliu
  • 3,793
  • This is the more general approach compare to mine. But I would generally recommend to use xargs for find as well, as it handles large result sets better (-exec spawns a new process for every file while xargs groups them to create as few processes as possible). – Sven Aug 05 '11 at 15:52
  • When find returns a huge amount of lines you might have problems to buffer all of them. Also with -exec you process the result as soon as it appears and you don't have to wait the end of the find process to start the xargs part. – hmontoliu Aug 05 '11 at 15:55
  • 2
    if execing things I find it better to use + e.g. find . -exec ls -l '{}' +. This reduces the number of calls to exec as + puts many of the files found on one command line. – user9517 Aug 05 '11 at 16:04
  • xargs starts working as soon as it has enough data. – Sven Aug 05 '11 at 16:05
  • Awesome - this is exactly what I wanted to know and am going to go learn more about xargs. Thanks! – Ryan Jurgensen Aug 05 '11 at 16:20
  • Watch out if something matches a directory then the ls -l prints the contents of the directory too ;) – user9517 Aug 05 '11 at 16:23
3

I am not sure what you want to do, but try

find . -ls 
Sven
  • 99,533
  • 15
  • 182
  • 228
1

You can use -printf and a suitable format string

 find ./ -printf "%M\t%n\t%u\t%g\t%s\t%t%f\n"
  • %M Symbolic permissions
  • %n hard links
  • %u username or numeric user id
  • %g group name or numeric group id
  • %s file size in bytes
  • %t last modification time
  • %f filename
user9517
  • 116,228
0

One more option:

find | while read a; do ls -l "$a"; done
feklee
  • 505