PDA

View Full Version : how to create mass backups of files?



dmbyer
19th April 2008, 04:41 AM
Is there a way via the command line without using a script to copy all the files in a given directory to the same directory plus a .bak extension?

For instance, say I have 4 files:


file1.ex1
file2.ex2
file3.ex3
file4.ex4


And I want to have the end result this:


file1.ex1
file2.ex2
file3.ex3
file4.ex4
file1.ex1.bak
file2.ex2.bak
file3.ex3.bak
file4.ex4.bak


I'd like to do this with simply 1 command. I tried using cp with wildcards but it doesn't like it.


[root@localhost vsftpd]# cp ./* ./*.bak
cp: target `./*.bak' is not a directory

[root@localhost vsftpd]# cp -T * *.bak
cp: extra operand `vsftpd.conf'
Try `cp --help' for more information.


I have a few workarounds to this as well such as just tarring up, but I am making a lot of conf changes while learning to set up my linux box and need to restore constantly, so having to untar and re-tar is cumbersome. I can make a script too but just wondering if there is a streamlined existing method for what I am trying to do.

Thanks in advance!

ogetbilo
19th April 2008, 07:22 AM
for i in `ls`; do cp -R $i $i.bak; done

should work. Note that the -R flag is for directories. You don't need it if you don't have sub-directories to back up.

dmbyer
19th April 2008, 03:48 PM
Thank you very much!