Other contacts

Novi članci

Flickr Goodness


February 5, 2011 @ 21:19

Supress cp “Do you want to overwrite” prompt in Fedora

When you try to copy one file over existing one as root user in Fedora you will be asked to confirm that action, but as regular user you can overwrite existing files without any question. So you can easily overwrite your own personal files, GNOME settings, documents, images, etc.

It is obvious that this is policy is made from sysadmin point of view. Sysadmins usually doesn’t care if people mess up or delete their own files, as long as they don’t mess up or damage system in some way.
If you look in .bashrc file of your root account you will find alias for rm, cp and mv commands:

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

I would argue that these aliases should be enabled also for regular users to keep them from messing up their files.
If you are a power user and you need to copy over whole directories over existing files you probably don’t want to keep hitting that “y” button over and over.
Only way I found out that you can suppress being asked annoying “overwrite y/n” question is by deleting alias cp='cp -i' definition from root user’s .bashrc file.
But maybe it is better to have protective policy enabled and just temporariliy disable it by using unalias cp command.
If you know other way to disable being asked confirming question for overwriting existing file please explain how in comments.

Filed under english, fedora, linux, tips&tricks


  1. Posted by Tweets that mention /kernel_reloaded/ — Topsy.com

    February 5, 2011 @ 21:53

    [...] This post was mentioned on Twitter by Zuissi, Planet Fedora. Planet Fedora said: Valent Turkovic: Supress cp “Do you want to overwrite” prompt in Fedora:   When you try to copy one file over ex… http://bit.ly/fNiWOB [...]

  2. Posted by dmaphy

    February 5, 2011 @ 22:25

    If you call the commands with -f, they don’t care of the -i. In my opinion there is no need for un-setting those aliases.

  3. Posted by No alias

    February 5, 2011 @ 23:00

    Or for a onetime alias suspension use \cp instead of cp

  4. Posted by valent

    February 6, 2011 @ 0:33

    Nope, I tried using cp -f and it looks like -i options disabled -f option. Just try it and you will see for your self.

  5. Posted by Paul Frields

    February 6, 2011 @ 1:04

    “Regular users” would be using a GUI shell with its own protection settings. There’s no need for the current behavior to change.

  6. Posted by Clifford

    February 6, 2011 @ 4:15

    I have not tried this with cp, but I use the full path when removing files, for example /bin/rm. I would think /bin/cp would work the same. I can not test since I don’t have an alias for cp.

  7. Posted by J. Randall Owens

    February 6, 2011 @ 8:00

    Much like “No alias”‘s suggestion, I usually use /bin/cp to suppress the alias on a one-time basis.

  8. Posted by Rene

    February 6, 2011 @ 13:11

    You can do it using quotes like: “rm” file
    or ‘rm’ file
    I don’t know a manpage where this is explained. It was just one of those tricks you find on some random webpage.

  9. Posted by Peter Robinson

    February 6, 2011 @ 15:53

    As someone mentioned above for cp you can prepend a \ to all commands to get the base command and not aliases. Its a very quick way to get around either local or system aliases.

  10. Posted by Jeff Schroeder

    February 7, 2011 @ 15:56

    There is a much better way and I’m surprised no one has said it yet.

    The easiest way to reference the actual cp binary and skip over aliases is to use \. This is much easier than calling the full path to the binary (/bin/cp) and accomplishes the same job. It also lets you keep the alias so just in case you do something stupid you’ll have a chance to save yourself.

    For example:
    root@jschroeder2:~# touch file1 file2
    root@jschroeder2:~# cp file1 file2
    cp: overwrite `file2’? n
    root@jschroeder2:~# \cp file1 file2

    Perhaps I should write up a blog post on this and other common mistakes.

RSS feed for comments on this post · TrackBack URI

Leave a Comment


    Flickr photostream

    SSL is required

    Meta meta :)