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.

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





Commands using diff from sorted by
Terminal - Commands using diff - 104 results
git diff $(git log --pretty=format:%h -2 --reverse | tr "\n" " ")
2015-07-07 17:50:50
Functions: diff tr
Tags: git

A great command to assign to an alias, allowing you to git diff the last two commits in git.

diff a.txt b.txt | grep -E '^(<|>)' | sed 's:^< \(.*\):<del style="color\:red; text-decoration\: none">- \1</del><br>:' | sed 's:^> \(.*\):<ins style="color\:green; text-decoration\: none">+ \1</ins><br>:'
diff <(ssh $remote_site cat $file) $file
2015-05-09 11:11:56
User: hal8
Functions: cat diff ssh

opens the output of some command as a file so this also works with graphical editors like meld, kdiff3 etc

meld <(ssh $remote_site cat .zshrc) .zshrc
git diff --word-diff --color-words | aha > index.html && firefox index.html
vim `git diff --name-only`
2015-02-25 11:12:49
User: mbudde
Functions: diff vim
Tags: vim git

For editing files added to the index:

vim `git diff --name-only --cached`

To edit all changed files:

vim `git diff --name-only HEAD`

To edit changed files matching glob:

vim `git diff --name-only -- '*.html'`

If the commands needs to support filenames with whitespace, it gets a bit hacky (see http://superuser.com/questions/336016/invoking-vi-through-find-xargs-breaks-my-terminal-why for the reason):

git diff --name-only -z | xargs -0 bash -c '</dev/tty vim "$@"' x

The last part can be put in a script named e.g. vimargs, and used with any command outputting NUL separated filenames:

git grep -lz foobar | vimargs
FILE=somefile.js; LOG=~/changes.diff; truncate -s0 ${LOG}; for change in $(svn log ${FILE} | awk -F' | ' '/^r[0-9]+/{print $1}'); do svn log -c ${change} >> ${LOG}; printf "\n" >> ${LOG}; svn diff -c ${change} >> ${LOG}; printf "\n\n\n" >> ${LOG}; done
2014-12-23 20:00:54
User: hochmeister
Functions: awk diff printf
Tags: svn diff log

from a svn repo, print a log, with diff, of each commit touching a given file

diff -qr /dirA /dirB
ssh HOST '(cd REPO_DIR && git diff --name-only HEAD | cpio -o -Hnewc --quiet)' | cpio -iduv --quiet -Hnewc
2014-02-01 18:40:31
User: ivan4th
Functions: cd cpio diff ssh
Tags: ssh git cpio

Copy changed files from remote git repository, _including binary ones_, staged and unstaged alike. Note that this command doesn't handle deleted files properly.

lsof -c diff -o -r1 | grep $file
2014-01-29 18:35:28
User: d0g
Functions: diff grep

When running a long `diff -r` over folders, this simulates a "verbose" mode where you can see where diff is in the tree.

Replace $file with the first part of the path being compared.

diff <(cat /etc/fstab | grep vol | grep -v "^#" | awk '{print $1}') <(df -h | grep vol)
2014-01-23 15:18:08
User: Koobiac
Functions: awk cat df diff grep
Tags: diff fstab df

With this command, you can check the difference between the volumes mounted and the volume in /etc/fstab.

diff <(ssh-keygen -y -f ~/.ssh/id_rsa) <(cut -d' ' -f1,2 ~/.ssh/id_rsa.pub)
diff <(sort <(md5deep -b -r /directory/1/) ) <(sort <(md5deep -b -r /directory/2/)
2013-08-19 18:20:49
Functions: diff sort
Tags: bash Linux diff

Compares the md5 checksums of the contents of two directories, outputting the checksum and filename where any files differ. Shows only the file name, not the full path.

diff <(sort <(md5deep -r /directory/1/) |cut -f1 -d' ') <(sort <(md5deep -r /directory/2/) |cut -f1 -d' ')
2013-08-18 22:13:07
Functions: cut diff sort
Tags: bash Linux diff

Compute the md5 checksums for the contents of two mirrored directories, then sort and diff the results. If everything matches, nothing is returned. Otherwise, any checksums which do not match, or which exist in one tree but not the other, are returned. As you might imagine, the output is useful only if no errors are found, because only the checksums, not filenames, are returned. I hope to address this, or that someone else will!

vim $(git diff origin/master --name-only)
diff <(cd A; find -type f|xargs md5sum ) <(cd B; find -type f | xargs md5sum )
2013-07-02 18:02:05
User: glaudiston
Functions: cd diff find md5sum xargs

This is usefull to diff 2 paths in branches of software, or in different versions of a same zip file. So you can get the real file diff.

diff /path/to/localfile <(ssh user@host cat /path/to/remotefile)
2013-05-24 09:24:31
User: mc0e
Functions: cat diff ssh

Or, if you have restricted access for sftp only, I think you can still do this:

diff /path/to/localfile <(scp user@host:/path/to/remotefile >(cat))
diff -BI '^#' file{1,2}
diff -u <(grep -vE '^(#|$)' file1) <(grep -vE '^(#|$)' file2)
2013-02-12 13:59:39
Functions: diff grep

Runs a diff on two files ignore comments and blank lines (diff -I=RE does not work as expected). Adapted from a post found on stackexchange.

git diff --name-only --diff-filter=AMXTCR HEAD~2 HEAD | xargs -l -I{} cp --parents --verbose "{}" target_dir
diffprocess () { diff <($*) <(sleep 3; $*); }
2013-01-25 08:46:41
User: totti
Functions: diff sleep

Execute a process or list of commands in the given interval and output the difference in output.

svn diff . -r43:HEAD --summarize | cut -c9-99999 | cpio -pvdmu ~/destination
2012-12-26 05:02:59
User: Sebasg
Functions: cpio cut diff
Tags: svn

Get the list of changed files between revision 43 and HEAD revision: svn diff . -r43:HEAD --summarize

Strip extra 8 characters from every line: cut -c9-99999

Copy the listed files to home/me/destination: cpio -pvdmu ~/destination

Make a plain copy (-p), list files being copied (-v), create needed directories (-d), preserve modification time (-m), overwrite unconditionally (-u)

diff -qr <dir1> <dir2>
diff <(cd dir1 && find . | sort) <(cd dir2 && find . | sort)
diff -u <(ssh -t user@host1 sudo cat /dir1/file1) <(ssh -t user@host2 sudo cat /dir2/file2)
diff ../source-dir.orig/ ../source-dir.post/ | grep "Only in" | sed -e 's/^.*\:.\(\<.*\>\)/\1/g' | xargs rm -r
2012-10-17 14:12:32
User: bigc00p
Functions: diff grep rm sed xargs

Good for when your working on building a clean source install for RPM packaging or what have you. After testing, run this command to compare the original extracted source to your working source directory and it will remove the differences that are created when running './configure' and 'make'.