LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cp command with input from a text file (https://www.linuxquestions.org/questions/linux-newbie-8/cp-command-with-input-from-a-text-file-661362/)

khaos83 08-08-2008 04:23 AM

cp command with input from a text file
 
I have a file, in inside has a long list of full paths to different file.
e.g.

Code:

/etc/asdsad/filename
/home/asd/wewe/filename


I want to copy all of them to a specified location.
How can I use the information in the file and copy all of them to a specified location?

I remember achieving that but can't really remember how i did it.
something like ...

cp {cat list.txt} /destination/

ic_torres 08-08-2008 04:36 AM

Quote:

Originally Posted by khaos83 (Post 3240700)
I have a file, in inside has a long list of full paths to different file.
e.g.

Code:

/etc/asdsad/filename
/home/asd/wewe/filename


I want to copy all of them to a specified location.
How can I use the information in the file and copy all of them to a specified location?

I remember achieving that but can't really remember how i did it.
something like ...

cp {cat list.txt} /destination/

are you trying to copy the all the list of a particular directory on another location?

have you tried :

cp -r /the directory name/ /new location/

pixellany 08-08-2008 05:27 AM

I think you want something like this:
for file in `cat list`; do cp $file newplace; done

"newplace" would be the target pathname

Note the "backtics"---no single quotes.

colucix 08-08-2008 06:07 AM

Quote:

Originally Posted by pixellany (Post 3240745)
for file in `cat list`; do cp $file newplace; done

This does not manage file names containing blank spaces correctly. Better something like
Code:

while read file; do cp "$file" /path/to/destination/dir/; done < list


All times are GMT -5. The time now is 11:45 AM.