Hide

What's this?

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/

Get involved!

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.

Universal configuration monitoring and system of record for IT.
Hide

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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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:

Hide

News

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 12,302 results
ps -eo pmem,comm | grep java | awk '{sum+=$1} END {print sum " % of RAM"}'
2016-02-10 09:00:56
User: bugmenot
Functions: awk grep ps sum
0

This command will add up RAM usage of all processes whose name contains "java" and output the sum of percentages in HRF. Also, unlike the original #15430, it wont fail on processes with a usage of >9.9%.

Pleases note that this command wont work reliably in use cases where a significant portion of processes involved are using less than 0.1% of RAM, because they will be counted as "0", even though a great number of them could add up to significant amounts.

adb shell "screencap -p | base64" | sed 's/\r$//' | base64 -d | display
2016-02-07 18:46:35
User: T4b
Functions: sed
1

Dependencies on phone: adb access, screencap command, base64 command.

Dependencies on computer: adb, sed, base64, display (from imagemagick, but can substitute other image viewer which reads from stdin).

This should work around adb stupidies (i.e. that it replaces \n with \r\n) with base64.

sudo system-image-cli --switch ubuntu-touch/rc-proposed/ubuntu --build 0
2016-02-07 18:24:28
User: bugmenot
Functions: sudo
Tags: ubuntu-phone
0

Get the latest and hopefully greatest to test out on the Ubuntu Phone - sometimes broken but always interesting. https://developer.ubuntu.com/en/start/ubuntu-for-devices/image-channels/

sudo mount -o remount,rw /
2016-02-07 17:57:19
User: bugmenot
Functions: mount sudo
0

Warning this will allow you to write to the system image on the phone, not recommended. But sometimes useful.

gsettings reset com.canonical.Unity.Dash favorite-scopes
2016-02-07 17:50:19
User: bugmenot
Functions: reset
0

To fix this bug: https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1389698

fortune | cowsay -f sodomized-sheep
wget https://open.uappexplorer.com/api/download/openstore.mzanetti/openstore.mzanetti_*_armhf.click && pkcon install-local --allow-untrusted openstore.mzanetti_*_armhf.click
2016-02-04 14:24:46
User: bugmenot
Functions: wget
1

This will download and install the latest version of the open store on the ubuntu phone, this store includes unconfined applications such as the TweakGeek and the Ubuntu Touch Tweak Tool. You can see the install instructions from here: https://open.uappexplorer.com/docs#install

ssh-keygen -b 4048 -t rsa -C "comment"
2016-02-03 09:37:39
User: erez83
Functions: ssh ssh-keygen
Tags: ssh centos
0

Generating ssh key

then need to copy public key in to /root/.ssh/authorized_keys

$if [[ "$(sleep 1 | telnet -c <host> <port> 2>&1 | grep '^SSH')" == SSH* ]]; then <command when up>; else <command when down>; fi;
2016-02-02 13:06:51
User: paulera
0

This command telnet and and looks for a line starting with "SSH" - works for OpenSSH since the SSH banner is something like "SSH-2.0-OpenSSH_6.0p1 Debian-4+deb7u3". Then it triggers an action accordingly.

It can be packed as a script file to echo 0/1 indicating the SSH service availability:

if [[ "$(sleep 1 | telnet -c <host> <port> 2>&1 | grep '^SSH')" == SSH* ]]; then echo 1; else echo 0; fi;

Alternative uses:

Trigger an action when server is UP (using &&):

[[ "$(sleep 1 | telnet -c <host> <port> 2>&1 | grep '^SSH')" == SSH* ]] && <command when up>

Trigger an action when server is DOWN (using ||):

[[ "$(sleep 1 | telnet -c <host> <port> 2>&1 | grep '^SSH')" == SSH* ]] || <command when down>
tcpdump -nqt -s 0 -A -i eth0 port 5060
tcpdump -nqt -s 0 -A -i eth0 port 5060
tcpdump -nqt -s 0 -A -i eth0 port 5060
ip=$(curl ip.pla1.net)
sudo strace -e trace=network -p `pidof nginx | sed -e 's/ /,/g'`
2016-01-28 18:48:16
Functions: sed strace sudo
0

Nginx (and other webservers like Apache) can be awkward to trace. They run as root, then switch to another user once they're ready to serve web pages. They also have a "master" process and multiple worker processes.

The given command finds the process IDs of all Nginx processes, joins them together with a comma, then traces all of them at once with "sudo strace." System trace output can be overwhelming, so we only capture "networking" output.

TIP: to kill this complex strace, do "sudo killall strace".

Compare with a similar command: http://www.commandlinefu.com/commands/view/11918/easily-strace-all-your-apache-processes

pacman -Ss python | paste - - | grep --color=always -e '/python' | less -R
2016-01-25 14:29:31
User: hute37
Functions: grep less paste python
Tags: less paste pacman
1

Alternative1 (grep support):

pacman -Ss python | paste - - | grep --color=always -e '/python' | less -R

Alternative2 (eye-candy, no grep):

pacman --color=always -Ss "python" | paste - - | less -R

in ~/.bashrc:

pkg-grep() { pacman -Ss "$1" | paste - - | grep --color=always -e "${2:-$1}" | less -R ; }

pkg-search() { pacman --color=always -Ss "python" | paste - - | less -R; }

ps -eo pmem,comm | grep chrome | cut -d " " -f 2 | paste -sd+ | bc
echo one 22 three | awk -F'[0-9][0-9]' '{print $2}'
get_iplayer --type=radio --channel "Radio 4 Extra" | grep : | awk '{ if ( NR > 1 ) { print } }'|sed 's/:.*//' |sed '$ d' > pidlist && while read p; do get_iplayer --get --fields=pid $p; done <pidlist && rm pidlist
2016-01-16 17:20:54
User: dunryc
Functions: awk grep read rm sed
0

use get_iplay to download all listed content from http://www.bbc.co.uk/radio4extra run every night to make sure no episodes are missed

openssl enc -d -aes-256-cbc -a -in bitcoin-wallet-backup -out bitcoin-wallet-backup-decrypted
stat -f '%Su' /dev/console
declare -a array=($(tail -n +2 /proc/net/tcp | cut -d":" -f"3"|cut -d" " -f"1")) && for port in ${array[@]}; do echo $((0x$port)); done
ffmpeg -loop 1 -i image.jpg -i audio.m4a -c:v libx264 -c:a aac -strict experimental -b:a 192k -vf scale=720:-1 -shortest video-output.mp4
#@source; tar -cf - /path/to/dir | pv | nc -l -p 6666 -q 5; #@target; nc 192.168.1.100 6666 | pv | tar -xf -
sajb {$ip="192.168.100.1";$old=0;while(1){$up=test-connection -quiet -count 1 $ip;if($up-ne$old){$s=(date -u %s).split('.')[0]+' '+(date -f s).replace('T',' ')+' '+$ip+' '+$(if($up){'Up'}else{'Down'});echo $s|out-file -a $home\ping.txt;$old=$up}sleep 10}}
0

IMPORTANT: You need Windows PowerShell to run this command - in your Windows Command Prompt, type

powershell

Uses sajb to start a PowerShell background job that pings an IP host every 10 seconds.

Any changes in the host's Up/Down state is time-stamped and logged to a file.

Date/time stamps are logged in two formats: Unix and human-readable.

A while(1) loop repeats the test every 10 seconds by using the sleep command.

See the Sample Output for more detail.

I use this command to log Up/Down events of my Motorola SB6141 cable modem (192.168.100.1).

To end the logging, close the PowerShell window or use the "exit" command.

while(1){while((date -f ss)%10-gt0){sleep -m 300} echo "$(date -u %s) $((curl 192.168.100.1/cmSignalData.htm).parsedhtml.body.childnodes.item(1).firstchild.firstchild.childnodes.item(5).outertext|%{$_ -replace '\D+\n',''})">>modemlog.txt;sleep 1;echo .}
2015-12-24 02:12:10
User: omap7777
Functions: date echo sleep
0

IMPORTANT: You need Windows PowerShell to run this command - in your Windows Command Prompt, type

powershell

Create a log file of your Motorola Surfboard SB6141 downstream signal strengths.

Uses the built-in curl to request signal strength data from your SB6141 cable modem.

HTML page 192.168.100.1/cmSignalData.htm has the signal strength numbers for the 8 downstreams.

Some HTML/DOM processing parses out the 8 values from the above page.

The eight extracted signal strengths are then logged to a file.

A small while-loop watches the clock & repeats the process every 10 seconds.