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.

How to remove file (which has white space in name) from Unix?

share|improve this question

migrated from stackoverflow.com Apr 5 '11 at 9:22

This question came from our site for professional and enthusiast programmers.

4 Answers 4

up vote 3 down vote accepted

Another format:

rm file\ with\ spaces\ in\ the\ name
share|improve this answer

Use quotes to surround the file name:

rm "file with a space.txt"

Update: use the quotes to enclose the whole path to the file:

rm "../dir with spaces/file with spaces.txt"

The quotes tell the shell command to interpret the quoted string as one argument (so you can use this with most shell commands).

share|improve this answer
    
@Dave Nice, beat me by 7 seconds –  jnewman Feb 11 '11 at 6:14
    
if i need to delete from parent directory or somewhere else, then? –  Gaurav Feb 11 '11 at 6:21
    
You can always give rm the full path, starting with /blah\ blah. –  klang Feb 12 '11 at 7:07

If you do it manually in your shell (and the filename is more or less unique, i.e. it differs from other filenames not in the positions where whitespaces are) you can use TAB completion. Just type a few letters of the beginning of the filename and hit TAB. Repeat this until the filename is complete.

rm fi(press TAB)

share|improve this answer

Have you tried:

unlink 'path/to/my file with spaces in the name'

Edit: You might also consider changing your paths to not have spaces, using, perhaps, this script.

share|improve this answer
    
if i need to delete from parent directory or somewhere else, then? –  Gaurav Feb 11 '11 at 7:30
    
@Gaurav see @Dave Bachers' answer for something straight forward (he beat me to it). –  jnewman Feb 11 '11 at 7:46

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.