Find the answer to your Linux question:
Results 1 to 6 of 6
Hi ! I have to copy /usr directory from one drive to another. I tried to copy it with cp,but failed. Then people told me to use "tar". Then I ...
  1. #1
    Just Joined!
    Join Date
    Apr 2009
    Posts
    63

    Exclamation tar not working in this case

    Hi !
    I have to copy /usr directory from one drive to another. I tried to copy it with cp,but failed. Then people told me to use "tar". Then I made " tar -cvf ....." of /usr directory and moved it to the target drive by "mv".Then I tried to "tar -xvf ....." there. But I got a very big list of errors like " /usr/include/....something.... no such file or directory. I am using SuSE 11.0
    How to copy /usr correctly?

  2. #2
    Linux Guru reed9's Avatar
    Join Date
    Feb 2009
    Location
    Boston, MA
    Posts
    4,651
    Did you use the recursive flag with cp?
    Code:
    cp -r /usr /destination/directory

  3. #3
    Just Joined!
    Join Date
    Apr 2009
    Posts
    63
    No, I did not use "cp -r ....." I used " cp ....." and "cp -dpR ....." Now I will use cp -r and see what happens.

  4. #4
    Trusted Penguin Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,392
    You really should use 'cp -a ...' for tasks like this - it does the recursive thing and also preserves user permissions and ownership (-a wraps up a series of other flags for cp).
    Linux user #126863 - see http://linuxcounter.net/

  5. #5
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    This is how I've used tar to copy a directory structure to a new location:

    Code:
    cd /usr; tar -cf - . | ( cd /path/to/target; tar -xf - )

  6. #6
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    We need to know the exact (and by exact I mean "letter by letter") command that you used and what results did you get. Otherwise we have no idea about what your problem might be.

    In any case, two things are important when doing this task: you need to preserver ownserships/permissions and you have to copy recursively the whole tree. How to do that: it depends on the tools you use.

    If you are going to use tar, make sure you use -p, the rest of the flags you use depends on whether you want compression, verbosity or whatever else. For example, to /usr into a file using gz compression and verbosity while preserving permissions you would do

    Code:
    tar -cvjpf <backup_file> /usr
    If you want to use cp you can use either "cp -a" or "cp -dpR" (or -dpr, both cases work for the 'r'). -a almost equals -dpR (but not exactly, depending on the underlying file system anyway).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...