Linux 4 All

Best Linux tricks source

There are multiple ways of removing a file that starts with a dash sign (-).

1. Use — option to signal the end of options and disable further options processing

[root@linux4all test]# ls -l
-rw-r--r-- 1 root root 0 Nov  5 23:35 -rf file with space

[root@linux4all test]# rm -f -- -rf\ file\ with\ space

[root@linux4all test]# ls -l
total 0
[root@linux4all test]#

2. Put the full file path between single quotes.

[root@linux4all test]# ls -l
total 0
-rw-r--r-- 1 root root 0 Nov  5 23:43 -rf file with space

[root@linux4all test]# rm -f './-rf file with space'

[root@linux4all test]# ls -l
total 0
[root@linux4all test]#

This is one question you are most likely to get in a job interview, so next time you’ll be prepared.

Configure APC module arrow-right
Next post

arrow-left Remove duplicate RPM packages
Previous post

Leave a Reply

Your email address will not be published. Required fields are marked *