Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

how to copy directory with wildcard to another folder

Writer 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-free

what i need to copy is only folder that start with 'zone'

i've tried :

cp /home/zone* /home.bak

but 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/terdon

The 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:

  1. Create the backup directory

    mkdir ~/backup
  2. Copy 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy