So all the linux geeks talk about the shell, what the heck is it? The answer is simple. Unix shell is the powerful command line interpreter, that provides an user interface through the command line. Almost all the operations that are possible with a GUI, can be performed using the shell.
I came to know the immense power of shell more recently (during my internship with hashcube), where i had to log in to a remote server for all my work. That was the time where i learnt a lot about the linux shell since i had no GUI access and that was when i discovered the real power of shell.
The rest of this post might sound hebrew and chinese (why always greek and latin :D) for those who do not know (atleast) the basics of linux shell. In this article, i am going to share the (reasonably impacting) blunders i have made with my unix shell so far in life. Almost everything were done as root (unless mentioned).
- I once typed this in my friend's computer for fun when he was away talking over phone,
rm -rf *And i did not press the enter key. My friend was talking in phone for quite a while and his monitor went to sleep by the time he came back. Guess what he did ? Yeah, he tapped the enter key twice to wake his monitor up and by the time the display came back on he was already scolding me by bad words ;-) Moral: Never tap Enter/Esc key when monitor goes to sleep. To be safe, press keys like alt, ctrl, caps lock.
- To remove all the files in /tmp/foobar, i had to type
rm -rf /tmp/foobar/*But to my ill luck, that folder was empty and hence my tab completion added an extra space before i could type * and hence i typed rm -rf /tmp/foobar/ *Guess what the shell did with this ? Yeah, i lost my entire home directory :-) Moral: Always see the rm command thrice before pressing enter. And to be safe, put the -rf option in the end after checking the rest of the line.
- Recent linux versions have the option of protecting a partition by encryption. I once did an file system check fsck on such an encrypted volume and lost almost everything in it. Moral: Check the filesystem type twice before running a check
- I wanted to create a compressed archive. So i open the shell and quickly type in,
tar -czvf /path/to/file file_archive.tar.gz instead ofYes, i lost the file which i had no backup of!
tar -czvf file_archive.tar.gz /path/to/file
- I had around 1000 files with a # in their name. They were all debug files that were no more required. Hence i decided to remove them using the following command:
rm -rf *#*Well, whats wrong with this? Paste this command in an editor that highlights syntax, and you'll know whats wrong :-)
- I used to have my desktop switched on for days together. To check when it was last rebooted, i typed in
last | reboot instead of last | grep rebootNo need to guess what happened !! :-)
- Try this as root if you are dare enough (or free enough to sit and reinstall your linux now):
chmod -R -x /bin
Go ahead and share more interesting shell mistakes that you have come across.
Note: Throughout this article i have used the terms Unix/Linux interchangably though it is not the same