Find the answer to your Linux question:
Results 1 to 5 of 5
I checked out the man page for the cp command and noticed the --backup command. I've been playing around with it and I am getting it to work, but I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2012
    Posts
    3

    advanced cp command usage


    I checked out the man page for the cp command and noticed the --backup command.

    I've been playing around with it and I am getting it to work, but I can't seem to control the --suffix. The default is a ~.

    I would like to change that to something else like a v.

    I know the cp command is pretty simple, but I couldn't find any help on specifics of the command other than cp file1 file2 and things like that.

    Can anyone point me to a tut or example page using the more advanced controls of the cp command?

    Thanks,
    C

  2. #2
    Just Joined!
    Join Date
    Sep 2006
    Posts
    2
    Code:
    # touch testfile newfile
    #  cp --backup=simple --suffix=v testfile newfile
    cp: overwrite `newfile'? y
    # ls
    newfile  newfilev  testfile

    Is this what you are looking for?

    ~Vipinlal

  3. #3
    Just Joined!
    Join Date
    Apr 2012
    Posts
    3
    yes and no.

    when I run this command
    Code:
    cp --backup=numbered /tmp/file.log /home/file.log
    I get the "backup" file as file.log~1~. run it again and I get file.log~2~
    and so on.

    the --help says

    Code:
    The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
    The version control method may be selected via the --backup option or through
    the VERSION_CONTROL environment variable.  Here are the values:
    
      none, off       never make backups (even if --backup is given)
      numbered, t     make numbered backups
      existing, nil   numbered if numbered backups exist, simple otherwise
      simple, never   always make simple backups
    I was hoping to make numbered backups, but swap out the ~ for a standard character. however when I run the command

    Code:
    cp --backup=numbered --suffix=v /tmp/file.log /home/file.log
    the suffix doesn't change. When I run your command, the suffix changes, but I loose the numbering system.

    also, as a side note, if you have the --backup flag enabled, it doesn't appear that you can use the --force command to bypass the overwrite prompt.

    guess, I will have to figure something else out. bummer this would've saved like 1/2 days work.

  4. #4
    Just Joined!
    Join Date
    May 2011
    Location
    Central FL
    Posts
    91
    Being able to change the suffix is only when doing "simple" backups. Since "numbered" is not "simple" you cannot override the suffix when using it. The two features are mutually exclusive.

    If you're trying to do numbered backups, have you considered using rsync instead? I think that given what you're trying to accomplish you'll find that rsync, as a tool, is much better suited.

  5. #5
    Just Joined!
    Join Date
    Apr 2012
    Posts
    3
    Quote Originally Posted by dayid View Post
    If you're trying to do numbered backups, have you considered using rsync instead? I think that given what you're trying to accomplish you'll find that rsync, as a tool, is much better suited.
    all I am really doing it moving a file from one folder to another using inotify. I was just hoping to utilize the --backup feature in the cp to prevent accidental overwriting, without having to right a whole subroutine to check for duplicate files prior to writing.

    I kinda felt like rsync was overkill to simply move files from one folder to another. but maybe that is the answer in this case.

Posting Permissions

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