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,860 results
ip -4 addr show eth0 | awk ' /inet/ {print $2}'
2011-10-05 11:38:55
User: kadu
Functions: awk
-1

Shows the first IP on named interface including the network size

find /path/to/dir -type f -exec cachedel '{}' \;
2013-12-12 18:22:54
User: michelsberg
Functions: find
-1

This is just another example of what the nocache package is useful for, which I described in http://www.commandlinefu.com/commands/view/12357/ and that provides the commands

nocache <command to run with page cache disabled>

cachedel <single file to remove from page cache>

cachstats <single file> # to get the current cache state

Often, we do not want to disable caching, because several file reads are involved in a command and operations would be slowed down a lot, due to massive disk seeks. But after our operations, the file sits in the cache needlessly, if we know we're very likely never touching it again.

cachedel helps to reduce cache pollution, i.e. frequently required files relevant for desktop interaction (libs/configs/etc.) would be removed from RAM.

So we can run cachedel after each data intensive job. Today I run commands like these:

<compile job> && find . -type f -exec cachedel '{}' \; &> /dev/null # no need to keep all source code and tmp files in memory

sudo apt-get dist-upgrade && find /var/cache/apt/archives/ -type f -exec cachedel '{}' \; # Debian/*buntu system upgrade

dropbox status | grep -Fi idle && find ~/Dropbox -type f -exec cachedel '{}' \; &> /dev/null # if Dropbox is idle, remove sync'ed files from cache

https://github.com/Feh/nocache

http://packages.debian.org/search?keywords=nocache

http://packages.ubuntu.com/search?keywords=nocache

http://askubuntu.com/questions/122857

find . -maxdepth 1 -iname '*jpg' -exec convert -quality 60 {} lowQ/{} \;
2009-02-15 19:34:38
User: abhinay
Functions: find
-1

* lowQ/ is the output directory

* pass quality level from 1 to 100

echo "import random; print(random.choice(['heads', 'tails']))" | python
convert -bordercolor Transparent -border 1x1 in.png out.png
2009-02-15 19:42:17
User: jimmac
-1

Requires either imagemagick or graphicsmagic utility.

/usr/local/bin/OFPW -pass thepassword
while read str; do echo "$((++i)) - $str"; done < infile
2009-12-09 15:11:25
User: putnamhill
Functions: echo read
Tags: bash
-1

Hi glaudiston, you can save a few chars by leaving out cat and pipe and still enjoy the added flexibility.

tw translate.google.com.de-en `xsel`
2010-06-11 22:28:28
User: dbbolton
-1

Translate the X selection from German to English. The tw program is available from Savannah: http://mirror.its.uidaho.edu/pub/savannah/twandgtw/

I'm posting this because the base Debian system also does not include curl.

/usr/local/bin/OFPW -mode 1
perl -wlne 'print $1 if /(([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5]))/' iplist
2009-09-17 16:14:52
User: salparadise
Functions: perl
-1

if you want to only print the IP address from a file.

In this case the file will be called "iplist" with a line like "ip address 1.1.1.1"

it will only print the "1.1.1.1" portion

<ctrl+s>|<alt+s>
2011-05-02 14:44:41
User: Nbeker
-1

Learning cardinal and ordinal numbers in Spanish, with the best sounds files, try to get the best way to improve youLearning cardinal and ordinal numbers in Spanish, with the best sounds files, try to get the best way to improve your vocabulary.

xpath () { xmllint --format --shell "$2" <<< "cat $1" | sed '/^\/ >/d' }
2011-12-20 08:34:11
User: sharfah
Functions: sed
Tags: xml xmllint xpath
-1

This function uses xmllint to evaluate xpaths.

Usage: xpath /path/to/element XMLfile

copy /b part.1 + part.2 + part.n file.extension
echo 127.0.0.1 | egrep -e '^(([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-4])\.){3}([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-4])$'
2009-09-17 17:40:48
User: arcege
Functions: echo egrep
-1

Handles everything except octets with 255. Ran through ip generator with variable octet lengths.

sudo usermod -p $(mkpasswd '') user_id
2010-05-06 20:39:58
User: ckclark
Functions: sudo usermod
-1

It is safe when there is

"PermitEmptyPasswords no"

in /etc/ssh/sshd_config.

This command is useful when there is no need to have a password.

awk '{print $0/60;}' /proc/uptime
2011-08-31 10:41:21
User: ioggstream
Functions: awk
-1

Get info directly from /proc/uptime

ssh -XfC -c blowfish user@host Xephyr dpms -fullscreen -query localhost :5
2012-11-01 18:59:57
User: hute37
Functions: ssh
Tags: ssh X Xephyr xdmcp
-1

ssh compresion -C option ...

on slow connection VNC performs better but in local LAN native secure X protocol is an option

curl curlmyip.com
%s/?/\&iuml;/ge | %s/?/\&#0233;/ge | %s/?/"/ge | %s/?/"/ge | %s/?/'/ge | %s/?/'/ge | %s/?/\&ecirc;/ge | %s/?/\&#0133;/ge | %s/?/\&#232;/ge | %s/?/\&#243;/ge | %s/?/\&ouml;/ge | %s/?/\&#0233;/ge | %s/?/\&ndash;/ge | %s/?/\&mdash;/ge
2010-07-15 07:40:45
User: miccaman
Tags: vim
-1

a brief list of very common special characters in Dutch. Usefull for formatting Word source to html.

di
find ./ -iname "*.mp3" -type f -printf "mv '%p' '%p'\n" | sed -e "s/mp3'$/mp3'/I" | sh
2009-03-27 13:42:40
User: jnash
Functions: find sed
-1

Extensible to other ugly extensions like *.JPG, *.Jpg etc..

Leave out the last pipe to sh to perform a dry run.

for i in {0..1}{0..9}; do echo $i; done
2009-09-18 02:51:12
User: dennisw
Functions: echo
Tags: bash strings
-1

Bash 4 will let you do {00..19} to get leading zeros, but Bash 3 doesn't have that feature. This technique gets you partway there (the sequences need be such that the last digit ranges from zero to nine - you can't use this for something like Bash 4's {03..27}, for example). When this limitation is not a problem, you can avoid some complicated string manipulation for concatenating leading zeros.

You can add more digits like this: {0..1}{0..9}{0..9} (ranges from 0 to 99 with up to two leading zeros). To pad with additional zeros:

for i in 000{0..1}{0..9}; do echo $i; done

or

for i in {0..1}{0..9}; do echo "000$i"; done

This is useful for creating values to sort or for creating filenames with a fixed format. Note that this will also work:

touch {0..1}{0..9}
gst-launch avimux name=mux ! filesink location=out.avi \ alsasrc ! audioconvert ! queue ! mux. istximagesrc name=videosource use-damage=false ! video/x-raw-rgb,framerate=10/1 ! videorate ! ffmpegcolorspace ! video/x-raw-yuv,framerate=10/1 ! mux.
2010-07-15 09:39:51
User: Nicolargo
-1

The command generate an huge output file (depending on screen resolution and time).

pbzip2 -dck <bz2file> | tar xvf -