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,493 results
date --iso
2009-02-25 23:50:40
User: raphink
Functions: date
-1

Useful to archive files once a day:

cp file file.$(date --iso)
^Z then bg
^A ?
2009-02-25 23:42:33
User: raphink
Tags: screen
19

Displays a list of all the basic keyboard shortcuts in screen.

:split <file>
2009-02-25 23:41:22
User: raphink
4

You can then switch from a file to another with ^W^W

dmidecode | grep -i prod
2009-02-25 23:05:17
User: rockon
Functions: grep
6

This command gives a model information of a computer. Also useful in determining the host is a VM machine or actual physical machine.

IPADDR=`ifconfig eth0 | grep -i inet | awk -F: '{print $2}'| awk '{print $1}'`
2009-02-25 22:58:19
User: rockon
Functions: awk grep
-1

Useful in scripts while you just need an IP address in a variable.

rm -rf `ls | head -5000`
2009-02-25 22:52:23
User: rockon
Functions: head rm
-3

Deletes thousands of files at one go, I'm not able to recall the exact # of files that rm can delete at one go(apprx. around 7000.)

blockdev --rereadpt /dev/sda
count=`wc -l file | cut -d ' ' -f1`
bash -x ./post_to_commandlinefu.sh
ctrl + \
2009-02-25 18:52:57
User: nottings
7

useful for loops like for i in $(cat list_of_servers); do ssh -q $i hostname; done

if there is an unreachable server, you can just press ctrl + \ to skip that server and continue on with the loop

ls /sys/bus/scsi/devices
2009-02-25 18:49:27
Functions: ls
3

This will show all physically connected SATA (and SCSI) drives on your system. This is particularly useful when troubleshooting hard disks.... or when a mount point seems to be missing.

hdiutil makehybrid -o CDname.iso /Way/to/folder ; hdiutil burn CDname.iso
2009-02-25 17:46:59
User: vranx
Tags: Os X
3

Create an ISO Image from a folder and burn it to CD (Os X)

lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|grep address|egrep 'city|state|country'|awk '{print $3,$4,$5,$6,$7,$8}'|sed 's\ip address flag \\'|sed 's\My\\'
2009-02-25 17:16:56
User: leftyfb
Tags: bash
24

I save this to bin/iptrace and run "iptrace ipaddress" to get the Country, City and State of an ip address using the http://ipadress.com service.

I add the following to my script to get a tinyurl of the map as well:

URL=`lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|grep details|awk '{print $2}'`

lynx -dump http://tinyurl.com/create.php?url=$URL|grep tinyurl|grep "19. http"|awk '{print $2}'

:r !command
2009-02-25 15:49:08
User: sud0er
Tags: vim
13

This will append the output of "command" to whatever file you're currently editing in vim. Who else has good vim tricks? :)

split -b 19m file Nameforpart
2009-02-25 15:24:06
User: vranx
Functions: file split
10

Split File in 19 MB big parts, putting parts together again via

cat Nameforpartaa Nameforpartab Nameforpartac >> File

command !$
tail -1000 /some/file | vim -
2009-02-25 11:43:27
User: root
Functions: tail vim
17

The hyphen tells vim to open from STDOUT - saves having to create temporary files.

svn st | grep ^? | xargs svn add 2> /dev/null
ps -ef | grep [t]clsh
on="off"; off="on"; now=$(amixer get Master | tr -d '[]' | grep "Playback.*%" |head -n1 |awk '{print $7}'); amixer sset Master ${!now}
tr -dc "a-zA-Z0-9-_\$\?" < /dev/urandom | head -c 10 | gpg -e -r medha@nerdish.de > password.gpg
2009-02-25 08:48:26
User: hans
Functions: gpg head tr
2

Adjust the

head -c

part for password length.

I use filenames like "hans@commandlinefu.com.gpg" and a vim which automatically decrypts files with .gpg suffixes.

for x in `find . -name '*.html'` ; do iconv -f ISO-8859-1 -t UTF-8 $x > "$x.utf8"; rm $x; mv "$x.utf8" $x; done
2009-02-25 08:16:01
Functions: iconv mv rm
7

This is my first attempt at converting all HTML files to UTF-8 file encoding, including all subfolders.

Theres probably a much more compact way to do it, but I'm quite proud of it with my windows background ;)

echo COMMAND | xargs -ixxx ps -C xxx -o pid= | xargs -ixxx ls -l /proc/xxx/cwd
function miso () { mkdir ~/ISO_CD && sudo mount -o loop "$@" ~/ISO_CD && cd ~/ISO_CD && ls; } function uiso () { cd ~ && sudo umount ~/ISO_CD && rm -r ~/ISO_CD; }
2009-02-25 03:41:35
User: vududevil
Functions: cd mkdir mount rm sudo umount
4

Add the functions to the .bashrc to make it work

Example: First go to the iso file directory and type:

----------------------------------------------------------------------------------------------------

user@box:~$ miso file.iso

----------------------------------------------------------------------------------------------------

It will put you into a temporary mounting point directory (ISO_CD) and will show the files

You can umount the iso file whatever the directory you are

----------------------------------------------------------------------------------------------------

user@box:~/ISO_CD$ uiso

----------------------------------------------------------------------------------------------------

It wil umount the iso file and remove the temporary directory in your home