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,605 results
tag() { local t="$HOME/tags/$1"; [ -d $t ] || mkdir -p $t; shift; local i; for i in $*; do ln -s $(readlink -f $i) $t;done}
2012-02-10 15:43:02
Functions: ln mkdir readlink
0

shell function which allows you to tag files by creating symbolic links directories in a 'tags' folder.

The tag function takes a tag name as its first argument, then a list of files which take that tag. The directory $HOME/tags/tagname will then hold symbolic links to each of the tagged files. This function was modified from bartonski's (http://www.commandlinefu.com/commands/view/10216) inspired by tmsu (found at https://bitbucket.org/oniony/tmsu/wiki/Home) with readlink function by flxndn (http://www.commandlinefu.com/commands/view/10222).

Example:

tag dog airedale.txt .shizturc weimeraner.pl

This will create $HOME/tags/dog which contains symbolic links to airedale.txt .shizturc and weimeraner.pl

pdftk file.pdf dump_data output | grep -i Num
ip a s eth0 | awk -F"[/ ]+" '/inet / {print $3}'
sudo lastb | awk '{if ($3 ~ /([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}/)a[$3] = a[$3]+1} END {for (i in a){print i " : " a[i]}}' | sort -nk 3
2012-09-11 14:51:10
User: sgowie
Functions: awk lastb sort sudo
0

The lastb command presents you with the history of failed login attempts (stored in /var/log/btmp). The reference file is read/write by root only by default. This can be quite an exhaustive list with lots of bots hammering away at your machine. Sometimes it is more important to see the scale of things, or in this case the volume of failed logins tied to each source IP.

The awk statement determines if the 3rd element is an IP address, and if so increments the running count of failed login attempts associated with it. When done it prints the IP and count.

The sort statement sorts numerically (-n) by column 3 (-k 3), so you can see the most aggressive sources of login attempts. Note that the ':' character is the 2nd column, and that the -n and -k can be combined to -nk.

Please be aware that the btmp file will contain every instance of a failed login unless explicitly rolled over. It should be safe to delete/archive this file after you've processed it.

svn st | grep ^\? | awk '{print $2}' | xargs svn add
^[c (ctrl-v esc-c)
2009-03-18 15:15:24
User: angrox
0

Resets a scrambled terminal into its orignal state.

cat file | tee >> file
2009-07-30 07:34:03
User: GeckoDH
Functions: cat file tee
0

The command `cat file >> file` failes with the following error message:

cat: file: input file is output file

`tee` is a nice workaround without using any temporary files.

/bin/cp -n <from> <to>
vim `find . -iname '*.php'`
2011-05-11 01:19:28
User: wsams
Functions: vim
0

In this case, we'll be editing every PHP file from the current location down the tree.

You can show all the files in the vim buffer with :buffers which outputs something like,

:buffers

1 %a "./config/config.php" line 1

2 "./lib/ws-php-library.php" line 0

3 "./lib/css.php" line 0

4 "./lib/mysqldb.class.php" line 0

5 "./lib/config.class.php" line 0

6 "./lib/actions.php" line 0

Press ENTER or type command to continue

If you'd like to edit ./lib/mysqldb.class.php for example, enter :b4 anytime you're editing a file. You can switch back and forth.

slpappasswd
2011-10-13 14:46:03
User: evolix
0

Permit to generate a password for userPassword in ldap.

Use ?slappasswd -g? to generate a random passowrd.

sudo killall -HUP mDNSResponder
2012-05-15 18:33:51
User: Xeno
Functions: killall sudo
0

Purges DNS cache of OS X.

dscacheutil -flushcache does not work since OS X 10.7.

xclip -sel clip < ~/.ssh/id_rsa.pub
mdfind 'kMDItemFSCreationDate >= $time.this_month'
2012-11-13 12:50:51
User: peter4512
0

This uses spotlight indices to find files that have recently been added. Other options include underscore separated versions of: this week, this month, this

year; today, yesterday.

curl ip.appspot.com
pkgchk -l -p <full path to the file>
2009-07-04 08:22:11
User: sengork
Tags: solaris
0

Find which package a file belongs to on Solaris along with it's packaging system metadata.

watch -d 'ls -l'
2009-09-03 20:12:36
User: 0disse0
Functions: watch
Tags: watch stats
0

To highlight the difference between screen updates

snarf http://foo.bar.com/picture.jpg
2009-09-23 04:22:57
0

It can transfer files through the http, gopher, finger, and ftp protocols without user interaction. It is small and fast.

sync; time `dd if=/dev/zero of=bigfile bs=1M count=2048 && sync`
for i in `ndd /dev/ip \? | awk '{ print $1 }' | egrep -v "ip6|status|icmp|igmp|\?"` ; do echo $i `ndd -get /dev/ip $i` ; done | grep -v \?
2010-02-15 12:32:33
User: felix001
Functions: awk echo egrep grep
0

This command is jsut for the main IP settings of ndd. if you need ip6 or icmp edit the text within the egrep inclusion area.

Felix001 - www.Fir3net.com

gnome-open . & disown
find /var/log/apache2 -name 'access.log*gz' -exec zcat {} \; -or -name 'access.log*' -exec cat {} \;
2010-06-19 08:35:12
User: recursiverse
Functions: cat find zcat
0

This command allows you to stream your log files, including gziped files, into one stream which can be piped to awk or some other command for analysis.

Note: if your version of 'find' supports it, use:

find /var/log/apache2 -name 'access.log*gz' -exec zcat {} + -or -name 'access.log*' -exec cat {} +
perl -le '$,=".";print map int rand 256,1..4'
tr -d '\\' | tr -d '\n'
cat ~/.ssh/id_rsa.pub | ssh tester@10.2.6.10 "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys"
2012-07-18 04:41:54
Functions: cat ssh
0

chmod authorized_keys so you don't get "Authentication refused: bad ownership or modes for file /home/user/.ssh/authorized_keys"

sudo usermod -s `which zsh` `whoami`