News for hackers. Stuff that matters.
Re:My 10 UNIX Command Line Mistakes by kragen on Monday February 28, 2011 @01:06AM (#2270265)
Here's a compendium of tips for avoiding mistakes like these, largely culled from other comments here, but some from the article.

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.

There are no comments on this comment yet.