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

  • Pingback: Tweets that mention /kernel_reloaded/ -- Topsy.com

  • dmaphy

    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.

    • valent

      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.

  • No alias

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

  • Paul Frields

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

  • Clifford

    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.

  • J. Randall Owens

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

  • Rene

    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.

  • Peter Robinson

    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.

  • http://www.digitalprognosis.com Jeff Schroeder

    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.


    Flickr photostream

    User not found

    Meta meta :)