Tips & Tricks


You might find yourself struggling with deleting files with leading or trailing spaces through ‘rm’ command on Linux command line.

For example:

$ rm tempFile
rm: cannot remove `tempFile’: No such file or directory

So we see that rm command says that this file does not exist. But you are pretty confident that file with such name exists. Then the only thing could be that this file name would be having leading or trailing spaces.

You can use double quotes to avoid this problem:

$ rm “tempFile ”

The above command worked in my case.

Note that if you do not want to use double quotes then ‘\ ‘ can be used. Here is an example:

$ rm tempFile\

Remember to add a space after back slash.

Go Back to Menu