Copy several files listed in a text file to a new folder
Copying multiple files listed in a text file to a new folder is a fairly simple task, and can be accomplished using the command line.
The first step is to create a text file that contains the list of files you want to copy. This file should contain the full paths of the files you want to copy, one per line. For example, if you wanted to copy the files “/home/user/file1” and “/home/user/file2”, the text file would look like this:
/home/user/file1 /home/user/file2
Once you’ve created the text file, you can then use the “xargs” command to copy the files listed in the text file to a new folder. The syntax for this command is as follows:
xargs -I{} cp {} new_folder
In this example, “{}” is a placeholder for each of the files listed in the text file. The “-I” flag is used to specify the placeholder, and the “cp” command is used to copy the files. The “new_folder” is the path of the folder where the files should be copied.
For example, if you wanted to copy the files listed in the text file above to a folder called “/home/user/new_folder”, you would use the following command:
xargs -I{} cp {} /home/user/new_folder
This command will copy the files listed in the text file to the new folder.
It’s important to note that the “xargs” command is not a standard command, so it might not be available on all systems. If it’s not available, you can use the “find” command to accomplish the same task. The syntax for this command is as follows:
find -name \\*.txt -exec cp {} new_folder \\;
In this example, the “-name” flag is used to specify the name of the text file containing the list of files, and the “-exec” flag is used to execute the “cp” command. The “new_folder” is the path of the folder where the files should be copied.
For example, if you wanted to copy the files listed in a text file called “file_list.txt” to a folder called “/home/user/new_folder”, you would use the following command:
This command will copy the files listed in the text file to the new folder.
In summary, copying multiple files listed in a text file to a new folder is a simple task that can be accomplished using the “xargs” or “find” command. The “xargs” command is the easiest to use, but it might not be available on all systems. If it’s not available, you can use the “find” command instead. Both commands allow you to specify the list of files to copy, as well as the destination folder.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.