Changing rm -r autocomplete behaviour for directories with whitespace in their name
I'm running Ubuntu 12.04.
If I try to auto-complete to delete a directory with spaces in the name, it doesn't work.
Say my directory is called "some spacey directory". If I type rm -r some and hit tab, nothing more autocompletes. So then I type a bit more, say rm -r some\ s. Now if I hit tab, it autocompletes but removes the \ characters giving rm -r some spacey directory. This, however, won't delete some spacey directory. So that's inconvenient.
But when this is a real nightmare: If you have two directories, say "basic" and "basic with an added feature" and execute rm -r basic with an added feature you end up deleting basic.
My question: Is there any reason autocomplete has that behaviour? Is there anyway I can get rid of it? This seems like dangerous behaviour in the context of a permanent delete command.
41 Answer
Tab completion is working here for directories and files with spaces in their names.
As you can see, Linux does not like spaces in file names. You have to escape them with a \ or use quotes.
rm -rf "directory with spaces"rm on the command line is harsh and typos can give you problems. I suggest you use the -i option for confirmation.
rm -i file to removewill give you confirmation, do you want to remove file? and you can abort. I alisis in ~/.bashrc
alias rm="rm -i"good luck
7More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"