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,134 results
wget -q -O - 'http://wap.weather.gov.hk/' | sed -r 's/<[^>]+>//g;/^UV/q' | tail -n4
2009-09-25 02:36:46
User: dakunesu
Functions: sed tail wget
-1

"get Hong Kong weather infomation from HK Observatory

From Hong Kong Observatory wap site ;)"

other one showed alot of blank lines for me

find -maxdepth 1 -type f -name "*.7z" -exec 7zr e '{}' ';'
2010-01-23 19:50:10
User: minnmass
Functions: find
-1

Use find's built-in ability to call programs.

Alternatively,

find -maxdepth 1 -type f -name "*.7z" -print0 | xargx -0 -n 1 7zr e

would work, too.

setserial -g /dev/ttyS[0-9]* | grep -v "unknown"
test $((RANDOM%2)) -eq 0
sudo add-apt-repository ppa:PPA_TO_ADD
2014-04-24 20:02:39
User: KlfJoat
Functions: sudo
-1

There is no longer a need to add PGP keys for Ubuntu Launchpad PPA's.

The add-apt-repository command creates a new file for the PPA in /etc/sources.list.d/ then adds the PPA's keys to the apt keyring automatically. No muss, no fuss.

perl -pi -e "s/\r/\n/g" <file>
2010-07-29 16:07:36
User: din7
Functions: perl
-1

Replace DOS character ^M with newline using perl inline replace.

eog `curl 'http://xkcd.com/' | awk -F "ng): |</h" '/embedding/{print $2}'`
curl ifconfig.me
wget --spider -o wget.log -e robots=off --wait 1 -r -p http://www.example.com
2011-04-05 13:42:14
User: lele
Functions: wget
-1

This will visit recursively all linked urls starting from the specified URL. It won't save anything locally and it will produce a detailed log.

Useful to find broken links in your site. It ignores robots.txt, so just use it on a site you own!

find . -name '*.java' -o -name '*.xml' | grep -v '\.svn' | xargs wc -l
2011-06-30 12:45:40
User: ewilson
Functions: find grep wc xargs
Tags: find grep wc
-1

There's nothing particularly novel about this combination of find, grep, and wc, I'm just putting it here in case I want it again.

sudo port installed | grep -v 'active\|The' | xargs sudo port uninstall
squidclient mgr:info | grep "file desc"
2010-07-29 17:35:20
User: KoRoVaMiLK
Functions: grep
-1

Shows useful informations about file descriptors in Squid web proxy

makeself <archive_dir> <file_name> <label>
2012-01-10 18:08:50
User: totti
-1

Used by virtualbox and others to create '.run' file.

echo -e 'alias exit='\''pwd > ~/.lastdir;exit'\''\n[ -n "$(cat .lastdir 2>/dev/null)" ] && cd "$(cat .lastdir)"' >> ~/.bash_aliases
2014-01-28 18:02:04
User: ichbins
Functions: cd echo
Tags: exit pwd
-1

this command will add the following two lines into the ~/.bash_aliases:

alias exit='pwd > ~/.lastdir;exit'

[ -n "$(cat .lastdir 2>/dev/null)" ] && cd "$(cat .lastdir)"

or redirect it to the ~/.bashrc if you like

Donno, I find it usefull. You may also define an alias for 'cd ~' like - alias cdh='cd ~'

function sshdel { perl -i -n -e "print unless (\$. == $1)" ~/.ssh/known_hosts; }
2009-02-03 16:20:50
User: xsawyerx
Functions: perl
-1

sometimes you got conflicts using SSH (host changing ip, ip now belongs to a different machine) and you need to edit the file and remove the offending line from known_hosts. this does it much easier.

Use history -S in your .logout file
2009-02-07 10:53:14
User: vijucat
-1

That's the key part.

I got this from http://www.macosxhints.com/article.php?story=20070715091413640. See that article for other other, more basic, tcsh-specific history-related settings.

echo "sed -e"|perl -pe 's/sed -e/perl -pe/'
2009-02-16 18:39:06
User: drossman
Functions: echo
-1

Replace sed regular expressions with perl patterns on the command line.

The sed equivalent is: echo "sed -e"|sed -e 's/sed -e/perl -pe/'

cat file | tr -d "\n"
2010-12-02 09:22:02
User: uzsolt
Functions: cat file tr
-1

This command deletes the "newline" chars, so its output maybe unusable :)

$grep -hIr -m 1 em:name ~/.mozilla/firefox/*.default/extensions|sed 's#\s*##'|tr '<>=' '"""'|cut -f3 -d'"'|sort -u
2010-05-24 08:03:53
User: raj77_in
Functions: sed sort tr
-1

with grep for em:name rather than name, you will get much better result.

wc -L files
zcat log.tar.gz | grep -a -i "string"
2011-09-14 17:20:43
User: dycropts
Functions: grep zcat
-1

Useful in system where log files are compressed for archival purposes

find . -type f -print0 | xargs -0r awk '/^\xEF\xBB\xBF/ {print FILENAME} {nextfile}'
trash <file>
2012-11-22 18:05:11
User: bkmeneguello
Tags: bash trash rm
-1

# put into .bashrc

function trash() {

if [ -z "$*" ] ; then

echo "Usage: trash filename"

else

local TRASH="${HOME}/.local/share/Trash"

if [ ! -d "$TRASH/files" ]; then mkdir -p "$TRASH/files"; fi

if [ ! -d "$TRASH/info" ]; then mkdir -p "$TRASH/info"; fi

local IFS_BKP=$IFS

IFS='

'

for FILE in $@ ; do

local BASE=$( basename "$FILE" )

local TRASH_NAME="$BASE"

local COUNTER=1

while [ -e "$TRASH/files/$TRASH_NAME" ]; do

COUNTER=`expr $COUNTER + 1`

TRASH_NAME="$BASE.$COUNTER"

done

local FULL_PATH=$( readlink -f "$FILE" )

local DATE=$( date +%Y-%m-%dT%H:%M:%S )

mv "$FULL_PATH" "$TRASH/files/$TRASH_NAME"

if [ $? -eq 0 ]; then

echo "[Trash Info]

Path=$FULL_PATH

DeletionDate=$DATE" > "$TRASH/info/$TRASH_NAME.trashinfo"

fi

done

IFS=$IFS_BKP

fi

}

grep -w /media/KINGSTON /proc/mounts | cut -d " " -f
curl ifconfig.me