I need to print a list of "full" relative paths of all the files present in a directory and in its sub-directories. I used to do this with du and grep:
du -a <path_to_directory> | grep -Po '[0-9]+\t\/\K.*'
But du replaces part of the paths with dots if they are too long.
Which is a good alternative?
Parsing ls is not an option.
The most straightforward option would be
find
:It has various tests for filtering such as:
-type
to filter based on type (regular filef
, directoryd
, etc.)-mindepth
and-maxdepth
to set the depths to whichfind
should search (not really tests as such)-name
and-path
to filter based on filename and path, supporting wildcards.It offers a variety of output formats, using the
-printf
option.Depending on the shell and the options enabled, you can also use globbing for this purpose. For example, in
bash
:And in
zsh
: