how to copy directory with wildcard to another folder
Sebastian Wright
i need to make a cron that copy folder on /home
here is the content of my /home
fina
f-logistik
folder-surat-jalan
zone-A
zone-B
zone-C
zone-freewhat i need to copy is only folder that start with 'zone'
i've tried :
cp /home/zone* /home.bakbut return No such file or directory
EDIT : and all of the list is folders
EDIT #2 : i use 12.04 precise..
1 Answer
That's because your $HOME is not /home. It is a sub-directory of /home with the same name as your user. So, if your user name is mootensai, your $HOME is /home/mootensai. To avoid these errors, you can simply use ~ or $HOME both of which are your actual home directory. For example, on my system:
$ echo ~
/home/terdon
$ echo $HOME
/home/terdonThe next problem is that if you are copying multiple files, you want to make sure the last file is a directory. Otherwise, each file you copy will overwrite the last one and you will end up with only one file.
Anyway, the commands you want are:
Create the backup directory
mkdir ~/backupCopy the files over
cp -r ~/zone* ~/backup
If, as is most likely the case, you are in your $HOME, you can simply do this:
cp -r zone* backup 11