We\'ve detected that you\'re using AdBlock Plus or some other adblocking software. Please be aware that this is only contributing to the demise of the site. We need money to operate the site, and almost all of that comes from our online advertising.

Linux tips and tricks for all users.

Deleting a file named -f and other Linux tricks.

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.

john@deusexmachina:~/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.

john@deusexmachina:~/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.

john@deusexmachina:~/Desktop$ ed hello
This is another line I am adding to a text file.
john@deusexmachina:~/Desktop$ cat hello 
This is another line I am adding to a text file.

This is continuing on from my old posting about the UNIX ed editor here: http://doomersthoughts.blogspot.com.au/2011/07/unix-ed-editor.html.

Post a Comment

Your email is kept private. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current day month ye@r *