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,620 results
sed '1,55d'
2009-02-16 20:36:25
User: grep
Functions: sed
-4

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
-4

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
4

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
6

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
-2

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
6

-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
8

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
1

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
9

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
1

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
-1

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
8

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
8

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
4

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
5

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

_cd ~/nsfw; mplayer midget_donkey.mpeg
2009-02-16 17:19:40
User: Kirbe
5

Note the extra space before the command (I had to put it as an underscore since the website eats up preceding spaces). That's all it takes. Now if you check your history with "$ history", it wont show up.

find . -name "*.jar" | xargs -tn1 jar tvf | grep --color "SearchTerm"
2009-02-16 17:18:36
Functions: find grep xargs
2

Great for finding which jar some pesky class is hiding in!

find . -name "*.pyc" -exec rm {} \;
2009-02-16 17:15:58
User: nsmgr8
Functions: find rm
-2

For a python project, sometimes I need to clean all the compiled python files. I have an alias 'rmpyc' to this command. This really saves me a lot of typing and hunting throughout the folders to delete those files.

for I in `find . -name "*.php"`; do sed -i "s/old name/new name/g" $I; done
2009-02-16 17:09:09
User: ruedu
Functions: sed
-1

So you have a web site and you've plastered your significant other's name all over it. But you broke up with them and have some new love in your life. How do you find all those instances of their name and replace them?

pushd /tmp
2009-02-16 16:52:59
User: ruedu
83

If are a Bash user and you are in a directory and need to go else where for a while but don't want to lose where you were, use pushd instead of cd.

cd /home/complicated/path/.I/dont/want/to/forget

pushd /tmp

cd thing/in/tmp

popd (returns you to /home/complicated/path/.I/dont/want/to/forget)