LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-08-2008, 04:23 AM   #1
khaos83
Member
 
Registered: Dec 2007
Posts: 97

Rep: Reputation: 15
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/
 
Old 08-08-2008, 04:36 AM   #2
ic_torres
Member
 
Registered: Nov 2005
Location: ABAP
Distribution: slackware 12.0, Vector Linux STD 6.0 and 5.8, ZenWalk 4.6.1, OpenBSD 3.9
Posts: 389

Rep: Reputation: 34
Quote:
Originally Posted by khaos83 View Post
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/
 
Old 08-08-2008, 05:27 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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.
 
Old 08-08-2008, 06:07 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by pixellany View Post
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
parse input text file and generate output TsanChung Programming 5 07-27-2008 10:23 PM
Using command output as file input FlowState Linux - Software 1 05-14-2008 07:30 PM
howto run the htpasswd command with input from file for 500 usernames !! PK2K Linux - Software 4 02-02-2006 02:54 AM
input text file processing the gnu way? zero79 Programming 3 03-04-2005 07:41 PM
how to use the output of a file for input of a command sneak Linux - General 2 05-12-2004 09:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration