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
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; }

netstat -pnut -W | column -t -s $'\t'
2014-05-03 00:48:53
User: Nadiar
Functions: column netstat
2

This takes all of the tab spaces, and uses column to put them into the appropriately sized table.

find directory -type l -lname string
2014-05-02 14:44:24
User: gumption
Functions: find
Tags: find
1

Finds all symbolic links in the specified directory which match the specified string pattern.

I used this when upgrading from an Apple-supported version of Java 6 (1.6.0_65) to an Oracle-supported version (1.7.0_55) on Mac OS X 10.8.5 to find out which executables were pointing to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands (Apple version) vs. /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/bin (Oracle version). However, it appears the current JDK installation script already takes care of modifying the links.

find /some/directory/* -prune -type f -name *.log
2014-05-02 00:14:32
User: bigstupid
Functions: find
0

This find syntax seems a little easier to remember for me when I have to use -prune on AIX's find. It works with gnu find, too.

Add whatever other find options after -prune

psql -X -A -t -c "SELECT version();"
2014-05-01 18:10:20
User: malathion
0

Without using a pipe.

-X ignores the user's .psqlrc configuration file

-A sets un-aligned table output mode

-t prints rows only (no headers or footers)

xset dpms force off
2014-05-01 14:16:27
User: GusPS
2

To turn off monitor:

xset dpms force off

To turn on, simply press a key, or move mouse/mousepad.

10,30,50 * * * * ping -c1 -w3 www.test.com >/dev/null
10,30,50 * * * * ping -q -c1 -w3 www.test.com | grep '1 received' - || mail -ne -s'Host 192.168.0.14 not reachable' test@gmail.com
git rm $(git ls-files --deleted)
2014-05-01 06:21:56
User: jaapie
Functions: rm
Tags: git
1

You'll probably want to pass in the -rf options if you have to delete a directory or something.

for i in $(cat vulns.txt); do echo $i; rpm -qa ?changelog | grep -i $i; done
2014-04-30 16:11:14
User: sonny108
Functions: cat echo grep rpm
0

Found it online and could be very useful

pgrep 'sleep' | while read pid; do pstree -sa -H$pid $pid ; done
csvcount() { for dir in $@; do echo -e "$(find $dir -name '*.csv' | wc -l)\t$dir"; done }
ifconfig |grep HWaddr |cut -d ' ' -f 1,11 |grep eth0 |cut -d ' ' -f 2|xargs | awk -F':' '{ print $1$2$3$4$5$6 }'
2014-04-25 18:43:47
User: simplewall
Functions: awk cut grep ifconfig xargs
0

Many tasks need mac id check. above command exactly do the same

ps -efa | grep httpd | grep -v grep | awk '{ print $2 }' |xargs