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,611 results
gopyrit () { if [ $# -lt 1 ]; then echo $0 '< list of ESSIDs >'; return -1; fi; for i in "$@"; do pyrit -e $i create_essid && pyrit batch; done; pyrit eval }
2010-06-19 01:11:00
User: meathive
Functions: echo eval return
0

This command will automate the creation of ESSIDs and batch processing in pyrit. Give it a list of WPA/WPA2 access points you're targeting and it'll import those ESSIDs and pre-compute the potential password hashes for you, assuming you've got a list of passwords already imported using:

pyrit -i dictionary import_passwords

Once the command finishes, point pyrit to your packet capture containing a handshake with the attack_db module. Game over.

perl -e "tr/[A-Z]/[a-z]/;" -pi.save $(find . -type f)
perl -e 'printf join ".", map int rand 256, 1 .. 4;'
geoip() { lynx -dump "http://api.hostip.info/get_html.php?ip=$1&position=true"; }
0

Defines a function to geolocate a given IP address; if none supplied, will default to your external IP address.

perl -MAcme::POE::Tree -e 'Acme::POE::Tree->new()->run()'
IMG="image.img";PART=1;mount -o loop,ro,offset=$(parted $IMG -s unit b print|awk '$1=='$PART' {sub(/B/,"",$2);print $2}') $IMG /mnt/whatever
2011-12-31 14:58:18
User: AndroTux
Functions: awk mount
0

Mounts a disk-image of a hdd with partitions

import unicodedata; map(unicodedata.name, '\u2022'.decode('ascii'))
paste -sd, <<< $'line1\nline2'
2012-11-13 01:26:05
User: kodango
Functions: paste
Tags: paste
0

A more simple way to join lines with paste command than sed.

exiv2 -M"set Exif.Photo.DateTimeOriginal `date "+%Y:%m:%d %H:%M:%S"`" filename.jpg
equery s | sed 's/(\|)/ /g' | sort -n -k 9 | gawk '{print $1" "$9/1048576"m"}'
2009-07-30 01:12:10
User: Alanceil
Functions: gawk sed sort
0

On a Gentoo system, this command will tell you which packets you have installed and sort them by how much space they consume. Good for finding out space-hogs when tidying up disk space.

`ls`
2009-08-17 03:56:05
User: matthewbauer
Tags: wildcard
0

This is exactly the same as a wildcard - good for times when wildcards are disabled and when you want have a wildcard of a directory that is not your current ({`ls /path/to/dir`}). Does not work on older versions of Bash though.

perl -le 'use Config; foreach $i (keys %Config) {print "$i : @Config{$i}"}'
2009-09-22 22:14:21
User: chuckr
Functions: perl
Tags: perl
0

This dumps all of your installed perl's config information.

for item in *;do echo -n "$item - ";find "$item" -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1 | xargs -d'\n' /usr/share/doc/mplayer/examples/midentify | grep ID_LENGTH | awk -F= '{sum+=$2} END {print(sum/60)}'; done | grep -v ' - 0$'
2009-11-19 06:28:15
User: jnash
Functions: awk cut echo file grep xargs
0

I know this has been beaten to death but finding video files using mime types and printing the "hours of video" for each directory is (IMHO) easier to parse than just a single total. Output is in minutes.

Among the other niceties is that it omits printing of non-video files/folders

PS: Barely managed to fit it within the 255 character limit :D

instapaper-add(){ curl -s -d username="$1" -d password="$2" -d url="$3" https://www.instapaper.com/api/add; }
2010-03-21 23:01:38
User: matthewbauer
0

Adds URL to Instapaper.

Usage:

instapaper-add user@example.com 12345 http://www.commandlinefu.com/

\cp something toSomeWhereElse
2010-09-25 03:07:04
User: xakon
0

If the problem is an aliased synonym for a command, you can still execute the original command by pre-pending it with a reverse-slash '\'. This works at least in Bash, but I guess the aliasing system refers definitely to Bash (and not only).

kill -9 `ps xawo state=,pid=|sed -n 's/Z //p'`
2010-10-27 07:38:07
User: AskApache
Functions: kill sed
0

just a leaner, smaller version. Love the original idea!

gawk 'BEGIN {RS="\n\n"; if (ARGV[1]=="-i")IGNORECASE=1;ARGC=1}{if (IGNORECASE)Text[tolower($0)]=$0;else Text[$0]=$0 };END {N=asort(Text);for(i=1;i<=N;i++)printf "%s\n\n",Text[i]}' -i<Test.txt
2011-05-11 01:03:30
User: IF_Rock
Functions: gawk
0

Sorts blank line delimited paragraphs. '-i' -- case insensitivity option -- removes redundant paragraphs in a case insensitive way, and then sorts in a case insensitive way.

If you search CommandLineFu with multiple anded terms searches, redundancy can ensue. This sorts the retrieved text (among other kinds of data), and removes the redundancy.

nmap -sP 192.168.1.0/24 | awk "/^Host/"'{ print $3 }' |nawk -F'[()]' '{print $2}'
2011-12-31 15:50:22
User: cantormath
Functions: awk
0

Often you want to nmap a list of IPs using the -iL flag. This is an easy way to generate a list of IPs that are online in a specific subnet or IP range (192.168.1.100-110).

sed -i -e '1i \# -*- coding: utf-8 -*-' yourfile.py
2012-05-15 14:54:06
User: igniteflow
Functions: sed
0

Useful when specifying char encoding for Python and/or your editor

ip a s eth0 | awk '/inet / {print $2} | sed -e 's/\/..//g'
mplayer $(find . -iname '*.avi' | shuf -n1)
lp -dhp -P1-1 -o media=a4 *
2013-07-26 00:09:56
User: alphabraga
Functions: lp
0

Very usefull script to use when uoy must print all files from a directory.

for file in "$@"; do name=$(basename "$file" .webm) echo ffmpeg -i $file -vn -c:a copy $name.ogg ffmpeg -i "$file" -vn -c:a copy "$name.ogg" done
2013-10-05 14:49:07
User: hoodie
Functions: basename echo file
0

Strips the audio track from a webm video. Use this in combination with clive or youtube-dl.

rpm -ivh 'http://www.website.com/path/to/desired_software_package.rpm'
ioreg -l -p IODeviceTree | grep -o EFI[0-9]. && system_profiler SPSoftwareDataType |grep 64