My 10 UNIX Command Line Mistakes
cyberciti.biz
cyberciti.biz
I ended up restoring from backup.
This way I can be sure I'm typing `halt` into the right box, because it's easier to spot the wrong color than the wrong hostname in 10pt text.
Usually I'll just do things like df on the wrong machine and wonder what's going on with my disk space, but I've made a few less happy errors in the past.
I use a similar style:
[alfie] ~$
[rupert] ~$
etc. for my SSH connections, but not for local shells, even though I also use screen. I also use color-coded prompts for selecting particular PATH and other environment variable setups for different branches of our corporate dev tree, to remind myself which compiler etc. I'm using.PS1="\[\033[0m\](\[\033[0;36m\]\u\[\033[0m\]@\[\033[0;33m\]\h\[\033[0m\])(\[\033[1;34m\]\w\[\033[0;0;0m\])"
Try adding to ~/.screenrc
caption always "| %L=%-Lw%45>%{+b by}%n%f* %t%{-}%+Lw%-0<"
Not done that exact one, but I've added firewall rules that cut me out in exactly the same way.
Another favourite is typing "shutdown -h now" into the wrong terminal: I know a few people who have admitted to doing that.
http://packages.debian.org/sid/molly-guard is a good remedy for this :)
I do that less now that the machine's hostname is prominently displayed in my prompt.
I thought I was logged into my home server. Turns out I shut down the main web server. Oops!
./mkzone example.com > /var/named/chroot/etc/named.conf
in at least tcsh, "set noclobber" will help with this. when you try to overwrite a file that exists (usually from doing > instead of >>) you will get an error that the file exists instead. if you really want to overwrite the file, you have to use ">!".
A nice safety feature that's already saved my bacon.
`cp -r folder backup` turns out folder was a symlink. Then I messed up my script and deleted all of the contents. Backup was destroyed with the original since I copied the symlink instead of the directory. Luckily I had just setup a slave server and was able to copy 95% of the files from there.
Recently I did a `rm -rf /directory/` instead of a `rm -rf /directory/directory2`. Once again luckily I had real backups.
Every-time I screw up, or a system has problems (stupid hard drives) the belief that backups the most important part of a system is reinforced. It basically doesn't matter what you do if you have proper backups you can recover.
The catch there is that no backup is truly a backup until it is tested.
Unfortunately, even that is not enough, in the long run.
You have to periodically retest your backups, and transfer them to new media as they age.
It's also a good idea to store backups off-site (preferably in multiple geographically-dispersed locations).
And, it almost goes without saying that the more frequently you do backups, the less data you'll lose when you actually have to restore from them.
Before long, it's a full time job just to keep the backup system humming along smoothly, testing and retesting backups, and transferring them from old media to new.
Of course, this problem gets a lot harder and more time consuming as the quantity of data you need to backup/restore grows.
I keep reading about the crazy amounts of data generated by projects like the LHC, and my mind boggles at what the challenges in doing backups of that amount of data must be like.
1. Never `rm `, especially `-rf`. If you must, `rm -rf ../tmp/` or similar. You do not want this command to be in your history. Especially in the form `rm -rf * & cd; trn`.
2. Set up backups early on. Use `git` or similar for as much as possible.
3. `noclobber` (or not setting CLOBBER in zsh) may help. I found `noclobber` irritating because it also refused to append to nonexistent files.
4. Take three deep breaths after typing and before executing a `shutdown` or `rm -r` command, or typing a password at a password prompt. (Did you just give your intranet server password to whoever has backdoored your weekend-project VPS?)
5. Keep backups in a format that you can readily verify is usable. `rsync` with `--link-dest` is handy for this, as is `git`.
6. When referring to a directory that you believe exists, don't say `foo/bar/baz`. Say `foo/bar/baz/.` so that whatever command doesn't try to create the directory `baz` if it doesn't exist yet.
7. Color-coded prompts or terminal windows by server.
8. Tab-complete to ensure that things exist.
9. Use `sudo` instead of root shells.
10. Keep your config files in source control. RCS is okay, but Git is better.
I'm observing the exact opposite. While the official project sites show indeed only success stories, I'm observing a trend that those sites increasingly add a "blog" section where the developers talk freely about their experiences and mistakes.
> I'm dreaming to see the academic papers where instead of all the wonderful results you'll see the errors path to reach the final result.
This would not only be great, but should be mandatory (maybe by law) in order to get rid of the publication bias. (http://en.wikipedia.org/wiki/Publication_bias)
So, having finished first, I type "rm cobol < a.txt > a.out", and I spend a while wondering what "cobol not found" means before I realise what I've done.
[unix syntax from memory, may be wrong]
Deleted comment
As a young programmer on my first real programming job, an online stock broker in 1999, I did this. I had been running Linux since -95 and was familiar with Solaris from college. I had no idea about this though. I was so ashamed, but I didn't face any dire consequences.
I will never forget my lesson (then again, I will probably not be managing Solaris anymore).
I have also done variations on "ifconfig eth1 down" (or messing around with iptables) on a remote computer.
I would imagine just about everyone from the same era who was newly exposed to administering both sunos/solaris and linux probably did the same thing. (the longbeards who already new Sunos/solaris would already know better)
But seriously.. what a stupid command. What was the practical value of "killall" on solaris? seriously?
Even git clone follows this convention.
4. Use CVS to store configuration files.
using CVS ? even if it was written 2009 that still pretty backward...
mv stuffwithoutbackup tosomeotherplacewithatypointhepath
curse at typo
rm -rf tosomeotherplacewithatypointhepath
curse more vigorously
scp file linuxbox:~
# on linux box # I now have a file called /home/me/~
rm ~
# some stupid error...
rm -fr ~
# that's taking a while...
NOOOOOOO!
Its no type, its a steam locomotive. http://www.freebsdsoftware.org/games/sl.html
*nix newbie here - how is a process determined to be active vs not? Wouldn't this completely tank the machine?
killall terminates all processes with open files so that the mounted file systems will be unbusied and can be unmounted.
killall sends signal (see kill(1)) to the active processes. If no signal is specified, a default of 15 is used.
Try and guess where I got that info from.
sudo chown -R me:mygroup .*
Fortunately, I caught it before it made it out of /home, so only some user directories were affected, and the cleanup was relatively straightforward.