Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This is my directory list on my NFS:

macbook-pro-andrey-k:Download Andrey$ ls
1289816143_PL_t1181913
1289816171_PL_t1183807
1290117075_BFD_DVD02(Drums)

I can't delete "1290117075_BFD_DVD02(Drums)" using

sudo rm -Rf 1290117075_BFD_DVD02(Drums)

because I get the error message

-bash: syntax error near unexpected token `('

How can I either rename the directory so that the error message would not show up, or delete the directory right away omitting the renaming procedure?

share|improve this question
1  
The funniest thing is, you could have typed "sudo rm -Rf 129[tab]" and it would have been escaped. –  Daniel Beck Nov 26 '10 at 21:11

2 Answers 2

up vote 0 down vote accepted

As Ignacio Vazquez-Abrams says, you can surround the file name in quotes to have it treated as a literal. You can also escape characters with special meanings in the shell (space is probably the most common; you have just discovered brackets) with \, so your command would end up as:

sudo rm -Rf 1290117075_BFD_DVD02\(Drums\)

The escape character causes the character immediately after it (and no other) to be treated as a normal character.

share|improve this answer
    
And if dir name contains spaces and &-sign (i.e. 123_Pics & Video) –  user56990 Dec 10 '10 at 21:15
    
Just escape them all, one at a time. 123_Pics\ \&\ Video. The backslash-and-something is what's known as a digraph - two characters that are interpreted as one. See en.wikipedia.org/wiki/Digraphs_and_trigraphs for more detail. –  Scott Dec 10 '10 at 22:16
sudo rm -Rf '1290117075_BFD_DVD02(Drums)'
share|improve this answer
    
And if dir name is for example 123_Pics & Video ? –  user56990 Dec 10 '10 at 21:14
    
@user56990: Single quotes will also work for that. –  Ignacio Vazquez-Abrams Dec 10 '10 at 21:33

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.