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
Here's an example that prints out a list without an extra period and that also demonstrates how to search for a file match. Hope this helps:
find . -type f -name "extr*" -exec echo `pwd`/{} \; | sed "s|\./||"
Most if not all of the suggested methods result in paths that cannot be used directly in some other terminal command if the path contains spaces. Ideally the results will have slashes prepended. This works for me on macOS:
find / -iname "*SEARCH TERM spaces are okay*" -print 2>&1 | grep -v denied |grep -v permitted |sed -E 's/\ /\\ /g'
readlink -f filename
gives the full absolute path. but if the file is a symlink, u'll get the final resolved name.
You can use
find $PWD
in bash
ls -1 | awk -vpath=$PWD/ '{print path$1}'
Use this for dirs (the /
after **
is needed in bash to limit it to directories):
ls -d -1 "$PWD/"**/
this for files and directories directly under the current directory, whose names contain a .
:
ls -d -1 "$PWD/"*.*
this for everything:
ls -d -1 "$PWD/"**/*
Taken from here http://www.zsh.org/mla/users/2002/msg00033.html
In bash, **
is recursive if you enable shopt -s globstar
.