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,927 results
cat File.txt | grep -io 'http://www.acme.com/a/files/.*.pdf'| uniq
for i in `lanscan -i | awk '{print $1}'` ; do ifconfig $i ; done 2> /dev/null
netstat -nr|egrep -v "Routing|Interface|lo0"|awk '{print $5}'|sort -u| while read l; do ifconfig $l ; echo " Station Addr: `lanscan -ia|grep "$l "|cut -d ' ' -f 1`" ; done
jhead -n%Y-%m-%d_%H-%M-%S__%f *.JPG
for i in `ls` ; do date=$(identify -format %[exif:DateTime] $i); date=${date//:/-}; date=${date// /_}; mv $i ${date}__$i; done
find -type f -exec ffmpeg -i "{}" "{}".mp3 \;
lsof -ns | grep REG | grep deleted | awk '{s+=$7/1024} END {print s}'
ip a s eth0 | sed -nr 's!.*inet ([^/]+)/.*!\1!p'
ls *.png | cut -d . -f 1 | xargs -L1 -i convert -strip -interlace Plane -quality 80 {}.png {}.jpg
find . -name *.png | xargs optipng -nc -nb -o7 -full
tar -cvf bind9-config-`date +%s`.tar *
2014-10-29 05:15:15
User: Fuonum
Functions: tar
-1

backup your files in tar archive + timestamp of backup

cut -d: -f1 /etc/group | sort
setxkbmap -option caps:backspace
2014-10-27 22:53:39
User: lgarron
0

The internet is full of advice about how to change the caps lock key into a backspace key (a useful practice that originated with Colemak), but a lot of instructions are complicated or outdated.

After *lots* of searching for something that still worked on Ubuntu 14.04, I finally found that this simple command is sufficient and takes effect immediately.

(Found at: http://www.howtogeek.com/194705/how-to-disable-or-reassign-the-caps-lock-key-on-any-operating-system/ )

=() {python3 -c "from math import *;print($*)"}
echo $(wget http://ipecho.net/plain -q -O -)
2014-10-25 20:25:05
User: KonKar
Functions: echo wget
0

Easiest way to get the external IP address.

cat /etc/named.conf | grep -Po '(?<=(named/)).*(?=\.db)'
2014-10-25 20:16:17
User: KonKar
Functions: cat grep
0

Allows you to have a list of the domains on the server.

git branch -r | awk -F'/' '{print "git fetch "$1,$2}' | xargs -I {} sh -c {}
du -hL --max-depth=1
gunzip -c x.txt.gz >x.txt
find . -name '*.jar' | xargs -l jar vtf | grep XXX.java
fortune | cowsay $(ls/usr/share/cowsay | shuf -n1)
2014-10-23 10:09:44
0

To install on centos 6.2

for Centos auto accept:

yum install fortune* -y

yum install cowsay* -y

Removed the -f command as I dont know how, but it works without it.

Almost the same but one folder higher =).

dmesg
2014-10-22 10:03:56
User: sagarsakre
Functions: dmesg
0

The dmesg will show the kernel it is booting. No more dependency on files

dumpe2fs -h /dev/xvda1 | egrep -i 'mount count|check'
2014-10-22 08:38:43
User: manju712
Functions: dumpe2fs egrep
0

To check the total number of mounts, maximum number of mounts before performing the fsck and last time when the fsck was performed.

wait 536; anywait 536; anywaitd 537; anywaitp 5562 5563 5564
2014-10-22 06:31:47
User: colemar
Functions: wait
0

Silent:

anywait () { for pid in "$@"; do while kill -0 "$pid" >/dev/null 2>&1; do sleep 0.5; done; done }

Prints dots:

anywaitd () { for pid in "$@"; do while kill -0 "$pid" >/dev/null 2>&1; do sleep 0.5; echo -n '.'; done; done }

Prints process ids:

anywaitp () { for pid in "$@"; do while kill -0 "$pid" >/dev/null 2>&1; do sleep 0.5; echo -n $pid' '; done; echo; done }

You cannot anywait for other users processes.

rsync --recursive --info=progress2 <src> <dst>
2014-10-21 22:19:44
User: koter84
Functions: rsync
Tags: rsync progress
0

update the output of rsync after completing a file but don't create newlines, just overwrite the last line, this looks a lot better in scripts where you do want to see a progress-indicator, but not the lengthy logs

this option is available since rsync 3.1.0