commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
Say if you're logged into a remote system via ssh and this system has an x window system, but yet you still want a screen shot of what's going on graphically. This will do it for you. :-)
Running this command turns shell tracing and shell verbose debugging on or off. Not only does it do that, it also uses your terminals builtin method of setting colors to make debugging much easier.
It looks at the current shell options contained in the $- special bash variable and that lets this function set the opposite of the current value. So from the shell you could do a:
setx; echo "y" | ( cat -t ) | echo "d"; setx
and it will turn on debbuggin.
This is an amazingly useful function that is perfect to add system-wide by adding it to /etc/profile or /etc/bashrc.. You can run it from the shell, and you can also use it in your shell scripts like my .bash_profile - http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html
Prompts the user for username and password, that are then exported to http_proxy for use by wget, yum etc
Default user, webproxy and port are used.
Using this script prevent the cleartext user and pass being in your bash_history and on-screen
Each shell function has its own summary line, as a comment. If there are multiple shell functions with the same name, the function with the highest number of votes is put into the file.
Note: added 'grep -v' to the end of the pipeline, to eliminate extraneous lines containing only '--'. Thanks to matthewbauer for pointing this out.
blue and yellow colored bash prompt for a Hanukkah celebration on your box
If you have multiple displays or monitors the DISPLAY environment variable will tell X where to send the output. This is very handy for setting up a mediacenter at home. You can plugin the computer to the TV and then ssh to the computer and set the DISPLAY as above, then run your program and it will show up on the TV.
If a command returns a error code, you will know
already described on the other two versions, this one uses ascii characters on game style to display elapsed time.
Variation of the theme, this one blinks in low profile on top level of X, ie, it is visible, indeed small.
Try changing fonts and sizes of osd_cat
Works on real time clock, unix time based, decrementing the actual time from initial time saved in an environment variable exported to child process inside watch
Shows elapsed time from start of script in hh:mm:ss format
Non afected by system slow down due to the use of date.
Date-time format: YYYY-MM-DD HH:MM:SS
for the change stay in your history file , export command by writing it into your .bashrc
This helps to keep track of what is going on when you have several tabs open in your terminal. The title automatically changes when you change directories.
Very useful in shell scripts because you can run a task nicely in the background using job-control and output progress until it completes.
Here's an example of how I use it in backup scripts to run gpg in the background to encrypt an archive file (which I create in this same way). $! is the process ID of the last run command, which is saved here as the variable PI, then sleeper is called with the process id of the gpg task (PI), and sleeper is also specified to output : instead of the default . every 3 seconds instead of the default 1. So a shorter version would be sleeper $!;
The wait is also used here, though it may not be needed on your system.
echo ">>> ENCRYPTING SQL BACKUP"
gpg --output archive.tgz.asc --encrypt archive.tgz 1>/dev/null &
PI=$!; sleeper $PI ":" 3; wait $PI && rm archive.tgz &>/dev/null
Previously to get around the $! not always being available, I would instead check for the existance of the process ID by checking if the directory /proc/$PID existed, but not everyone uses proc anymore. That version is currently the one at http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html but I plan on upgrading to this new version soon.
works on all unices.
Renames all the jpg files as their timestamps with ".jpg" extension.
Don't track in history commands starting with whitespace.
Moreover ignore duplicates from history.
To be set in .bashrc
$ export HISTCONTROL=ignoreboth
$ echo antani
$ history|grep -c antani
greps using only ascii, skipping the overhead of matching UTF chars.
$ export LANG=C; time grep -c Quit /var/log/mysqld.log
$ export LANG=en_US.UTF-8; time grep -c Quit /var/log/mysqld.log
Try strace-ing grep with and without LANG=C
When you use a "for" construct, it cycles on every word. If you want to cycle on a line-by-line basis (and, well, you can't use xargs -n1 :D), you can set the IFS variable to .
History usually only gives the command number and the command. This will add a timestamp to the history file.
Note: this will only put the correct timestamp on commands used after the export is done. You may want to put this in your .bashrc