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.

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

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 11,848 results
yum list installed| awk '{print $1}'| grep -e "x86" -e "noarch" | grep -v -e '^@'| sort
2014-08-06 23:13:24
Functions: awk grep
0

Great for moves, re-installs etc since it is not version specific yet is architecture specific.

Centos yum list is well know for wrapping lines .

sudo dpkg -P $(dpkg -l yourPkgName* | awk '$2 ~ /yourPkgName.*/ && $1 ~ /.i/ {print $2}')
2014-08-06 22:40:32
User: wejn
Functions: awk sudo
Tags: dpkg purge
0

Recently in Debian Wheezy the dpkg command refuses to work with wildcards, so this is the one-liner alternative. (alternative to #13614)

sudo restart lightdm
svn merge -r 854:853 l3toks.dtx
hl() { while read -r; do printf '%s\n' "$(perl -p -e 's/('"$1"')/\a\e[7m$1\e[0m/g' <<< "$REPLY")"; done; }
(echo -e '\x06\x00\x00\x00\x00\x00\x01\x01\x00'; sleep 1)|nc -c $host 25565
w !sudo cat >%
sudo dpkg -P $(sudo dpkg -l yourPkgName* | awk '$2 ~ /yourPkgName.*/' | awk '$1 ~ /.i/' | awk '{print $2}')
2014-08-02 18:14:02
User: woohoo
Functions: awk sudo
Tags: dpkg purge
0

Recently in Debian Wheezy the dpkg command refuses to work with wildcards, so this is the one-liner alternative.

On target: "nc -l 4000 | lz4c -d - | tar xvf -" On source: "tar -cf - . | lz4c | nc target_ip 4000"
2014-08-02 05:09:30
User: baitisj
Tags: tar nc lz4
0

Adds high-performance, lightweight lz4 compression to speed the transfer of files over a trusted network link. Using (insecure) netcat results in a much faster transfer than using a ssh tunnel because of the lack of overhead. Also, LZ4 is as fast or faster than LZ0, much faster than gzip or LZMA, an in a worst-case scenario, incompressible data gets increased by 0.4% in size. Using LZMA or gzip compressors makes more sense in cases where the network link is the bottleneck, whereas LZ4 makes more sense if CPU time is more of a bottleneck.

function say { wget -q -U Mozilla -O google-tts.mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=$1&q=$2" open google-tts.mp3 &>/dev/null || mplayer google-tts.mp3 &>/dev/null; rm google-tts.mp3; }
2014-08-01 23:43:16
User: Zath
Functions: rm wget
0

Improved google text-to-speech function. Allows to specify language, plays sound in terminal. Automatically removes downloaded file after successfully processing.

Usage:

say LANGUAGE TEXT

Examples:

say en "This is a test." say pl "To jest test"
Mac OSX: ping -oc 30 8.8.4.4 > /dev/null && say "Google name server is up" || say "This host is down"
2014-08-01 15:44:57
User: raulyca
Functions: ping
Tags: ping beep
4

Audio acknowledgement for host availability.

When running the command from a Linux systems, you can use "festival" or "espeak" instead of "say".

netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head
echo "scale=1000; 4*a(1)" | bc -l
2014-07-31 19:13:26
User: regulatre
Functions: bc echo
0

Change the scale to adjust number of decimal places

prefix the command with "time" to benchmark the computer (compare how long it takes to calculate 10000 digits of pi on various computers).

tar -vzc /path/to/cool/directory | ssh -q my_server 'tar -vzx -C /'
2014-07-31 18:42:57
User: regulatre
Functions: ssh tar
0

Copy a local directory to a remote server using ssh+tar (assume server is lame and does not have rsync).

tar cvzf - dir | ssh my_server 'tar xzf -'
watch -n5 ss \| grep -c WAIT
2014-07-30 17:09:08
User: djpohly
Functions: grep watch
Tags: tcp ss iproute2
0

Uses the suggestions by jld on #12421 as well as the new iproute2 tools instead of old net-tools.

find /var/log -type f -iregex '.*[^\.][^0-9]+$' -not -iregex '.*gz$' 2> /dev/null | xargs tail -n0 -f | ccze -A
2014-07-29 17:11:17
User: rubo77
Functions: find tail xargs
Tags: unix ccze logging
3

This will show all changes in all log files under /var/log/ that are regular files and don't end with `gz` nor with a number

changeFolder() { if [ $# -ne 2 ]; then echo "Usage: changeFolder old new"; return; fi; old=$(pwd); folder=$(echo "$old" | sed -e "s/$1/$2/g"); if [ ! -d "$folder" ]; then echo "Folder '$folder' not found."; return; fi; echo "$old -> $folder"; cd $folder;}
2014-07-29 15:36:32
User: Dracks
Functions: cd echo sed
0

change the path where you are, when is executed, is usefule when you've got folders to classify something like a tags, you've got devel/dist, android/ios, etc. like:

~user/Documents/devel/project

~user/Documents/dist/project

You can change between devel/project folder to dist/project without leave project.

If somebody has a better idea to do that without replace command.

awk -F: '{print $2}' access_log | sort | uniq -c
emerge -a `qcheck -aCB`
sudo bash -c "cd /PATH/TO/THE/DIRECTORY;bash"
2014-07-28 20:20:04
User: Zath
Functions: bash sudo
0

Change current working directory with root permissions.

Place this snippet in your .bashrc to add a new "sudocd" command:

function sudocd { sudo bash -c "cd $1;bash" }

Usage: sudocd DIRECTORY

Please note that if you will use this command to cd into directories with the permissions allowing only root to be in them, you will have to use sudo as a prefix to every command that changes/does something in that directory (yes, even ls).

for a in $(seq 15); do (xset led 3);(xset -led 3);sleep .9;done
docker ps -q | xargs -n 1 docker inspect | jq '.[0].NetworkSettings.Ports +{} | map(select(. != null)[0].HostPort) | map("-L \(.):localhost:\(.)") ' | sed -n 's/.*"\(.*\)".*/\1/p' |xargs boot2docker ssh -N
docker inspect -f "{{ .NetworkSettings.IPAddress }}" $CONTAINERID
docker kill $(docker ps -q)