Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In my /home/user/.bashrc file, I have those aliases to prevent mistakes:

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

If I'm really sure of what I'm doing, I can overwrite rm and mv aliases using rm -f or mv -f, it will not ask me if I really want to overwrite files.

The problem, is that it doesn't work for the cp command, using cp -f will still ask me a question.

Is this normal? What should I do in order to have cp -i alias by default and be able to use cp -f command too?

I'm using Debian Wheezy 64bit.

share|improve this question

2 Answers 2

up vote 6 down vote accepted

While -f means force on all of them, for cp, it means force by trying to remove the destination first if the destination can't be updated.

For mv and rm, -f just overrides -i. But for cp, it changes the behavior of the utility, -f is not the opposite of -i in that case, cp -i -f makes sense and means, if the target exists, ask the user and if it can't be overridden, remove it first.

Even for mv and rm, adding -f is not the same as removing -i when it comes to warning and error messages sent to the user. For instance rm non-existent-file would report an error while rm -i -f non-existent-file would not.

As already mentioned, instead of adding -f, you should disable the alias using any of the solutions provided.

share|improve this answer
    
"For mv and cp, -f just overrides -i." You mean mv and rm I think. Thanks for explaining, it is very clear to me now! –  baptx Dec 3 '12 at 14:08

By giving cp -r, the option simply adds up with the existing option.

To override the alias:

\cp -f file1 file2

The backslash before the command will disable the alias.

share|improve this answer
    
I made a mistake in my post, when I talked about cp -r, I meant cp -f, it's corrected. Your solution with a backslash is working, thanks! But I still don't understand why the backslash is not needed for mv or rm command, the alias is directly disabled with mv -f and rm -f! –  baptx Dec 3 '12 at 12:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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