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.
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