LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   need help with copying files (https://www.linuxquestions.org/questions/linux-general-1/need-help-with-copying-files-362374/)

Earl Parker II 09-11-2005 12:11 PM

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!

Matir 09-11-2005 12:24 PM

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 \;

Earl Parker II 09-11-2005 01:47 PM

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.

Matir 09-11-2005 02:32 PM

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 \;

Earl Parker II 09-11-2005 08:46 PM

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.

Matir 09-11-2005 09:20 PM

Odd. But it actually works otherwise?

Earl Parker II 09-12-2005 12:12 AM

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.

Matir 09-12-2005 07:28 AM

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.

Earl Parker II 09-12-2005 08:54 AM

I'll play with it when I get a little time and will let you know if I come up with anything.


All times are GMT -5. The time now is 07:02 AM.