Using a shell loop:
for dir in */; do
{ printf '%s\n' "$dir"
( cd "$dir" && find . )
} >"$dir/original_filenames.txt"
done
This iterates over all subdirectories in the current directory. The body of the loop outputs the name of the directory, and then a list of all files and directories, recursively, in that directory. This output goes to the original_filenames.txt
file in the directory.
Shorter:
for dir in */; do
find "$dir" >"$dir/original_filenames.txt"
done
This gives slightly different output in that the pathnames that are written to the file all start with the name of the subfolder.
If you're uninterested in directory names and just want pathnames of the regular files, use find
with -type f
after the directory name.
Note that if you're planning on using the generate output files for anything, then this will fail (or at least be very problematic) if any of the found pathnames contain newlines (which is entirely possible on a Unix system).
#!/bin/bash; for dir in */ ; do ; tree -s "$dir">"$dir/original_filenames.txt"; done
– Murgatroyd May 30 '18 at 19:24