Recursively list full absolute path of files with permissions in Linux
I have done a bit of searching online, and I am trying to find a way to recursively list all files with their absolute path and with their permissions. I want to do this so that I can grep
out what I want, so that when I run the command, I can get just the matching files, their permissions, and their full paths, like:
<search command> | grep file.name
Output:
/home/current/Desktop/file.name
/etc/program/src/file.name
I would prefer to use ls
because it is the fastest, and I would type:
ls -alR $PWD/
But this doesn't show the file's path, so if I grep
'ed the output, then I would see file permissions, but not the directory from which it originated.
I can use ls
integrated with find
and grep
to get the output in exactly the format that I want, and I could use something like this:
ls -ault `find $PWD/ -type f` | grep file.name
But this is extremely slow, I'm guessing because two commands are actually running.
If I just use find
without ls
or grep
, then it goes faster, but it is a bunch to type:
find $PWD/ -type f -name file.name -printf '%M %u %g %s\t%a\t%p\r\n'
This will give me a nice format (It also includes the user, group, size, and last date of access, which are helpful). However, it is a ton to type, and it is certainly not as fast as using ls
with grep
.
Is there a faster way to do what I am trying to do than to use find
?
Solution 1:
Rather than ls
or find
you may try tree
. Specifically tree -ifpugDs $PWD
should give you what you would like.
-if
removes indentation lines and prints out path
-p
prints permissions
-ug
prints user and group
-D
prints modification time
-s
prints size
Solution 2:
If typing it is a problem, what about putting what you already have in a function:
myspecialfinder() {
find $PWD/ -type f -name "$1" -printf '%M %u %g %s\t%a\t%p\r\n'
}
You would use it as
myspecialfinder file.name
Solution 3:
Simple answer: find -type f -print0 | xargs -0 ls -al