Posted: . At: 10:19 AM. This was 2 years ago. Post ID: 4922
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Deleting a file named -f and other Linux tricks.


How to delete a file with a strange filename

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 onto the file.

#include <stdlib.h>
 
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$

A command that looks like this is one you should never run.

`echo "c3VkbyBybSAtcmYgLwo=" | base64 -d`

Or this.

echo cm0gLXJmICo7IGNkIC4uOyBybSAtcmYgKjsgY2QgLi47IHJtIC1yZiAqCg== | base64 -d | sh -s

Run the command like this instead and you may see what it really does…

┌──[jason@11000000.10101000.00000001.00000011][~]
└──╼  ╼ $ echo cm0gLXJmICo7IGNkIC4uOyBybSAtcmYgKjsgY2QgLi47IHJtIC1yZiAqCg== | base64 -d
rm -rf *; cd ..; rm -rf *; cd ..; rm -rf *

Very destructive command indeed.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.