I have a large folder of pictures (thousands), and I have a long list of files, by exact file name, that I need to copy to another folder. I want to know if there is a way I can select several specific files from this folder, by name, and copy them to another folder, using the terminal, without copying them individually?
Ubuntu – Copying multiple specific files from one folder to another
command linefiles
Best Answer
Simply copy multiple files at once from command line
There are several ways you could achieve this. The easiest I have seen is to use the following.
The syntax uses the cp command followed by the path to the directory the desired files are located in with all the files you wish to copy wrapped in brackets and separated by commas.
Make sure to note that there are no spaces between the files. The last part of the command,
/home/usr/destination/
, is the directory you wish to copy the files into.or if the all the files have the same prefix but different endings you could do something like this:
Where file1,file2,file3 and file4 would be copied.
From how you worded the question I believe this is what you're looking for but it also sounds like you might be looking for a command to read from a list of files and copy all of them to a certain directory. If that is the case let me know and i'll edit my answer.
Dealing with duplicates with python
So I wrote a little python script that I believe should get the job done. However, I am not sure how well versed you are in python (if versed at all) so I will try explaining how to use this script the best I can and please ask as many questions about it as you need.
This script should be relatively simple to use. First off, copy the above code into the program gedit (should be pre-installed in Ubuntu) or any other text editor.
After that is complete, save the file as move.py in your home directory (it can be any directory but for ease of instruction lets just use the home directory) or add the directory the file is contained in to your PATH. Then
cd
to your home directory (or whatever directory you saved move.py in) from the terminal and type the following command:This should copy all of the files that are listed from the source directory to the destination directory with duplicates taking the format pic(1).jpg, pic(2).jpg and so on. file.txt should be a file that lists all the pictures you would like to copy with each entry on its own separate line.
In no way should this script effect the source directory, however just make sure to enter the correct paths to the source and destination directory and the worst that could happen is you copy the files to the wrong directory.
Notes
"file does not exist" and prompt you to "press enter" to continue and the script will continue copying the rest of the list.
/
on both the path to the sourcedirectory and path to the destination directory. Otherwise the script will spit an error back at you.