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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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 tagged diff from sorted by
Terminal - Commands tagged diff - 53 results
:w !diff -u % -
wdiff -n -w $'\033[30;41m' -x $'\033[0m' -y $'\033[30;42m' -z $'\033[0m' oldversion.txt newversion.txt
2011-11-10 18:35:41
User: abracadabra
Tags: diff color wdiff

Requires wdiff. Prints the word-by-word diff with the old version highlighted in red, and the new in green. Change the colors by altering 41m and 42m. 45m is more of a magenta and may be easier to read.

diffxml() { diff -wb <(xmllint --format "$1") <(xmllint --format "$2"); }
2011-10-06 07:36:13
User: sharfah
Functions: diff
Tags: diff xml xmllint

Diffs two xml files by formatting them first using xmllint and then invoking diff.

Usage: diffxml XMLFile1 XMLFile2

diff -U 9999 file_a file_b | tail -n +3 | grep -P "^(\ Header|\-|\+)"
2011-09-21 21:33:40
User: nnutter
Functions: diff grep tail
Tags: diff

Maybe very limited in its applicability but could be of use at times.

bsdiff <oldfile> <newfile> <patchfile>
2011-09-13 18:22:40
User: totti

Upload/download newer version of any file with less size and high speed.

To remake the new file use

bspatch <oldfile> <newfile> <patchfile>
diff rpm_output_from_other_computer <(rpm -qa|sort)
2011-06-25 11:45:15
User: xeor
Functions: diff rpm

Description is moved to "Sample output" because the html sanitizer for commandlinefu breaks the examples..

sdiff <(ls /) <(ls /usr)
svn diff -r M:N file.php | patch -p0
2011-03-29 04:15:02
User: ruslan
Functions: diff patch

M - current revision, N - older revision

diff -Naur --strip-trailing-cr
2011-02-10 14:32:42
User: ruslan
Functions: diff

This form is used in patches, svn, git etc. And I've created an alias for it:

alias diff='diff -Naur --strip-trailing-cr'

The latter option is especially useful, when somebody in team works in Windows; could be also used in commands like

svn diff --diff-cmd 'diff --strip-trailing-cr'...
hg diff -r$((`hg -q par | cut -d":" -f1`-1))
diff -b $file1 $file2 # GNU Tools
diff <(perl -wpl -e '$_ =~ s/^\s+|\s+$//g ;' file1) <(perl -wpl -e '$_ =~ s/^\s+|\s+$//g ;' file2)
2010-10-06 19:14:42
User: jemptymethod
Functions: diff perl
Tags: bash diff perl

**NOTE** Tekhne's alternative is much more succinct and its output conforms to the files actual contents rather than with white space removed

My command on the other hand uses bash process substitution (and "Minimal" Perl), instead of files, to first remove leading and trailing white space from lines, before diff'ing the streams. Very useful when differences in indentation, such as in programming source code files, may be irrelevant

dpkg-query -l > 1.lst; sudo apt-get install -y build-essential; ./configure; make; sudo checkinstall -D make install; dpkg-query --list > 2.lst; diff 1.lst 2.lst | grep '^>' | awk '{print $3}' | xargs sudo apt-get remove -y --purge
2010-06-16 22:06:07
User: danlangford

on a dpkg managed system this PATTERN will help you generate .deb files from source AND remove all the dev libs you had to install. i hate cluttering up my machine with rouge packages and headers.

it would be pretty darn easy on rpm systems as well. i just dont have a rpm managed system to test on right now.

NOTE, you sharp ones will notice that it uninstalls the deb you just made! yeah, but the deb is still there to do with it what you want, like re install it. or you can just grep -v after the diff

diff -wubBEr -x .svn dirA dirB
colordiff -yW"`tput cols`" /path/to/file1 /path/to/file2
2009-11-26 18:00:53
User: dweomer21

Barely worth posting because it is so simple, but I use it literally all the time. I was always frustrated by the limitations that a non-gui environment imposes on diff'ing files. This fixes some of those limitations by colourising the output (you'll have to install colordiff, but it is just a wrapper for diff itself), using side-by-side mode for clearer presentation, and of course, the -W parameter, using tput to automatically insert you terminal width. Note that the double quotes aren't necessary if typed into terminal as-is. I included them for safety sake,

diff <(ssh server01 'cd config; find . -type f -exec md5sum {} \;| sort -k 2') <(ssh server02 'cd config;find . -type f -exec md5sum {} \;| sort -k 2')
2009-09-11 15:24:59
User: arcege
Functions: diff find md5sum sort ssh

This can be much faster than downloading one or both trees to a common servers and comparing the files there. After, only those files could be copied down for deeper comparison if needed.

vimdiff <(svn cat "$1") "$1"
2009-09-04 18:41:40
User: plasticboy
Functions: cat
Tags: svn vim diff color

This will diff your local version of the file with the latest version in svn. I put this in a shell function like so:

svd() { vimdiff <(svn cat "$1") "$1"; }
svn diff | view -
gdiff --unified=10000 input.file1 inpute.file2 | egrep -v "(^\+[a-z]|^\-[a-z])"| sort > outputfile.sorted
2009-06-18 20:35:00
User: slashdot
Functions: egrep sort

This commands will make it easier to select only common items between two files being compared. If your lines start with things other than lowercase a-z, adjust this Regex appropriately. Number of lines in the output has been set to no more than 10000, and should be adjusted as needed.

opendiff <file1> <file2>
2009-06-16 03:22:52
User: claytron

This command will open up the two files in FileMerge on OS X. You can also compare two directories.

opendiff directory1 directory2

NOTE: FileMerge is a part of the OS X Developer Tools, available on the install disc.

svn diff <file> | vim -R -
2009-06-13 22:00:49
User: caiosba
Functions: diff vim
Tags: svn vim diff color

Simple way to achieve a colored SVN diff

diff -uw <(fmt -1 {file1, file2})
2009-05-23 03:11:08
User: sunny256
Functions: diff fmt
Tags: bash diff

It can be hard to spot differences in reformatted files, because of all the diff noise created by word wrapped lines. This command removes all the noise and performs a word-by-word diff. To ignore empty lines, add -B to the diff command. Also, if this is something you do often, you might want to check out the wdiff(1) program.

diff <(cd dir1 && find | sort) <(cd dir2 && find | sort)
2009-05-21 04:44:29
User: mbirk
Functions: cd diff find
Tags: bash diff find

This uses Bash's "process substitution" feature to compare (using diff) the output of two different process pipelines.

diff <(ssh alice cat /etc/apt/sources.list) <(ssh bob cat /etc/apt/sources.list)