Reputation: 69
I have a list of images in a text file in the following format:
abc.jpg
xyz.jpg
The list contains about a hundred images in various directories within a specific directory. I would like to create a shell script that finds and copies these files into a specified directory.
Can this script be adapted to what I need? Copy list of file names from multiple directories
Upvotes: 2
Views: 2262
Reputation: 971
you do not need a script for this, a simple oneliner will do: (assuming, that the full filepath, or the relative filepath to were you executing the command is written in your_file.txt file for every image)
cat your_file.txt | xargs find path_to_root_dir -name | xargs -I{} cp {} specfic_directory/
xargs will take multiple lines and runs the command you give it with the input of every line with -I you can specify a variable, for where the content of the line is placed in the command (default is at the end).
So this will take every line from you file, search the file in all subdirectories of path_to_root_dir and then does a copy.
Upvotes: 5