cp command help
I have around 500 files in a folder. But I don't want to copy all of them. The name of the files that I want to copy is in a txt file.
The question is how to use the names from the txt file as arguments for the cp command. |
You need to read the lines from the file into a variable and then use that variable as an argument to the cp command. For example, consider the file "numbers":
1 2 3 4 A simple shell script to read the values from this file and print the numbers is as follows: Code:
#!/bin/bash |
Hi,
I hope you are trying to copy the files and not the lines in a file, if so, here is your option. Quote:
|
In addition of writing a shell script as nylex suggested, you can easily do it from the command line. For example in the bash shell the following would copy all the files listed in my_file_list.txt to /my/dest_dir
Code:
for i in `cat my_file_list.txt`; do cp $i /my/dest_dir; done |
Quote:
|
Depending on whether or not you are copying all the file to the same location, you could simply do:
Code:
cp $(< file) location/ And of course that the destination 'location' exists. |
Quote:
Sorry for that mis leading message, I took your question i a wrong sense. You can go with Nylex and z1p's option. |
All times are GMT -5. The time now is 05:11 PM. |