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,177 results
pgrep command_name
:%v/./,/./-j
printf "%'d\n" 1234567
2009-08-15 14:48:56
User: twfcc
Functions: printf
3

it is not work with Cygwin's bash3.X. Test in Linux.

use printf "%'f" number while it is floating point number

python -c 'import this'
echo "import this" | python
2009-08-15 09:42:36
User: loquitus
Functions: echo
0

Very very cool list of quotations and directives on pythonic programming. I love them and they are sure applicable in C++ too, and for most any programming, really.

vditool COPYDD my.vdi my.dd ; sudo mount -t ntfs -o ro,noatime,noexex,loop,offset=32256 my.dd ./my_dir
while true; do clear; nmap ${hostname} -PN -p ${hostport}; sleep 5; done
2009-08-14 20:19:59
User: flokra
Functions: sleep
0

the command for the impatient sysadmin: simply checks every five secs, if a host or a specific service running on it is up. ideal for hosts that are configured not to respond on pings.

$(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.

mv -vi file{,~}
2009-08-14 19:29:59
User: fsilveira
Functions: mv
1

Very helpful when you've got complex filenames and needs to change just some small parts of it.

Renaming a file called "i-made-a-small-typo-right-here" to "i-made-a-big-typo-right-here":

mv -vi i-made-a-{small,big}-typo-right-here

You could also copy multiple files, edit, remove, process, etc.

SERVER: nc -l p 666 CLIENT: telnet -l -p 666
2009-08-14 17:01:57
User: Cowboy
Functions: telnet
1

This will start a netcat process listening on port 666. If you are able connect to your your server, netcat will receive the data being sent and spit it out to the screen (it may look like random garbage, so you might want to redirect it to a file).

mkdir 0{0..9}{0..9};mv 000 100
2009-08-14 16:33:20
User: sitaram
Functions: mkdir
-4

no external commands, but can only do 0-99, not 1-100, so we adjust it later

host -t a dartsclink.com | sed 's/.*has address //'
ps -C command
2009-08-14 15:30:42
User: recursiverse
Functions: ps
6

preferred way to query ps for a specific process name (not supported with all flavors of ps, but will work on just about any linux afaik)

uuid
2009-08-14 14:02:37
-1

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

http://www.ossp.org/pkg/lib/uuid/

You'll first need to install the uuid package. Available immediately from apt in Ubuntu, Debian, or other myriad Debian variants. You could always compile it from source as well.

IFS=:; find $PATH | grep pattern
2009-08-14 13:38:58
User: camspiers
Functions: find grep
Tags: bash find grep
1

Best to put it in a file somewhere in your path. (I call the file spath)

#!/bin/bash

IFS=:; find $PATH | grep $1

Usage: $ spath php

watch -n 10 'du -sk testfile'
2009-08-14 12:35:21
User: ianux
Functions: watch
2

watch is a command especially designed for doing this job

while true ; do du -sk testfile ; sleep 10 ; done
2009-08-14 11:39:52
User: Solaris
Functions: du sleep true
-2

This command produces the output of "du -sk testfile" in every 10 seconds. You can change the command to be whatever you want.

mkdir $(printf '%03d\n' {1..100})
wget -O - -q icanhazip.com
2009-08-14 10:24:30
User: andrepuel
Functions: wget
5

I dont have curl or links installed, so I use wget with write file as standard out.

host -t mx foo.org
2009-08-14 09:55:19
User: peshay
Functions: host
1

command is shorter, output unnecessary longer

sed -e :a -e 's/<[^>]*>//g;/</N;//ba' index.html
2009-08-14 09:55:00
User: Blackbit
Functions: sed
6

This regular expression removes all HTML-Tags from the file.

egrep "^lease" /var/lib/dhcp/db/dhcpd.leases |awk '{ print $2 }'
2009-08-14 07:31:00
User: peshay
Functions: awk egrep
0

You can use that to create a excludefile for nmap, to find hosts, with no DHCP lease in your DHCP range.

smartypants | php -r "echo mb_decode_numericentity(file_get_contents('php://stdin'),array(0x0000,0xFFFF,0x0000,0xFFFF),'UTF-8');"
2009-08-14 04:02:38
User: infinull
-2

Turns regular quotes into curly quotes, also converts hyphens to dashes using a heuristic and outputs the result as UTF-8, suitable to copy/paste into wordprocessor.

requires: http://daringfireball.net/projects/smartypants/ (which does most of the work)

(I renamed smartypants.pl to smartypants before adding it to my $PATH)

Also requrires PHP with the multibyte module installed (its installed by default with PHP, but the sysadmin on one server I use disabled it... presumadly to increase performance or something).

git show --relative --pretty=format:'' --name-only HASH
2009-08-14 03:36:03
User: lingo
Tags: git files list
2

Lists ONLY the files changed by the given HASH/HEAD/list of hashes, etc. The message, commit ID, author, etc. is not included

rename 's/^/prefix/' *
2009-08-14 03:26:45
User: lingo
Functions: rename
12

Best to try first with -n flag, to preview