1

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

4 Answers 4

6

Another format:

rm file\ with\ spaces\ in\ the\ name
5

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).

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

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)

0

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .