commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
Crash Override, man!
Apparently the exec call tricks BASH into setting the output buffer size to 0 under the assumption that the system (or the calling shell) will handle the output buffering. trapping the ERR signal will stop the subshell from dying and sending the ERR signal to the main script--which will terminate immediately if it does--when the program fails.
The only problem is that the kernel will output a whole bunch of stack trace garbage directly to the console device once the process segfaults, so there's no way to prevent it from being output [that I know of].
Check out the usage of 'trap', you may not have seen this one much. This command provides a way to schedule commands at certain times by running them after sleep finishes sleeping. In the example 'sleep 2h' sleeps for 2 hours. What is cool about this command is that it uses the 'trap' builtin bash command to remove the SIGHUP trap that normally exits all processes started by the shell upon logout. The 'trap 1' command then restores the normal SIGHUP behaviour.
It also uses the 'nice -n 19' command which causes the sleep process to be run with minimal CPU.
Further, it runs all the commands within the 2nd parentheses in the background. This is sweet cuz you can fire off as many of these as you want. Very helpful for shell scripts.
You can set the previous bash command as the terminal title by this command.
-trap assigns a command to execute at a given bash signal.
-in the $BASH_COMMAND you find the last command
-you can set the terminal title with the escape sequence: \e]0;this is the title\007
-to let the echo care about the backslashes give the -e to it
Since trap is a built in bash command you find more informatin in 'man bash'for more
Cleanly create tempfiles using mktemp and remove them using traps instead of removing them in the end of the script. This way, you make sure the tempfiles are removed properly even if the script is killed or interrupted.
For a user script in KDE4, you can set TMPROOT using :
TMPROOT=$(kde4-config --path tmp)