Ubuntu – Get the file path relatively

bashcommand linefindtext processing

I have two directories A and B. Each one contains a zip.

How can I write the path of these two zip files into a text file?

Example for the directory system:

FILES/ONE/one.zip
FILES/TWO/two.zip

And I want to run the command from FILES directory

Best Answer

You can use the find command, with its output directed to a file, in the following way:

/tmp/FILES$ find . -name "*.zip" -print > outfile.txt

Find every file ended with zip inside the current folder (FILES) and print it path
The output of the find command is directed into a text file:

The content of the outfile.txt is:

/tmp/FILES$ cat outfile.txt 

./TWO/two.zip
./ONE/one.zip

Note, if you'll execute the find command in one folder above the FILES folder, your output will include also the FILES part of the folder.

e.g. when find output is directed to stdout

/tmp$ find FILES -name "*.zip" -print
FILES/TWO/two.zip
FILES/ONE/one.zip
Related Question