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,162 results
stat -c "%s" <file>
atq |sort -k 6n -k 3M -k 4n -k 5 -k 7 -k 1
2012-05-03 23:15:08
User: klepsydra
Functions: atq sort
0

couldn't stand previous unsortability of at jobs list

aptitude purge $(dpkg -l|grep ^rc|awk '{ print $2 }')
readlink -fn foo | xsel -ib
2013-03-09 14:15:31
User: zplesivcak
Functions: readlink
0

'readlink -fn' gets canonical path of the file/directory without newline at the end;

'xsel -ib' copies pipelined string from STDIO to system clipboard (ready to be pasted with CTRL+V).

curl -s -k https://www.kernel.org/feeds/kdist.xml | sed -n -e 's@.*<guid>\(.*\)</guid>.*@\1@p' | grep 'stable' | head -1 | awk -F , '{print $3}'
2013-12-17 23:59:27
User: Wafelijzer
Functions: awk grep head sed
Tags: kernel
0

Fetches latest stable release version from first entry between tags

ssh <user>@<ip address> $(echo wmic process where \"name like \'%<process to kill>%\'\" delete)
2014-07-02 04:41:05
User: adanisch
Functions: echo ssh
0

Tested on Windows 8 w/SSH, Cygwin - it can be tricky to quote if you dont use the $(..) syntax to echo it back out

command foo bar | sudo tee /etc/write-protected > /dev/null
xmms `python -c "print \"tone://\" + \";\".join([str(22*(2**x)) for x in range(9)])"`
S=`pidof skype`;grep heap /proc/$S/maps|cut -f1 -d' '|awk -F- '{print "0x" $1 " 0x" $2}'|xargs echo "du me t ">l;gdb -batch -p $S -x l>/dev/null 2>&1;strings t|grep \(smirk|head -n1
2009-06-26 20:03:17
User: alvieboy
Functions: awk cut echo grep head xargs
0

Skype has an internal regex which depicts the emoticons it supports. However you cannot simply search the binary file for it. This small 181 character line will do just that, provided skype is running. And of course, only works in linux.

$(while [ ! -z "$(pgrep rsync)" ]; do echo; done; echo "rsync done" | mailx user@example.com) > /dev/null &
2009-08-14 19:46:59
User: matthewbauer
Functions: echo mailx
0

This will email user@example.com a message with the body: "rsync done" when there are no processes of rsync running. This can be changed for other uses by changing $(pgrep rsync) to something else, and echo "rsync done" | mailx user@example.com to another command.

Split() { SENT=${*} ; sentarry=( ${SENT} ) ; while [[ ${#sentarry[@]} -gt 0 ]] ; do printf "%s\n" "${sentarry[0]}" ; sentarry=( ${sentarry[@]:1} ) ; done ; }
(for i in `find . -maxdepth 2 -name .svn | sed 's/.svn$//'`; do echo $i; svn info $i; done ) | egrep '^.\/|^URL'
2010-05-09 11:54:37
User: jespere
Functions: echo egrep info sed
0

If you have lots of subversion working copies in one directory and want to see in which repositories they are stored, this will do the trick. Can be convenient if you need to move to a new subversion server.

echo Good $(i=`date | cut -d: -f1 | cut -d' ' -f4-4` ; if [ $i -lt 12 ] ; then echo morning ; else if [ $i -lt 15 ] ; then echo afternoon ; else echo evening ; fi ; fi)
2010-09-21 11:16:36
User: foolcraft
Functions: cut echo
0

Get the hour and greet the user!

Make sure you add this to your bashrc, for a pleasant hacking experience!

date +%Y%m%d%T -s "`ssh user@server 'date "+%Y%m%d %T"'`"
2011-01-11 10:33:32
Functions: date
Tags: ssh ,NTP ,Date
0

If you are stuck behind a firewall and want to synchronize time with another server but you do not want to port forward NTP (which uses UDP) then this command is handy. It gets the time from a server and sets the local time. It is not that accurate but I can live with a second or so drift.

ipcs -ma | awk '/^m / { if ($9 == 0) { print $2 }}' | xargs -n 1 ipcrm -m
2011-07-26 15:53:59
User: keymon
Functions: awk ipcrm ipcs xargs
0

It can work for message queue, semaphore set or shared memory just changing the parameter.

rsync -a /path/from/.[^.]* /path/to
2012-03-19 22:08:54
User: magbeat
Functions: rsync
Tags: rsync
0

Useful when upgrading my Linux distro and trying to copy only "settings" from the old home folder to the new one.

hdparm --verbose /dev/sda1
2012-05-04 05:58:58
User: yrkharche1
Functions: hdparm
0

Useful to get info about the hard disk detail.

for i in /var/spool/cron/*; do echo ${i##*/}; sed 's/^/\t/' $i; echo; done
watch -n 1 pkill -USR1 "^dd$"
2012-08-31 05:15:45
Functions: watch
Tags: dd progress speed
0

Sends the "USR1" signal every 1 second (-n 1) to a process called exactly "dd".

The signal in some systems can be INFO or SIGINFO ...

look at the signals list in: man kill

byobu new-session -d -s name; byobu new-window -t name:1 -n 'window-1-title' 'command-1'; byobu new-window -t name:2 -n 'window-2-title' 'command-2'; byobu select-window -t name:1; byobu -2 attach-session -t name
2013-01-09 14:09:26
User: alikhalil
0

Create a byobu (tmux) session and attach several windows to it.

curl --silent http://www.census.gov/population/international/ | grep wclocknum | sed -r 's@^.*>([0-9,]+)<.*$@\1@'
2013-07-15 22:35:05
User: malathion
Functions: grep sed
Tags: curl
0

Deprecated due to a change in the site design: see alternatives.

wget -q -O- http://example-podcast-feed.com/rss | grep -o "<enclosure[ -~][^>]*" | grep -o "http://[ -~][^\"]*" | xargs wget -c
2013-09-24 12:38:08
User: talha131
Functions: grep wget xargs
0

This script can be used to download enclosed files from a RSS feed. For example, it can be used to download mp3 files from a podcasts RSS feed.

Add-MailboxPermission -Identity "username_of_mailbox_owner" -User username_control_to -AccessRights Fullaccess -InheritanceType all
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
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.