1

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 1

1

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
  • i've tried cp zone* backup, but return "No such file or directory" when i'm at /home
    – moo tensai
    Apr 15, 2014 at 2:33
  • @moo.tensai that's because you're at /home and not at /home/mootensai. Forget /home, that is not your home directory, think of it as the /Users directory on OSX or C:\Users on Windows. Your actual home directory is a sub directory of that.
    – terdon
    Apr 15, 2014 at 2:35
  • @moo.tensai if your sources are also directories, make sure to use -r (see updated answer).
    – terdon
    Apr 15, 2014 at 2:37
  • i've tried 'cp -r zone* /home.bak' but still return no such file or directory..
    – moo tensai
    Apr 15, 2014 at 2:43
  • @moo.tensai please use one of the commands I suggested. For example cp -r ~/zone* ~/home.bak. That will work as long as the ~/home.bak directory exists. You can't copy directories into a directory that doesn't exist. Try running the exact 2 commands I gave you, step 1 and step 2.
    – terdon
    Apr 15, 2014 at 2:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .