8

On windows OS, when you copy a file into a directory that already has a file with that name, it asks you whether you want to:

  1. copy the file and replace/overwrite the existing one
  2. cancel copying the new file into the directory
  3. copy the file, but rename it (as something like "filename - copy (1)")

When I do this in Ubuntu, I don't have that 3rd option (which is a lot of times a very useful option). Is there any way to be able to do that in Ubuntu?

14

Unfortunately Nautilus doesn't have that option.

Option 1: A different file manager

You could try another file manager like Dolphin.

Install Dolphin (requires the Universe repository)

Option 2: Command-line

You can also use the command line program cp(1) with the backup option:

cp --backup -t DESTINATION SOURCE [SOURCE...]

This has the following effects which can be controlled with other options as described in the manual page of cp(1):

--backup[=CONTROL] ― make a backup of each existing destination file

-b ― like --backup but does not accept an argument

-S, --suffix=SUFFIX ― override the usual backup suffix

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

Example

cp --backup=existing --suffix=.orig -t ~/Videos ~/Music/*

This will copy all files in ~/Music to ~/Videos. If a file of the same name exists at the destination, it is renamed by appending .orig to its name as a backup. If a file with the same name as the backup exists, the backup is instead renamed by appending .1 and if that exists as well .2 and so forth. Only then is the source file copied to the destination.

If you want to copy files in subdirectories recursively use:

cp -R --backup=existing --suffix=.orig -t ~/Videos ~/Music
  • Thanks for the suggestion to use a different file manager. Unfortunately, Thunar also doesn't have the option that I'm referring to. It just has: Cancel, Skip All, Skip, Replace, Replace All. Will try out Dolphin. – heisenbergman Oct 19 '14 at 11:12
  • 1
    Dolphin works great for this :) – heisenbergman Oct 19 '14 at 13:05
  • Thanks for trying out the two. I'll update my question according to your findings. – David Foerster Oct 19 '14 at 13:11
  • @heisenbergman, Hi what did you mean by Dolphin works great for this? It does offer the option to rename, but it still only allows me to rename the files one by one. Unfortunately the "apply to all" option cannot be used with the option to rename. This is quite useless for a large amount of files. Is this just my version? Did you manage to rename all your doubles at once (like you can in Windows), using Dolphin? – Kvothe Feb 27 '18 at 13:46
2

Found this on superuser:

#!/bin/bash
cp -vn "$1" "$2"/ || cp -vn "$1" "$2"/"${1##*/}"~"$(md5sum "$1" | cut -f1 -d' ')"

The file that has the same name gets renamed to the file with the md5sum added to the name. If you save it to a filename like "saveCopy" you can use find like this to execute it:

find . -name 'z*.jpg' -exec ./saveCopy {} /tmp/Extracted/ \;

For more on this see the link.

0

There was a solution (ultracopier) to this question in this forum before: see https://ubuntuforums.org/showthread.php?t=2251859 According to that discussion, it can eb integrated into Nautilus.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.