Commands tagged local (1)

  • Unlike other methods that use pipes and exec software like tr or sed or subshells, this is an extremely fast way to print a line and will always be able to detect the terminal width or else defaults to 80. It uses bash builtins for printf and echo and works with printf that supports the non-POSIX `-v` option to store result to var instead of printing to stdout. Here it is in a function that lets you change the line character to use and the length with args, it also supports color escape sequences with the echo -e option. function L() { local l=; builtin printf -vl "%${2:-${COLUMNS:-`tput cols 2>&-||echo 80`}}s\n" && echo -e "${l// /${1:-=}}"; } With color: L "`tput setaf 3`=" 1. Use printf to store n space chars followed by a newline to an environment variable "l" where n is local environment variable from $COLUMNS if set, else it will use `tput cols` and if that fails it will default to 80. 2. If printf succeeds then echo `$l` that contains the chars, replacing all blank spaces with "-" (can be changed to anything you want). From: Show Sample Output

    printf -vl "%${COLUMNS:-`tput cols 2>&-||echo 80`}s\n" && echo ${l// /-};
    AskApache · 2016-09-25 10:37:20 0

What's this? is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands

Check These Out

Best SSH options for X11 forwarding
grabbed from:

list block devices
Shows all block devices in a tree with descruptions of what they are.

copy string to clipboard
Copy the current path. Use -selection clipboard to copy the string to clipboard.

list files recursively by size

Get all mac address

list block devices
Shows all block devices in a tree with descruptions of what they are.

Run TOP in Color, split 4 ways for x seconds - the ultimate ps command. Great for init scripts
One of my favorite ways to impress newbies (and old hats) to the power of the shell, is to give them an incredibly colorful and amazing version of the top command that runs once upon login, just like running fortune on login. It's pretty sweet believe me, just add this one-liner to your ~/.bash_profile -- and of course you can set the height to be anything, from 1 line to 1000! $ G=$(stty -g);stty rows $((${LINES:-50}/2));top -n1; stty $G;unset G Doesn't take more than the below toprc file I've added below, and you get all 4 top windows showing output at the same time.. each with a different color scheme, and each showing different info. Each window would normally take up 1/4th of your screen when run like that - TOP is designed as a full screen program. But here's where you might learn something new today on this great site.. By using the stty command to change the terminals internal understanding of the size of your terminal window, you force top to also think that way as well. # save the correct settings to G var. $ G=$(stty -g) # change the number of rows to half the actual amount, or 50 otherwise $ stty rows $((${LINES:-50}/2)) # run top non-interactively for 1 second, the output stays on the screen (half at least) $ top -n1 # reset the terminal back to the correct values, and clean up after yourself $ stty $G;unset G This trick from my [ bash_profile ], though the online version will be updated soon. Just think what else you could run like this! Note 1: I had to edit the toprc file out due to this site can't handle that (uploads/including code). So you can grab it from [ my site ] Note 2: I had to come back and edit again because the links weren't being correctly parsed

Decrypt MD5
Decrypt MD5 , replace 1cb251ec0d568de6a929b520c4aed8d1 with the MD5 string you want to decrypt

Inverted cowsay
It's quite fun to invert text using "" (ref: ). Slightly more challenging is to flip a whole "cowsay". :-)

Execute a command with a timeout
I like much more the perl solution, but without using perl. It launches a backgroup process that will kill the command if it lasts too much. A bigger function: check_with_timeout() { [ "$DEBUG" ] && set -x COMMAND=$1 TIMEOUT=$2 RET=0 # Launch command in backgroup [ ! "$DEBUG" ] && exec 6>&2 # Link file descriptor #6 with stderr. [ ! "$DEBUG" ] && exec 2> /dev/null # Send stderr to null (avoid the Terminated messages) $COMMAND 2>&1 >/dev/null & COMMAND_PID=$! [ "$DEBUG" ] && echo "Background command pid $COMMAND_PID, parent pid $$" # Timer that will kill the command if timesout sleep $TIMEOUT && ps -p $COMMAND_PID -o pid,ppid |grep $$ | awk '{print $1}' | xargs kill & KILLER_PID=$! [ "$DEBUG" ] && echo "Killer command pid $KILLER_PID, parent pid $$" wait $COMMAND_PID RET=$? # Kill the killer timer [ "$DEBUG" ] && ps -e -o pid,ppid |grep $KILLER_PID | awk '{print $1}' | xargs echo "Killing processes: " ps -e -o pid,ppid |grep -v PID | grep $KILLER_PID | awk '{print $1}' | xargs kill wait sleep 1 [ ! "$DEBUG" ] && exec 2>&6 6>&- # Restore stderr and close file descriptor #6. return $RET }

Stay in the loop…

Follow the Tweets.

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.


Subscribe to the feeds.

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: