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.

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:



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.

Top Tags



All commands from sorted by
Terminal - All commands - 12,075 results
cd /usr/ports; grep -F "`for o in \`pkg_info -qao\` ; \ do echo "|/usr/ports/${o}|" ; done`" `make -V INDEXFILE` | \ grep -i \|[email protected]\| | cut -f 2 -d \|
2009-02-16 21:07:35
User: grep
Functions: cd cut grep

only works for freeBSD where ports are installed in /usr/ports

credit to http://wiki.freebsd.org/PortsTasks

sed '1!G;h;$!d'
sed 's/$//'
sed 's/$/<ctrl+v><ctrl+m>/'
2009-02-16 20:53:05
User: SiegeX
Functions: sed

The ctrl+v,ctrl+m portion represents key presses that you should do. If you do it successfully you should see a ^M character appear.

sed '/./,$!d'
sed '1,55d'
2009-02-16 20:36:25
User: grep
Functions: sed

deletes first 55 lines; change the 55 to whatever number

newhostname=$(hostname | awk -F. '{print $1 "." $2}'); ipaddress=$(nslookup `hostname` | grep -i address | awk -F" " '{print $2}' | awk -F. '{print $3 "." $4}' | grep -v 64.142);PS1="[`id -un`.$newhostname.$ipaddress]"' (${PWD}): '; export PS1
2009-02-16 20:11:53
User: simardd

changes the PS1 to something better than default.

[username.hostname.last-2-digits-of-ip] (current directory)

sed 's/$'"/`echo \\\r`/"
gpg --encrypt --recipient 'Foo Bar' foo.txt
2009-02-16 19:58:13
User: mariusz
Functions: gpg

gpg command to encrypt a file on the command line.

gpg --output foo.txt --decrypt foo.txt.pgp
2009-02-16 19:56:19
User: mariusz
Functions: gpg

gpg command to decrypt a previously encrypted file on the command line.

Can be optionally made into an alias:

alias decrypt='gpg --output foo.txt --decrypt foo.txt.pgp'

find path/to/folder/ -type f -print0 | xargs -0 -n 1 md5sum | awk '{print $1}' | sort | md5sum | awk '{print $1}'
2009-02-16 19:39:37
User: mcover
Functions: awk find md5sum sort xargs

For quick validation of folder's file-contents (structure not taken into account) - I use it mostly to check if two folders' contents are the same.

netstat -putona
2009-02-16 19:14:35
User: starchox
Functions: netstat

-p PID and name of the program

-u on a UDP port.

-t also TCP ports

-o networking timer

-n numeric IP addresses (don't resolve them)

-a all sockets

echo "<?php phpinfo(); ?>" | php > phpinfo.txt
echo "SELECT * FROM table; " | mysql -u root -p${MYSQLROOTPW} databasename | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > outfile.csv
2009-02-16 18:55:18
Functions: echo sed

This command converts a MySQL query directly into a .csv (Comma Seperated Value)-file.

smbcacls //server/sharename file -U username
2009-02-16 18:52:14
User: drossman
Functions: file

You can read, add, delete and modify Windows permissions from Linux using smbcacls from the smb-client package.

df / | awk '{print $1}' | grep dev | xargs tune2fs -l | grep create
2009-02-16 18:45:03
User: Kaio
Functions: awk df grep tune2fs xargs

Very useful set of commands to know when your file system was created.

for i in `df -P |grep string|cut -f2 -d%|cut -c2-100`; do umount -l -f $i;done
2009-02-16 18:42:00
User: Kaio
Functions: umount

Sometimes, you have a lot of NFS in the server and you can't or shouldn't use umount -a. Whis this command, you only umount the fs related to the 'string'

echo "sed -e"|perl -pe 's/sed -e/perl -pe/'
2009-02-16 18:39:06
User: drossman
Functions: echo

Replace sed regular expressions with perl patterns on the command line.

The sed equivalent is: echo "sed -e"|sed -e 's/sed -e/perl -pe/'

dd if=/dev/zero of=/swapfile bs=1M count=64; chmod 600 /swapfile; mkswap /swapfile; swapon /swapfile
2009-02-16 18:36:38
User: starchox
Functions: chmod dd mkswap swapon

In addition to a swap partition, Linux can also use a swap file. Some programs, like g++, can use huge amounts of virtual memory, requiring the temporary creation of extra space.

find . -type f -perm +0111 -print
scp user@hostb:file user@hostc:
2009-02-16 18:33:08
User: drossman
Functions: scp

While at the command line of of hosta, scp a file from remote hostb to remote hostc. This saves the step of logging into hostb and then issuing the scp command to hostc.

function man2pdf(){ man -t ${1:?Specify man as arg} | open -f -a preview; }
2009-02-16 18:29:35
User: piXelz
Functions: as man

Simply pass an argument to the script to convert the manual page to a PDF:

man2pdf drutil
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user
apache2 -t -D DUMP_MODULES
2009-02-16 17:30:20
User: ElAlecs
Tags: apache httpd

This let you know which modules has loaded the Apache server, very useful to know if the mod_rewrite is ready to use.