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

Commands by pykler from sorted by
Terminal - Commands by pykler - 19 results
curl ifconfig.me/all
2012-05-16 18:22:28
User: pykler
9

Gets all kind of info, ifconfig.me rocks ...

for just the ip addess you can use ifconfig.me or ifconfig.me/ip

awk -F'\t' '{print $0 >>$5.tsv}'
2012-05-16 18:18:16
User: pykler
Functions: awk
Tags: awk split tsv
0

Will split the std input lines into files grouped by the 5th column content.

tail -F /var/log/nginx/access.log | python -c 'exec("import sys,time\nl=0\ne=int(time.time())\nfor line in sys.stdin:\n\tt = int(time.time())\n\tl += 1\n\tif t > e:\n\t\te = t\n\t\tprint l\n\t\tl = 0")'
2012-05-15 21:56:46
User: pykler
Functions: python tail
0

Realtime lines per second in a log file using python ... identical to perl version, except python is much better :)

aptitude search ~ahold
fuser -v 80/tcp
rsync -rv --exclude .svn src/dir/ dest/dir/
lsof -Pn | grep LISTEN
rsync --daemon --port 9999 --no-detach -v --config .rsyncd.conf
2011-09-22 20:48:31
User: pykler
Functions: rsync
-3

An example config file is placed in the sample output along with the command line call to use it.

The rsync daemon here is setup on the destination, thus requiring the read only = false flag. Also it uses uid and gid of root, change as required.

bash -i 2>&1 | tee /dev/stderr | nc -l 5000
2010-10-20 18:32:12
User: pykler
Functions: bash tee
Tags: nc
4

Doesn't work so well if you connect from windows. Linux only sends LF where windows wants CRLF. The alternative command works better with windows, however it uses script and a named pipe.

sqlite3 -line database.db
2010-10-09 16:10:19
User: pykler
Tags: CSV html sql sqlite
-2

Similar output to using MySQL with the \G at the end of a Query. Displays one column per line. Other modes include:

-column

Query results will be displayed in a table like form, using whitespace characters to separate the columns and align the output.

-html Query results will be output as simple HTML tables.

-line Query results will be displayed with one value per line, rows separated by a blank line. Designed to be easily parsed by scripts or other programs

-list Query results will be displayed with the separator (|, by default) character between each field value. The default.

From inside the command line this can be also changed using the mode command:

.mode MODE ?TABLE? Set output mode where MODE is one of:

csv Comma-separated values

column Left-aligned columns. (See .width)

html HTML code

insert SQL insert statements for TABLE

line One value per line

list Values delimited by .separator string

tabs Tab-separated values

tcl TCL list elements

rlwrap sqlite3 database.db
2010-10-09 15:56:08
User: pykler
Tags: readline
7

Enable readline even if the command line application is not using it.

ffmpeg -t 300 -r '0.5' -i head-%03d.png -i ../TvQuran.com__144.mp3 -acodec copy muxed.flv
2010-10-07 16:29:08
User: pykler
3

Creates a 5 minute flv file, with the given sequence of images and audio with 0.5 fps.

The images were created using the following command:

for x in `seq 0 300`; do cp ../head.PNG head-`printf '%03d' $x`.png; done

You can also inject metadata to seek easier using yamdi as follows:

yamdi -i muxed.flv -o video.flv

curl icanhazip.com
2010-06-14 18:47:11
User: pykler
-2

With a lolcat favicon if you access it from your browser

python -c 'import sys,csv; c = csv.reader(sys.stdin); [sys.stdout.write("^M".join(map(repr,r))+"\n") for r in c];' <tmp/test.csv | column -s '^M' -t
2010-02-01 14:57:25
User: pykler
Functions: c++ column python
Tags: CSV
1

Will handle pretty much all types of CSV Files.

The ^M character is typed on the command line using Ctrl-V Ctrl-M and can be replaced with any character that does not appear inside the CSV.

Tips for simpler CSV files:

* If newlines are not placed within a csv cell then you can replace `map(repr, r)` with r

tail -f /var/log/apache2/access.log | awk -W interactive '!x[$1]++ {print $1}'
2010-01-12 15:23:03
User: pykler
Functions: awk tail
1

Prints the unique IP Addresses as they arrive from an Apache `access.log` file.

The '-W interactive' tells awk to start writing to stdout immediately and not buffer the output.

This command builds on the uniq lines without sorting command (http://www.commandlinefu.com/commands/view/4389/remove-duplicate-entries-in-a-file-without-sorting.)

dpkg --get-selections | cut -f1 | while read pkg; do dpkg -L $pkg | xargs -I'{}' bash -c 'if [ ! -d "{}" ]; then echo "{}"; fi' | tr '\n' '\000' | du -c --files0-from - | tail -1 | sed "s/total/$pkg/"; done
2009-10-12 14:57:54
User: pykler
Functions: bash cut du echo read sed tail tr xargs
Tags: Debian wajig
4

Calculates the size on disk for each package installed on the filesystem (or removed but not purged). This is missing the

| sort -rn

which would put the biggest packges on top. That was purposely left out as the command is slightly on the slow side

Also you may need to run this as root as some files can only be checked by du if you can read them ;)

check the sample output below, the command was too long :(
2009-09-29 19:30:10
User: pykler
Functions: command
Tags: color
6

Same as the cool matrix style command ( http://www.commandlinefu.com/commands/view/3652/matrix-style ), except replacing the printed character with randomness. The command mentioned is much faster and thus more true to the matrix. However, mine can be optimized, but I wasted ... i mean spent enough time on it already

column -s, -t <tmp.csv
2009-09-24 20:57:32
User: pykler
Functions: column
17

Splits the input based on commas and prints it in a nice column format. This would not work for CSV rows that have "," between quotes or with newline characters. Use only simple simple csv files.

echo foo | netcat 192.168.1.2 25
2009-09-13 01:33:02
User: pykler
Functions: echo
2

Using netcat, usuallly installed on debian/ubuntu.

Also to test against a sample server the following two commands may help

echo got milk? | netcat -l -p 25

python -c "import SocketServer; SocketServer.BaseRequestHandler.handle = lambda self: self.request.send('got milk?\n'); SocketServer.TCPServer(('0.0.0.0', 25), SocketServer.BaseRequestHandler).serve_forever()"