I want to get the full path of all files in a directory and and the entire path has to be saved in one text file. Can you give me the script for that?


GNU coreutils contains the realpath program that returns the full path for each argument. The following program prints the full name of all files in the current directory (not expanding symlinks, -s; not recursive):

realpath -s *

Depending on your shell, hidden dot-files will not get expanded. For that, you also need to execute shops -s dotglob.


You should use readlink (available in GNU coreutils):

readlink - print resolved symbolic links or canonical file names


readlink -f <file-name>

The shell variable PWD contains the full path to the current directory.

You can use printf '%s\n' to print a list of strings with a newline after each string.

printf '%s\n' "$PWD"/* >somefile.txt

The wildcard pattern * excludes dot files (files whose name begins with a .). If there are dot files, you can use printf '%s\n' "$PWD"/.* "$PWD"/* >somefile.txt; note that this also lists . and ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.