Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Several distros unfortunately include 'mv' and 'cp' aliases by default. To get predictable behavior on the command line, always use '\mv' and '\cp'. (for bash)


I didn't know that! Why does it work?


The backslash basically means "ignore any aliases or functions by the same name, and run the first matching command in my $PATH instead".

One reason for providing this is so that you can have an alias like

    alias mv '\mv -=myfavoritearg '
but it's also good for ensuring that you didn't pick up some distro nonsense.


Thanks! So '\' is special cased here—it's not some specific manifestation of a more general phenomenon of specialised escape-handling in the shell?


> So '\' is special cased here

No; quoting any part of the command name prevents alias expansion. Eg 'mv', "mv", 'm'v, m\v, etc all work.


If I understand correctly, yes, that's how I'd describe it.


that's a good tip.

I've always used /bin/mv or /bin/ls to get just the command, but your method is shorter. (although I can't help but think of windows paths)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: