sudo rm (filename with spaces between two words)

Peter Garrett peter.garrett at optusnet.com.au
Tue Oct 24 18:00:53 BST 2006


On Tue, 24 Oct 2006 11:59:56 -0400
smithveg <smithveg at gmail.com> wrote:

> Hello,
> 
> Normally, i just use the 'sudo rm filenames' to delete a file. But i can not
> delete a filename like 'file to you.odt'
> When i try to create launcher in desktop, i can noticed the command also
> have the space inthe filename. But if i write in terminal, it prompt me file
> not found.
> 
> sudo rm file to you.odt ---> can not find the file. Why?

Linux/Unix doesn't like spaces in file names :) You can usually
tab-complete the name like this:

sudo rm file <tab>

or, you can put the file name in quotes like:

sudo rm "file to you.odt"

There is a reason for this, if you think about it - commands, options and
arguments are separated with spaces on the command line, so it's tricky
for the bash shell to guess which spaces meant what.... If there is a space
it assumes the next word is a file name, so it interprets  file to you as 3
files ( file , to, you ) . Since those files don't exist, it complains ;-)

When creating files I usually separate words using dots - like
file.to.you.odt . You might prefer to use underscores, or hyphens.

Peter



More information about the ubuntu-au mailing list