Deleting a file named -f and other Linux tricks.

Posted: November 29, 2012. At: 10:19 AM. This was 5 years ago. Post ID: 4922
Page permalink:

Now, we must convince Congress to stop the FCC. Can you display an alert?

This can be an annoying trick to play on someone. Create a file named -f with this command: >-f and then ask them to delete it with the command-line only. This can be frustrating exercise; you try to use rm \-f and that does not work; then you try something else like rm “-f” and the file is still there. The trick I discovered is to use this command.

[email protected]:~/Desktop$ rm -- -f

This will delete that file easily. This is another command I saw on the web that someone was wanting people to run.

[email protected]:~/Desktop$ chmod -x $(which chmod)

This will remove the executable permissions on the chmod command and then you will be unable to run it again to fix this. Not a good idea to run this command at all though as fixing it would be fun. But the best way would be to run this C program on it and it will set the executable flag back on to the file.


int main(void) {

	chmod("/bin/chmod", 0755);
	return 0;

I would not actually do this; but this is an interesting exercise anyway. Getting back to the file deletion; deleting a file named -e is the same as -f and you just use the same fix as above for that. Below I am using the ed UNIX line editor to add a line of text to a text file. This editor is not too hard to use; editing a file one line at a time. Just load the ed editor and then press the a key to start appending text and then type away.

[email protected]:~/Desktop$ ed hello
This is another line I am adding to a text file.
[email protected]:~/Desktop$ cat hello 
This is another line I am adding to a text file.
[email protected]:~/Desktop$

This is continuing on from my old posting about the UNIX ed editor here:

No comments have been made. Use this form to start the conversation :)

Leave a Reply