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

Hide

Credits

All commands from sorted by
Terminal - All commands - 12,180 results
:set number
2013-10-07 15:03:52
User: sonic
Tags: vim vi
0

Prints line numbers making it easier to see long lines that wrap in your terminal and extra line breaks at the end of a file.

:set nu

works too.

find . -name "*.DS_Store" -type f -delete
touch /forcefsk
(cd SRC; find . -type d -exec mkdir TARGET/{} ";"; find . -type f -exec mv {} TARGET/{} ";")
2009-08-17 12:35:48
User: karel1980
Functions: cd find mkdir mv
0

Using a GUI file managers you can merge directories (cut and paste). This command roughly does the same (it doesn't ask for confirmation (no problem for me) and it doesn't clean up the empty SRC directories (no problem, trivial).

probably does the same:

cp -l SRC TARGET; rm -rf SRC
i=60;while [ $i -gt 0 ];do if [ $i -gt 9 ];then printf "\b\b$i";else printf "\b\b $i";fi;sleep 1;i=`expr $i - 1`;done
cat /etc/squid/squid.conf | grep -v '^#' | sed '/^$/d'
ldd file | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' /destination
2012-02-11 17:50:10
User: rickard2
Functions: awk cp file grep ldd xargs
0

When working with jailed environments you need to copy all the shared libraries to your jail environment. This is done by running ldd on a binary which needs to run inside the jail. This command will use the output from ldd to automatically copy the shared libraries to a folder of your choice.

git diff | git apply --reverse
feh --bg-scale "`ls -d $HOME/backgrounds/* |sort -R |tail -1`"
2013-03-16 16:05:48
User: bertatum
0

Change your Desktop background/wallpaper with feh lightweight command.

fill background directory with appropriate content.

echo c > /proc/sysrq-trigger
2013-05-07 19:41:40
User: fangfufu
Functions: echo
Tags: kernel
0

Well, this is quite useful for testing if your hardware watchdog is working properly.

sed -i 's/^/ls -l /' output_files.txt
2013-10-07 15:12:53
User: sonic
Functions: sed
Tags: sed replace
0

The original command is great, but I often want to prepend to every line.

convert yourdoublewideimage.jpg -crop 50%x100% +repage output.jpg
2014-01-15 15:34:41
User: pagesix1536
0

Output should be two JPG files named like "output-1.jpg" and "output-2.jpg". The convert command is part of ImageMagick so you'll need that and dependent packages installed to use it.

git commit --allow-empty-message --message ""
2014-07-16 02:06:39
0

This is especially useful for adding changes to a temporary repo, such as a Gist. Avoid using this when collaborating with others.

pm2 start app.js
2014-11-07 23:15:12
User: strzel_a
0

I'm the author of PM2 and wrote this tool, and I'm please to share it here.

Github project link: https://github.com/Unitech/pm2

(acroread &);sleep 2;gdb /opt/Adobe/Reader8/Reader/intellinux/bin/acroread `pidof ld-linux.so.2`
echo 2+3 |bc
2009-07-04 22:03:41
User: Kaio
Functions: echo
0

Handy use of bc in the command line. No need to get 'into' the bc to perform calculations

perl -ne '$pkg=$1 if m/^Package: (.*)/; print "$1\t$pkg\n" if m/^Installed-Size: (.*)/;' < /var/lib/dpkg/status | sort -rn | less
2009-10-19 12:55:59
User: hfs
Functions: perl sort
0

List packages and their disk usage in decreasing order. This uses the "Installed-Size" from the package metadata. It may differ from the actual used space, because e.g. data files (think of databases) or log files may take additional space.

type <command>
find . -name "*.php" -exec grep -i -H "search pharse" {} \;
awk '{if ($1~/Sun|Mon|Tue|Wed|Thu|Fri|Sat/) {DATE=$2" "$3" "$4" "$5 } else {print DATE"|"$0}}' alterorcl.log
sudo netstat|head -n2|tail -n1 && sudo netstat -a|grep udp && echo && sudo netstat|head -n2|tail -n1 && sudo netstat -a|grep tcp
echo foobar | sed -r 's/(^.|.$)//g'
(sed 's/^/x*=/' file ; echo x) | bc
DATE=`date +"%H:%M" --date '-1 min'`; egrep "\ $DATE\:..\ " /var/log/dhcpd.log |awk '/DHCPREQUEST/ {split($3,t,":"); printf("%02d:%02d\n",t[1],t[2]);}' |uniq -c;
hexdump -C file