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.
#includeint 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 7 a This is another line I am adding to a text file. ^C ? w 56 q john@deusexmachina:~/Desktop$ cat hello Hello. This is another line I am adding to a text file. john@deusexmachina:~/Desktop$
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.
