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,586 results
awk '$1=="Host"{$1="";H=substr($0,2)};$1=="HostName"{print H,"$",$2}' ~/.ssh/config | column -s '$' -t
2014-05-24 20:51:47
User: wejn
Functions: awk column
Tags: awk column
3

Spits out table that shows your Host->HostName aliases in ~/.ssh/config

alias pp='python -mjson.tool|pygmentize -l js'
2014-05-22 10:29:44
User: wires
Functions: alias
Tags: bash json
5

Leave out pygmentize or `pip install pygments` first.

while true; do clear; cat /proc/[0-9]*/stat | cut -d' ' -f 3 | sort | uniq -c | awk '{print $2" "$1}'; echo '---'; sleep 1; done
ssh [remote-machine] "cat file" | xclip -selection c
2014-05-19 16:34:44
User: conga
Functions: ssh
1

ssh from local to remote and pipe output of file to the local clipboard

svn copy http://svnserver.com/svn/trunk/htdocs/CMS/views/module/scripts/modal/dialog-settings-items.phtml@3143 -r 3143 htdocs/CMS/views/module/scripts/modal/dialog-settings-items.phtml
2014-05-16 10:35:19
User: fabio
0

3143 is the latest revision with a file

ps -e -o pid,vsz,comm= | sort -n -k 2
2014-05-14 00:36:50
Functions: ps sort
-1

left-most column is PID, middle is virtual memory being consumed, right-most is actual process.

for i in $(getent group|cut -d: -f1); do sudo usermod -a -G "$i" $USER; done
[ ! -d /squashed/usr ] && mkdir -p /squashed/usr/{ro,rw} ; mksquashfs /usr /squashed/usr/usr.sfs.new -b 65536 ; mv /squashed/usr/usr.sfs.new /squashed/usr/usr.sfs ; reboot
2014-05-10 06:01:06
User: mhs
Functions: mkdir mv
4

Periodically run the one-liner above if/when there are significant changes to the files in /usr/

= Before rebooting, add following to /etc/fstab : =

/squashed/usr/usr.sfs /squashed/usr/ro squashfs loop,ro 0 0 usr /usr aufs udba=reval,br:/squashed/usr/rw:/squashed/usr/ro 0 0

No need to delete original /usr/ ! (unless you don't care about recovery). Also AuFS does not work with XFS

spacecmd --server server softwarechannel_listlatestpackages softwarechannel.name | grep ^kernel-[[:digit:]]
$ date --date='@1268727836'
jhead -rgt file-name.jpg
du -hs file-name
alias gitlog='git log -10 --graph --date-order -C -M --pretty=format:"%C(yellow)%h%C(reset) - %C(bold green)%ad%C(reset) - %C(dim yellow)%an%C(reset) %C(bold red)>%C(reset) %C(white)%s%C(reset) %C(bold red)%d%C(reset) " --abbrev-commit --date=short'
2014-05-08 09:43:55
User: deklau
Functions: alias
0

Cool alias that show a a better Git log

git status --porcelain | sed -ne 's/^ M //p' | tr '\n' '\0' | tr -d '"' | xargs -0 vim
2014-05-08 08:36:27
User: uschrisf
Functions: sed tr xargs
Tags: vim git
0

Works even with spaces in filenames.

As an alias in .gitconfig:

[alias]

editchanged = "!git status --porcelain | sed -ne 's/^ M //p' | tr '\\n' '\\0' | tr -d '\"' | xargs -0 vim"

ffmpeg -i input_file.mp4 -strict experimental output_file.webm
2014-05-08 01:45:33
User: angryunicorn
Tags: ffmpeg
1

If you're using the experimental vorbis encoder (homebrew version of libffmpeg)

find . -name '*.phtml' | xargs perl -pi -e 's/(?!(<\?(php|xml|=)))<\?/<\?php/g;'
2014-05-07 14:33:19
User: crashspeeder
Functions: find perl xargs
0

Tired of front end developers using short open tags in your views? This will replace all instances of

echo thisIsATest | sed -E 's/([A-Z])/_\L\1/g'
diskutil list
find . -regex ".*\(avi\|mp4\|wmv\)$" -print0 | xargs -0 sha1sum
function google () { st="$@"; open "http://www.google.com/search?q=${st}"; }
2014-05-07 03:14:05
User: plasticphyte
3

Searches Google, but requires no "", and will also search all terms input in the CL, eg:

> google foo bar

returns search URL "

You could also use awk to replace all spaces with a +, which is how the Google search handles spaces, but that makes it more than one line.

aspell -d en dump master | aspell -l en expand > words
man inet
find . -exec rename 's/_/\ /g' {} +
2014-05-05 02:47:19
User: KlfJoat
Functions: find rename
1

Everyone wants to take spaces out of filenames. Forget that. I want to put them back in. We've got tools and filesystems that support spaces, they look better, so I'm going to use them.

Because of how find works I find I need to run this multiple times, if it's renaming subdirs. But it can be re-run without issues.

I got this version of the command from a comment in this underscore-generating command. http://www.commandlinefu.com/commands/view/760/find-recursively-from-current-directory-down-files-and-directories-whose-names-contain-single-or-multiple-whitespaces-and-replace-each-such-occurrence-with-a-single-underscore. All I did was change the regex.

brew update && brew upgrade
stat -c '%n %U:%G-%a' *
2014-05-03 04:56:23
User: snipertyler
Functions: stat
Tags: permissions
3

#Alias

alias perm="stat -c '%n %U:%G-%a'"

#Function

perm() { for ll in $@; do stat -c "%n %U:%G-%a" "$ll"; done; }