I need to create a manifest of thousands of files and their directory paths recursively.

Here is an example of how i need the manifest to output

This_is_an_example/of_how/i_want_to_display/absolute_paths/
examplefiles.md5
examplefiles.txt
examplefile.wav

This_is_an_example/of_how/i_want_to_display/absolute_paths/part_2/
examplefiles.md5
examplefiles.txt
examplefile.wav

the command tree -fai > manifest.txt gets me close to what i need but it does not create a line break after the absolute path.

secondly i would like to output sequential files in a subdirectory as 1 single line input for example

This_is_an_example/of_how/i_want_to_display/absolute_paths/part_3/
test_file_here_0000001.dpx
test_file_here_0000002.dpx
test_file_here_0000003.dpx
test_file_here_0000004.dpx

displayed as below instead

 This_is_an_example/of_how/i_want_to_display/absolute_paths/part_4/
 test_file_here_[0000000-0000004].dpx
  • 1
    In the second part, the numbers in given pattern, test_file_here_[0000000-00001234].dpx, bears no resemblance to the numbers in the filenames shown. – Kusalananda Dec 7 at 6:53
  • ioshifting, would you please clarify your original post by clicking on edit and expanding on the last example? Folks trying to help here use Comments, but we want you to edit the original post so all can see the change requested. – K7AAY Dec 7 at 17:32
  • Sorry both, i have now corrected the example given to correctly match what i am looking to achieve – ioshifting Dec 9 at 15:02

From man:

  -R, --recursive
          list subdirectories recursively

Try,

ls -R /path/to/dir

more closely,

ll -R /path/to/dir | awk '$1!="total"{print $NF}'
  • the second example with the awk option prints all the files and folder paths how i need them thank you! - i just need to find out how to edit the sequential files into a singular input when printed out – ioshifting Dec 9 at 15:10
  • do you perhaps know the syntax for the awk part of the script to work on centos? i have gawk installed. – ioshifting Dec 9 at 15:56
find . -print | perl -pe 'a=$_; chomp $a; -d $a or s:.*/::'

Since you want to find directories and then list their contents, why not use find for it:

find /path/to/dir -type d -exec bash -O dotglob -O nullglob -c '
    for pathname do
        header=0
        for filename in "$pathname"/*; do
            if [ ! -d "$filename" ]; then
                if [ "$header" -eq 0 ]; then
                    printf "%s/\n" "${pathname%/}"
                    header=1
                fi
                printf "%s\n" "${filename##*/}"
            fi
        done
        [ "$header" -eq 1 ] && printf "\n"
    done' bash {} +

This finds all directories in or under the given directory path. It feeds the pathnames of all these directories to a bash script.

The bash script will iterate over each directory, printing the directory pathname as a header and listing non-directory entries present in that directory. At the end, if at least one non-directory file was found in the directory, an extra newline is outputted.

Directories that are empty or that only contains directories are not listed.

For a directory structure such as

/dir
`-- a
    |-- b
    |   `-- c
    |       |-- .hidden_file
    |       `-- file
    `-- file

This would produce the following output:

/dir/a/
file

/dir/a/b/c/
.hidden_file
file
  • This works very well and displays all hidden files - however i did notice that a lot of the files in the subdirectories appeared to duplicate for example test_file.txt would also have a seperate file labelled ._test_file.txt in some instances whole directories were duplicated. – ioshifting Dec 9 at 15:15
  • @ioshifting I don't think that's a sid effect of using my code. Could you check to see if those hidden and seemingly duplicate file are actually there, and what they are? – Kusalananda Dec 9 at 23:11

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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