Linux: find a list of files in a dictionary recursively


I have a text file with one file name per line:

Interpret 1 - Song 1.mp3
Interpret 2 - Song 2.mp3
...   

(about 200 file names)

Now I want to search the folder for these file names again to get the full path for each file name in Filenames.txt.
How to do it?:)

(Purpose: the copied files to the MP3 player, but some of them are broken, and I want to restore them without spending hours studying them from my music folder)

+3
source share
4 answers

The easiest way could be as follows:

cat orig_filenames.txt | while read file ; do find /dest/directory -name "$file" ; done > output_file_with_paths 
+4
source

The find command is run much faster only once and fgrep is used.

find . -type f -print0 | fgrep -zFf ./file_with_filenames.txt | xargs -0 -J % cp % /path/to/destdir
+3
source

while find:

filecopy.sh

#!/bin/bash

while read line
do
        find . -iname "$line" -exec cp '{}' /where/to/put/your/files \;
done < list_of_files.txt

Where list_of_files.txtis the list of files line by line, and /where/to/put/your/filesis the place you want to copy to. You can simply run it, as in the directory:

$ bash filecopy.sh
+1
source

+1 for @ jm666's answer, but the parameter -Jdoesn't work for my taste of xargs, so I highlighted it to:

find . -type f -print0 | fgrep -zFf ./file_with_filenames.txt | xargs -0 -I{} cp "{}" /path/to/destdir/
0
source

All Articles