If you're using a reasonably new version of bash
, then you can generally use simple globbing
, with the new recursive globstar
pattern (**). Use printf
to format the output one-file-per-line.
shopt -s globstar dotglob nullglob
printf '%s\n' "$location"/**/ >"$outfile"
If you add a backslash to the end of a glob pattern, it matches directories only.
to include hidden files.
Use b instead of nullglob
if you want the command to error out if no match instead.
is supported from bash v.4+
, and there's currently one problem with it. If the file tree contains any recursive directory symlinks, it will get caught in an infinite loop and bog everything down. Other than that it should be very efficient.
also supports this pattern out of the box
(correction, you need to use set -G
to enable it), and zsh
probably does too, or something similar. I don't think they suffer from the above bug. Check their documentation though for full info on their available options.
An added benefit of globbing patterns is that you can also process them directly with a for loop
, if you intend to do more with the files than just save their names.
PS: Please use ***[code][/code]
*** tags around your code and data, to preserve the original formatting and to improve readability. Do not
use quote tags, bolding, colors, "start/end" lines, or other creative techniques. Thanks.