LinuxQuestions.org
Visit Jeremy's Blog.
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 07-20-2006, 05:59 AM   #1
YunaFF102
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Rep: Reputation: 0
Question Copying files


Hello people,
In an attempt to rearrange all my folders, I made a text file that contains something like this:

[folder1] [folder2]
file1
file2
...
[folderx] [foldery]
file2312
file2313
...

The files listed after a line with 2 folder names(full path name) are the files I want to copy from the folder on the left to the folder on the right(some right folders might not have existed).
Is there any tool/program/command that would allow me to do that?
Thx,
 
Old 07-20-2006, 06:21 AM   #2
Zmyrgel
Senior Member
 
Registered: Dec 2005
Location: Finland
Distribution: Slackware, CentOS, RHEL, OpenBSD
Posts: 1,006

Rep: Reputation: 37
Check out "man cp" you can probably find your answer from there. I haven't played with cp that much or figured out exactly what are you trying to do here.

Are you trying to copy all files from one folder to next? Then the command should be simple: "cp /folder/* /folder/"
 
Old 07-20-2006, 06:41 AM   #3
YunaFF102
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Let me give you an example. Suppose I have a file list.txt that contains:


/home/folder1 /home/folder2
file1.gif
file2.doc
/home/testserver /home/testserver/day1
specs.doc
report.pdf


I'm looking for something that would read list.txt and then copy file1.gif and file2.doc from /home/folder1 to /home/folder2 AND specs.doc and report.pdf from /home/testserver to /home/testserver/day1 (suppose /home/testserver/day1 hasn't been created yet). Obviously I have a very huge list.txt, so copying manually wouldn't be fun.
Hope that clears up the question.
Cheers,
 
Old 07-20-2006, 03:24 PM   #4
csmarkus
LQ Newbie
 
Registered: Jun 2006
Location: Budapest, Hungary
Distribution: Debian
Posts: 4

Rep: Reputation: 0
You can try this one-liner:

awk 'NF==2 { fromdir=$1; todir=$2; system("mkdir -p " todir) } NF==1 { system("cp " fromdir "/" $1 " " todir) }' copylist.txt

It worked for me with the following six lines of content in copylist.txt:

/etc /tmp/q/a/b/c
motd
fstab
/bin /tmp/q/a/b/d
cp
ls


awk can do magic and so can perl. They are worth learning the basics of for everyone who is not afraid to type a few words for a short script.

Cheers,
Csaba
 
Old 07-21-2006, 06:06 AM   #5
YunaFF102
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by csmarkus
You can try this one-liner:

awk 'NF==2 { fromdir=$1; todir=$2; system("mkdir -p " todir) } NF==1 { system("cp " fromdir "/" $1 " " todir) }' copylist.txt

It worked for me with the following six lines of content in copylist.txt:

/etc /tmp/q/a/b/c
motd
fstab
/bin /tmp/q/a/b/d
cp
ls


awk can do magic and so can perl. They are worth learning the basics of for everyone who is not afraid to type a few words for a short script.

Cheers,
Csaba
You're a genius! It worked like a charm. Thank you very much!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Copying files paddyjoy Linux - Newbie 10 10-25-2013 12:12 PM
Copying files rvsridhar Linux - General 5 03-23-2006 05:06 AM
Copying FIles Casper12 General 4 08-07-2005 05:30 PM
copying files Sol0 Linux - Software 7 08-18-2003 11:40 AM
Copying Files... viperquest Linux - Software 3 03-07-2003 03:41 PM


All times are GMT -5. The time now is 06:44 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration