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,619 results
find . | grep -v svn
2011-01-16 03:51:57
User: gwchamb
Functions: find grep
Tags: grep
-1

Unless you have files that include 'svn' in them, this should provide enough information to be useful. If you need to be certain, add the leading dot in the search pattern

skill -KILL -t ttyS0
2009-05-26 21:47:33
User: jipipayo
Functions: skill
-1

when sometimes do a "w" or "who" command and see an orphan console session from time ago, you could kill with this command.

where ttyS0 its the console to kill.

rxvt-unicode -g 999x999 -sr -depth 32 -bg rg-ba:0000/0000/0000/dddd +sb -T irssi -n irssi -name irssichat -e ssh server.com -Xt screen -aAdr -RR irssi irssi
2009-07-30 04:53:17
User: MTecknology
Functions: screen ssh
-1

This will launch and irssi session on your server. If it's not running, it will create the session. If it's running it'll connect to it and destroy any other connections. If compositing is available, the rxvt window will have transparency added. This window will also open maximized. Anything else this does should be easily figured out in the man pages.

aptitude search ~d<string>
2011-08-02 05:19:13
-1

Especially useful for latex packages, which are listed in the description of their Ubuntu package E.g. say I want to find the Ubuntu package containing latex package aeguill:

aptitude search ~daeguill

p texlive-lang-french - TeX Live: French

cvs checkout -l project/src/
du -hs `du -sk * | sort -rn | cut -f2-`
awk 'BEGIN {count=0;prev=-1} {if(count>0) { if(int($1/100) > int(prev/100)) {print $1} } ; prev=$1; count++}' inputFile > rounded
CMD=chrome ; ps h -o pmem -C $CMD | awk '{sum+=$1} END {print sum}'
nohup gnome-open . 0</dev/null 1>/dev/null 2>/dev/null&
2010-03-22 07:19:37
User: drunkcoder
Functions: nohup
-1

this will open the current directory in nautilus detached from your terminal.

cat input.txt | sed 's/\\\033[^a-zA-Z]*.//g'
slpappasswd
2011-10-13 14:46:03
User: evolix
-1

Permit to generate a password for userPassword in ldap.

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

perl -ne 's/\^.{1,7}?m//g;print'
2012-01-02 01:32:33
User: Tracerneo
Functions: perl
Tags: perl regex colors
-1

Removes special characters (colors) in '^]]Xm' and '^]]X;Ym' format from file.

Use pipe ('input | perl [...]') or stream ('perl [...]

You can use 'cat -v infile' as 'input' to show special characters instead of interpreting (there is problem with non-ASCII chars, they are replaced by M-[char]).

awk '{pattern=$1$2; seen[pattern]++; if (seen[pattern] == 1) print NR}' inputFile
ps awwux|awk '{print $1}'|sort|uniq
gem list | cut -d" " -f1 | grep --invert-match "test-unit\|psych\|io-console\|rdoc\|json\|bigdecimal\|rake\|minitest" | xargs gem uninstall -aIx
2014-01-10 10:58:59
User: gdelfino
Functions: cut grep xargs
-1

This command removes all ruby gems except the default ones that can not be removed. It is based on http://geekystuff.net/2009/01/14/remove-all-ruby-gems/

WID=xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}' xdotool windowfocus $WID xdotool key ctrl+shift+t wmctrl -i -a $WID
2010-03-22 08:34:24
User: drunkcoder
Functions: awk grep
-1

open a new tab in active gnome-terminal instance

needs sudo apt-get install xdotool

and sudo apt-get install wmctrl

sed -i 's/\r\n//' file.txt
perl -MModule::Name\ 9999 -e 1
2013-01-15 22:51:39
User: three18ti
Functions: perl
Tags: bash perl zsh
-1

This attempts to load a Perl Module (-M flag) and use version 9999, since no module has a version this high, Perl exits either a) telling you the version of the module installed or b) tells you it can't find the module.

du -sm *|sort -rn|head -10
season=1; for file in $(ls) ; do dir=$(echo $file | sed 's/.*S0$season\(E[0-9]\{2\}\).*/\1/'); mkdir $dir ; mv $file $dir; done
2009-05-27 03:30:58
User: lonecat
Functions: echo file mkdir mv sed
-1

It happened to me that I got a season of a tv-show which had all files under the same folder like /home/blah/tv_show/season1/file{1,2,3,4,5,...}.avi

But I like to have them like this:

/home/blah/tv_show/season1/e{1,2,3,4,5,...}/file{1,2,3,4,5,...}.avi

So I can have both the srt and the avi on one folder without cluttering much. This command organizes everything assuming that the filename contains Exx where xx is the number of the episode.

You may need to set:

IFS=$'\n'

if your filenames have spaces.

xwinwrap -ni -argb -fs -s -st -sp -nf -b -- /usr/libexec/xscreensaver/atlantis -count 20 -window-id WID &
2009-09-23 05:29:21
User: dstahlke
Tags: xwinwrap
-1

xwinwrap allows you to run any program in the root desktop pane. I like to run atlantis, it goes well against Fedora 10's blue sun background. At one time this also served a useful purpose for me as a workaround for a problem that would happen when the video card went into sleep mode.

wget -O xkcd_$(date +%y-%m-%d).png `lynx --dump http://xkcd.com/|grep png`; eog xkcd_$(date +%y-%m-%d).png
awk -vRS="</Tag2>" '/<Tag2>/{gsub(/.*<Tag2>/,"");print}' file
while true; do /bin/ping -q -c1 -w3 8.8.8.8 2>&1 > /dev/null || echo "8.8.8.8 ping failed at $(date +%d/%m/%y) $(date +%H:%M:%S)" >> /var/log/ping.log; sleep 10; done &
2011-05-12 01:51:07
User: Arkey
Functions: echo sleep
-1

This command are using by me for checking connection with Internet.