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,619 results
nl filename | more
2009-05-04 07:35:16
User: haivu
Functions: nl
-2

The nl command lists the contents of a file where is each line is prefixed by a line number. For more information about this command, check out its man page. I tested under Mac OS X and Xubuntu 9.04

setxkbmap us
2010-01-23 04:08:46
User: keturn
-2

Restores the keyboard so your partner who expects the keys to correspond to what they're labelled can type (in qwerty).

printf "%.50d" 0 | tr 0 -
ls -l | sed -e 's/--x/1/g' -e 's/-w-/2/g' -e 's/-wx/3/g' -e 's/r--/4/g' -e 's/r-x/5/g' -e 's/rw-/6/g' -e 's/rwx/7/g' -e 's/---/0/g'
kill -HUP ` ps -aef | grep -i firefox | sort -k 2 -r | sed 1d | awk ' { print $2 } ' `
sudo iptables-restore < /etc/iptables.test.rules
2009-08-19 14:38:08
User: kamiller
Functions: iptables-restore sudo
Tags: iptables
-2

If you don't save the rule set it won't be applied during a reboot

echo "test" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
2011-04-05 09:52:37
User: lightuono
Functions: echo sed
-2

Convert text from lowercase to uppercase

for f in *; do clear; cat $f; sleep .3; done
2011-11-25 17:10:47
User: toddkaufmann
Functions: cat sleep
-2

The better alternative to #9756.

I don't think I'd ever use the original command, but this one was so bad I had to post this. Sorry.

1. $(ls) is dumb, and will give errors if you have an alias like "ls -Fs"

2. clear is better and more portable than reset state.

3. if you're interested in differences, then use diff, not cat.

sudo mount -t cifs -o credentials=/path/to/credenials //hostname/sharename /mount/point
2009-11-23 23:55:20
User: magma_camel
Functions: mount sudo
-2

mounts a samba share on a remote machine using a credentials file that can be in a file tht is not accessable by other users the file will look like:

username="username"

password="password"

best option i belive

tar zxvf fileNameHere.tgz
2014-01-28 10:33:51
User: Jonas_E
Functions: tar
Tags: tar unpack
-2

tar command options:

-z : Uncompress the resulting archive with gzip command.

-x : Extract to disk from the archive.

-v : Produce verbose output i.e. show progress and file names while extracting files.

-f backup.tgz : Read the archive from the specified file called backup.tgz.

-C /tmp/data : Unpack/extract files in /tmp/data instead of the default current directory.

alias somafm='read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls'
2009-05-05 12:13:46
User: denzuko
Functions: alias
-2

This is the alias command that I discussed in my prior release which you can add to your ~/.bashrc.

This command asks for the station name and then connects to somafm, Great for those who have linux home entertainment boxes and ssh enabled on them, just for the CLI fiends out there ( I know I'm one of them ;)

You can find future releases of this and many more scripts at the teachings of master denzuko - denzuko.co.cc.

find ./ -name $1 -exec grep -H -n $2 '{}' ';'
xfwm4 --replace
find -maxdepth 1 -type f -newermt "00:00" -printf "%f\n" | sort
2013-03-23 12:50:01
User: TetsuyO
Functions: find
Tags: sort find files
-2

Finds files modified today since 00:00, removes ugly dotslash characters in front of every filename, and sorts them.

*EDITED* with the advices coming from flatcap (thanks!)

grep lm /proc/cpuinfo
2009-02-19 22:48:47
User: bobbydale
Functions: grep
-2

If the 'lm' flag is present, then the CPU is 64-bit.

If no output, then CPU is 32-bit.

netstat | grep EST | awk '{print $5}' | sort
2009-11-24 13:38:28
User: unixoid
Functions: awk grep netstat
-2

Sometimes I need a quick visual way to determine if there is a particular server who is opening too many connections to the database machine.

system max <some value>
2010-03-26 02:39:00
User: rootgeek
Tags: foundry
-2

The sample output, is a display of the values you can change, using this command. After a change of of these settings you will need to reload the box, by typing...wait...wait for IT: 'reload'. This comes in handy when working with the RX hardware, for example, which has a base limitation of 32 (RSTP (802-1w) instances. For all of you paying attention that means if you run RSTP on a RX you can only have 32 VLANs. Sure, you can have common groups of VLANs, like back in the day style MSTP, PVST, PVST+ (and all that old STP (802.1d) mess), before "per vlan spanning-tree", RSTP (802-1w), was made. But who wants to do all that?

rm *[!teste0,teste1,teste2]
2011-01-25 22:00:29
Functions: rm
Tags: grep rm
-2

Remove all arquives except the list.

Can't have space between the commas.

ssh -g -L 8080:localhost:80 root@$HOST
2009-10-24 20:56:00
User: kayowas
Functions: ssh
-2

Forward connections to $HOSTNAME:8080 out to $HOST:80

for file in ./*; do cat "$file"; sleep 0.3
2011-11-28 20:10:57
User: DopeGhoti
Functions: cat file sleep
-2

Original submitted version would break if any filenames had whitespaces in them. The command is a Bad Idea anyhow, because you will end up `cat`ing a binary or something else specacularly bad.

cd /path/to/pmwiki/wiki.d;/bin/ls -1 | perl -ne 'my ($group,$name)=split(/\./);$counts{$group}++;' -e 'END { foreach $group (sort keys %counts) {printf("%d\t%s\n",$counts{$group},$group);} }'|sort -rn
2011-09-14 19:33:39
User: tamouse
Functions: cd perl sort
Tags: sort perl pmwiki
-2

PmWiki stores wiki pages as Group.Name. Simply split the directory listing and count frequency of group occurances.

php -i|grep -i max
2009-02-20 03:29:11
User: rjamestaylor
-2

Show the maximum settings in effect for PHP at the command line.

rm -rf `find . -name .svn`
2010-02-23 08:35:06
User: jfcalvo
Functions: rm
-2

Recursively remove .svn directories from the current location.

wget http://www.whatismyip.org --quiet -O - | cat
ntfsresize --size X[k,M.G] /dev/hda1
2011-07-02 17:47:05
User: 0disse0
Tags: ntfs
-2

With this command you can resize an NTFS partition by specifying the new size (X) in Kbytes, Mbytes or Gbytes. If you plan to do this it is advisable to precede --no-action parameter to size

see more:

http://ubuntuforums.org/showthread.php?t=1244058

and

http://en.wikipedia.org/wiki/Ntfsresize