I want to generate recursive file listings with full paths
/home/ken/foo/bar
but as far as I can see both ls
and find
only give relative path listings
./foo/bar (from the folder ken)
It seems like an obvious requirement but I can't see anything in the find
or ls
man pages.
If you give the find command an absolute path, it will spit the results out with an absolute path. So, from the Ken directory if you were to type:
find /home/ken/foo/ -name bar -print
(instead of the relative path find . -name bar -print)
You should get:
/home/ken/foo/bar
Therefore, if you want an ls -l and have it return the absolute path, you can just tell the find command to execute an ls -l on whatever it finds.
find /home/ken/foo -name bar -exec ls -l {} ;\
NOTE: There is a space between {} and ;
You'll get something like this:
-rw-r--r-- 1 ken admin 181 Jan 27 15:49 /home/ken/foo/bar
If you aren't sure where the file is, you can always change the search location. As long as the search path starts with "/", you will get an absolute path in return. If you are searching a location (like /) where you are going to get a lot of permission denied errors, then I would recommend redirecting standard error so you can actually see the find results:
find / -name bar -exec ls -l {} ;\ 2> /dev/null
(2> is the syntax for borne and bash shells, but will not work with c shell. It may work in other shells too, but I only know for sure that it works in bourne and bash).
I hope this helps!
gives the full absolute path. but if the file is a symlink, u'll get the final resolved name.
find / -print
will do this