linuxabsolute-path

How can I geta list of files in multiple sub-folder with their absolute path in Linux


I have multiple sub-folder, in every sub-folder have multiple .txt file. I want to organize a list with every file.I use this command to get absolute path.

find $PWD -type f -name "*.txt"

but how do I merge all of them into a text file.

like this

/home/2022/Dir/20220103/1.txt
/home/2022/Dir/20220103/2.txt
/home/2022/Dir/20220103/3.txt
/home/2022/Dir/20220103/4.txt
/home/2022/Dir/20220105/1.txt
/home/2022/Dir/20220105/2.txt
/home/2022/Dir/20220105/3.txt
/home/2022/Dir/20220107/11.txt
/home/2022/Dir1/20220211/12.txt
/home/2022/Dir1/20220211/13.txt
/home/2022/Dir1/20220217/1.txt
.
.
.
.
.

Solution

  • man find gives you the answer:

    Excerpt:

    -print True;  print  the full file name on the standard output, followed by a newline. ...
    

    Hence (for your case):

    find $PWD -type f -name "*.txt" -print
    

    In order to get the results of any UNIX/Linux command in a file, you just redirect, using the > character, like this:

    find $PWD -type f -name "*.txt" -print >outputfile