M BUZZ CRAZE NEWS
// general

Changing rm -r autocomplete behaviour for directories with whitespace in their name

By Jessica Wood

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.

4

1 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 remove

will give you confirmation, do you want to remove file? and you can abort. I alisis in ~/.bashrc

alias rm="rm -i"

good luck

7

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy