Bash Filenames – How to Delete a File Named ‘>’

bashfilenamesquotingrm

I was running a Python script that malfunctioned and used sudo to create a file named >.

How can I get rid of this file?

Of course, when I try sudo rm >, I get the error bash: syntax error near unexpected token 'newline', because it thinks I'm trying to redirect the output of rm.

Its permissions are -rw-r--r--.

Best Answer

Any of these should work:

sudo rm \>
sudo rm '>'
sudo rm ">"
sudo find . -name '>' -delete
sudo find . -name '>' -exec rm {} +

Note that the last two commands, those using find, will find all files or directories named > in the current folder and all its subfolders. To avoid that, use GNU find:

sudo find . -maxdepth 1 -name '>' -delete
sudo find . -maxdepth 1 -name '>' -exec rm {} +
Related Question