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.

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.

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:



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!

Top Tags





Maintained by Jon H.

Site originally by David Winterbottom (user root).

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands tagged git from sorted by
Terminal - Commands tagged git - 113 results
while true; do rsync -vR $(git ls-files | inotifywait -q -e modify -e attrib -e close_write --fromfile - --format '%w') user@host:dest/dir/; done
2014-01-21 10:31:41
User: leucos
Functions: rsync

While edtiing a project under git, it is sometimes nice to sync changes immediately to a test machine.

This command will take care of this if you have inotifywait installed on the developement machine.

Note the -R (relative) in rsync. with

rsync foo/bar/baz user@host:dest/dir/

it will put 'baz' in dest/dir/foo/bar/ which is what we want.

this can be turned into a function for additionnal flexibility :

function gitwatch() {

if [ -z $1 ]; then

echo "You must provide a rsync destination"



while true; do

rsync -vR $(git ls-files | inotifywait -q -e modify -e attrib -e close_write --fromfile -

--format '%w') $1



git log --pretty=oneline --abbrev-commit
git status -s | grep -o ' \S*php$' | while read f; do php -l $f; done
2013-12-14 11:47:54
User: ruslan
Functions: grep read
Tags: git PHP lint

Checks for syntax errors in PHP files modified in current working copy of a Git repository.

for file in $(git ls-files | grep old_name_pattern); do git mv $file $(echo $file | sed -e 's/old_name_pattern/new_name_pattern/'); done
alias tasks='git grep -EI "TODO|FIXME"'
2013-10-21 23:54:46
User: lizardo
Functions: alias grep
Tags: bash git todo

"git grep" automatically excludes untracked files (e.g. compiler output) and files under .git directory. If no directory or file is given, it will recursively search through the current directory.

git reset --hard <commidId> && git clean -f
git config --global diff.external 'bash -c "meld $2 $5"'
find .git/objects -type f -printf "%P\n" | sed s,/,, | while read object; do echo "=== $obj $(git cat-file -t $object) ==="; git cat-file -p $object; done
vim $(git diff origin/master --name-only)
git log --no-merges --format="%an: %s" v1..v2
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
git-createrepo() { repos_path='/srv/git/'; mkdir $repos_path$1; cd $repos_path$1; git init --bare; echo "Repository location: ssh://$USER@`cat /etc/HOSTNAME``pwd`"; cd -; }
2013-05-09 21:44:24
User: batandwa
Functions: cd echo init mkdir
Tags: git

Creates a git repository in a predefined location.

vim -p `git --porcelain | awk {print $2}`
2013-04-29 21:52:23
User: cnelsonsic
Functions: awk vim
Tags: vim git

Opens all files in the index (modified plus not added yet) in tabs in vim.

git log | grep Date | awk '{print " : "$4" "$3" "$6}' | uniq -c
git stash branch testchanges
git for-each-ref --sort=-committerdate --format="%1B[32m%(committerdate:iso8601) %1B[34m%(committerdate:relative) %1B[0;m%(refname:short)" refs/heads/
2013-03-11 20:48:25
User: mstormo
Tags: git branches

Full output in one single git command, no pipes nor other process invocations.

Will also work under cmd on Windows, with MSysGit, and can be aliased, simply add


branch-rel = "for-each-ref --sort=-committerdate --format='%1B[32m%(committerdate:iso8601) %1B[34m%(committerdate:relative) %1B[0;m%(refname:short)' refs/heads/"

to your .gitconfig file.

git grep -l foo | xargs sed -i 's/foo/bar/g'
2013-01-29 16:02:21
User: Schleis
Functions: grep sed xargs
Tags: git

Find all the occurrences in the git repo of 'foo' and replace with 'bar'

48 function gbl() { git for-each-ref --sort=-committerdate --format='%(committerdate) %(authorname) %(refname)' refs/remotes/origin/|grep -e ".$@"|head -n 10; }
vim `git status --porcelain | sed -ne 's/^ M //p'`
2012-11-21 06:31:46
User: seb1245
Functions: sed vim
Tags: vim git

The option --porcelain makes the output of git easier to parse.

This one-liner may not work if there is a space in the modified file name.

vim $(git rev-parse --show-toplevel)/.gitignore
2012-11-20 15:22:35
Functions: vim
Tags: git

A little used command, but one I find very useful when needed.

Note: It only works on gitignores in the top level directory.

vim `git status | grep modified | awk '{print $3}'`
2012-11-19 09:48:46
User: TetsuyO
Functions: awk grep vim
Tags: vim git

This oneliner gets all the 'modified' files in your git repository, and opens all of them in vim.

Very handy when you're starting to work in the morning and you simply want to review your modified files before committing them.

Maybe there are better ways to do that (and maybe integrated in vim and/or git, who knows), but I found quicker to do this oneliner.

wget --no-check-certificate https://code.google.com/p/msysgit/downloads/list -O - 2>nul | sed -n "0,/.*\(\/\/msysgit.googlecode.com\/files\/Git-.*\.exe\).*/s//http:\1/p" | wget -i - -O Git-Latest.exe
2012-11-14 08:17:50
User: michfield
Functions: sed wget
Tags: git windows wget

This command should be copy-pasted in Windows, but very similar one will work on Linux.

It uses wget and sed.

find . -maxdepth 2 -type d -name '.git' -print0 | while read -d ''; do (cd "$REPLY"; git gc); done
2012-11-07 08:38:33
User: unhammer
Functions: cd find read
Tags: git drivespace

Assumes you've cd'd to the folder in which all your git repos reside; you could run it from ~ without -maxdepth, although that might make find take quite a while longer.

If you have several processor cores, but not that much ram, you might want to run

git config --global pack.threads 1

first, since gc-ing can eat lots of ram.

for k in `git branch -r|awk '{print $1}'`;do echo -e `git show --pretty=format:"%Cgreen%ci_%C(blue)%c r_%Cred%cn_%Creset" $k|head -n 1`$k;done|sort -r|awk -F"_" '{printf("%s %17s %-22s %s\n",$1,$2,$3,$4)}'
2012-10-09 21:51:05
User: binaryten
Tags: git

It's useful to run run git st before you commit changes. To see an individual commit it's good practice to type git diff . If you are happy with what you see, to add the file, just type ^diff^add