LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 09-11-2005, 01:11 PM   #1
Earl Parker II
Member
 
Registered: Jan 2002
Location: Shelby, NC, US
Distribution: Slackware 12.2
Posts: 127

Rep: Reputation: 17
need help with copying files


This probably pretty simple but I haven't quite figured out how to do it. I want to copy every .conf file on my HD to a single folder for backup purposes. Backing up isn't a problem but I haven't figured out the correct syntax to do the copy deal. Does anyone have any suggestions? Thanks for any help!
 
Old 09-11-2005, 01:24 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Well, if you literally mean every file ending in .conf:
Code:
find / -iname '*.conf' -print0 | xargs -0 -i cp {} /backupdirectory
Just change /backupdirectory to taste.

Edit:
Or more simply, and I somehow didn't think of this:
Code:
find / -iname '*.conf' -exec cp {} /backupdirectory \;
 
Old 09-11-2005, 02:47 PM   #3
Earl Parker II
Member
 
Registered: Jan 2002
Location: Shelby, NC, US
Distribution: Slackware 12.2
Posts: 127

Original Poster
Rep: Reputation: 17
Thank you! The second command works perfectly (didn't try the first one yet). Now, just one more question- when I run the command, for every file that's copied I'm getting:

Code:
cp: '/conf/<filename>' and '/conf/<filename>' are the same file
Any ideas as to what's causing that? Seems like the command is being executed twice.

Later, when I have some time, I'm getting into the man pages to analyze the commands you've given me to see how they work.
 
Old 09-11-2005, 03:32 PM   #4
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Is /conf the directory you are using for backups? If so, it may be refinding the files. Oops. Try:
Code:
find / -iname '*.conf' \! -name "/conf/*" -exec cp {} /conf \;
 
Old 09-11-2005, 09:46 PM   #5
Earl Parker II
Member
 
Registered: Jan 2002
Location: Shelby, NC, US
Distribution: Slackware 12.2
Posts: 127

Original Poster
Rep: Reputation: 17
Yes it is. I'll give your fix a try in the morning and let you know- thanks again for the help!

Update:
Tried it tonight, same error messages.

Last edited by Earl Parker II; 09-11-2005 at 09:57 PM.
 
Old 09-11-2005, 10:20 PM   #6
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Odd. But it actually works otherwise?
 
Old 09-12-2005, 01:12 AM   #7
Earl Parker II
Member
 
Registered: Jan 2002
Location: Shelby, NC, US
Distribution: Slackware 12.2
Posts: 127

Original Poster
Rep: Reputation: 17
Seems to work perfectly. Truthfully the error message deal is of academic interest only as you've solved the original problem. Would be interesting to figure out, though. I changed a couple of things around just to see the effect but haven't hit on anything yet.
 
Old 09-12-2005, 08:28 AM   #8
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Well, it seems to be caused by the search find the copy of the file in the backup directory and trying to recopy it. I would've thought my other statement would exclude those files, but maybe not.
 
Old 09-12-2005, 09:54 AM   #9
Earl Parker II
Member
 
Registered: Jan 2002
Location: Shelby, NC, US
Distribution: Slackware 12.2
Posts: 127

Original Poster
Rep: Reputation: 17
I'll play with it when I get a little time and will let you know if I come up with anything.
 
  


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 On
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(s) in c climbingmerlin Programming 7 10-27-2005 03:00 PM
copying files neozero62 Linux - Newbie 1 11-23-2003 06:38 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 03:14 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration