I am writing a shell script that takes file paths as input.
For this reason, I need to generate recursive file listings with full paths. For example, the file bar has the path:
/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.
How can I generate a list of files in the shell including their absolute paths?
If you give
findan absolute path to start with, it will print absolute paths. For instance, to find all .htaccess files in the current directory:or if your shell expands
$PWDto the current directory:findsimply prepends the path it was given to a relative path to the file from that path.Greg Hewgill also suggested using
pwd -Pif you want to resolve symlinks in your current directory.