Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
You don't delete until you press the enter key so I can't see what your issue is. –  Meer Borg May 15 '13 at 1:22
    
Which is fine for the type of person who A) knows enough to know the behaviour of executing that command and B) Never makes mistakes. I only recently hit the criteria for A) and I don't know many people who meet B). –  BenB May 15 '13 at 1:33
    
I find the behavior odd too when I first hit it, but after realizing what it was about it clicked. I rarely have spaces in directories as that is not a good idea. Even in Windows I avoid the issue. I agree with you that leaving the \ in might be a better aproach, but its something we are all used to now... –  Meer Borg May 15 '13 at 1:37
    
Is there a way to autocomplete directory names with spaces? And what is the motivation behind this behaviour? –  BenB May 15 '13 at 1:56
add comment

1 Answer 1

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

share|improve this answer
1  
-i should be default when running recursive commands as root. :) –  Takkat May 15 '13 at 7:26
    
By "Tab completion is working here" does that mean you're not getting the behaviour I describe? –  BenB May 15 '13 at 17:36
    
no, if I have a file (or directory) called "file with space", bash tab completes. If I type rm -i file<tab> I get rm -i file\ with\ space. –  bodhi.zazen May 15 '13 at 17:41
    
Definitely does not work like that for me. Though I can do rm -r "some <tab> and get rm -r "some spacey" –  BenB May 15 '13 at 18:08
    
do you have a custom .bashrc or other config ? –  bodhi.zazen May 15 '13 at 19:15
show 2 more comments

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.