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.

#include 

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
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.

About

I am a computer enthusiast that has always been interested in maintaining and upgrading computer hardware. I was born on a farm and lived there for 13 years before moving into town. I was always interested in technology and my father always gave me good encouragement for developing my knowledge and interest in tinkering with computers. He was using a computer on the farm but that was in the very late 80`s and late 90`s. Seeing what a computer could do always fascinated me and then I knew that is what I wanted to do. The first time I used Linux was Red Hat 6.2 installed off a single CDROM and I was amazed that you did not need to install any more drivers on my old Intel Celeron machine to be able to enjoy a nice 24BPP desktop and use the GIMP to edit photos and enjoy playing the old Linux games like Xbill. Then a while later I tried Mandrake Linux 9.2 and I was hooked. It came with so much software and was very easy to use as well. Then Mandrake Linux 10 and on through FreeBSD, Debian 3.0, Debian 3.1 Suse Linux 9.2, Suse 10 and onto the Ubuntu distributions although I am using Fedora Core 15 and the Gnome 3 desktop at the moment.

Tagged with: , , , , , ,
Posted in bejiitaswrath

Leave a Reply

Plugin from the creators of Brindes :: More at Plulz Wordpress Plugins