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 using diff from sorted by
Terminal - Commands using diff - 104 results
diff --changed-group-format='differs from line %dF to line %dL|' --unchanged-line-format='' $FILE1 $FILE2 | sed 's/|/\n/'
2011-06-02 15:04:36
User: dullgiulio
Functions: diff sed

Using sed to print newlines as doing it in one line with diff is non-trivial.

Diff files over SSH: ssh [login]@[host] "cat [remote file]" | diff - "[local file]"
2011-04-28 16:59:56
User: dennisfaust
Functions: diff ssh

Sometimes you need to compare two config files on different servers. Put the file names into the above script and let 'er rip.

svn diff -r 1792:HEAD --summarize | awk '{if ($1 != "D") print $2}'| xargs -I {} tar rf incremental_release.tar {}
2011-04-05 15:00:49
User: windfold
Functions: awk diff tar xargs
Tags: bash svn awk xargs tar

The result of this command is a tar with all files that have been modified/added since revision 1792 until HEAD. This command is super useful for incremental releases.

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'...
svn diff --diff-cmd="colordiff"
2011-02-10 14:27:55
User: ruslan
Functions: diff

If colordiff utility installed, it is sometimes handy to call this command. Of course, you should create an alias for it. E.g. svndiff.

hg diff -c $REV --reverse | hg patch --no-commit -
diff <(lsusb) <(sleep 3s && lsusb)
2010-12-27 22:46:54
User: Juluan
Functions: diff sleep

I often use it to find recently added ou removed device, or using find in /dev, or anything similar.

Just run the command, plug the device, and wait to see him and only him

diff <(md5sum render_pack.zip| cut -d " " -f 1) <(md5sum /media/green/render_pack.zip| cut -d " " -f 1);echo $?
2010-12-27 18:29:00
User: schmiddim
Functions: cut diff echo md5sum

I had the problem that the Md5 Sum of a file changed after copying it to my external disk.

This unhandy command helped me to fix the problem.

diff -ua <(w3m -dump http://www.php.net/downloads.php|fgrep -A1 '5.2.15 (tar.bz2)'|awk '/md5:/{print $2}') <(md5sum php-5.2.15.tar.bz2|awk '{print $1}')
2010-12-10 11:31:07
User: sugitaro
Functions: awk diff fgrep md5sum

Use zsh process substitution syntax.

diff <(wget -q -O - URL1) <(wget -q -O - URL2)
diff <(ssh [email protected] cat /path/to/file) <(ssh [email protected] cat /path/to/file2)
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

HTMLTEXT=$( curl -s http://www.page.de/test.html > /tmp/new.html ; diff /tmp/new.html /tmp/old.html ); if [ "x$HTMLTEXT" != x ] ; then echo $HTMLTEXT | mail -s "Page has changed." [email protected] ; fi ; mv /tmp/new.html /tmp/old.html
2010-07-04 21:45:37
User: Emzy
Functions: diff echo mail mv

Checks if a web page has changed. Put it into cron to check periodically.

Change http://www.page.de/test.html and [email protected] for your needs.

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
diff <(tail -10 file1) <(tail -10 file2)
svn diff --diff-cmd='meld' -r 100:BASE FILE
2010-03-31 11:27:20
User: bw
Functions: diff

If you like to view what has been changed between revision 100 and the BASE on FILE. Meld will give you a nice overview.

svn diff | vim -
diff <(lsof -p 1234) <(sleep 10; lsof -p 1234)
2010-03-15 22:55:32
User: zlemini
Functions: diff sleep

This command takes a snapshot of the open files for a PID 1234 then waits 10 seconds and takes another snapshot of the same PID, it then displays the difference between each snapshot to give you an insight into what the application is doing.

diff -x "*CVS*" -r <path-1> <path-2> [<path-3>]
2010-02-17 11:08:17
User: sanmiguel
Functions: diff

This will cause diff to ignore any files whose path matches "*CVS*", ie any CVS control files.

diff {$path1,$path2}/file_to_diff
2010-01-29 23:00:57
User: bartonski
Functions: diff

This is useful when you're diffing two files of the same name in radically different directory trees. For example:





then run the command. Much easier on the eyes when you're looking back across your command history, especially if you're doing the same diff over and over again.

md5 myfile | awk '{print $4}' | diff <(echo "c84fa6b830e38ee8a551df61172d53d7") -
2010-01-29 16:57:13
User: voidpointer
Functions: awk diff echo

Makes sure the contents of "myfile" are the same contents that the author intended given the author's md5 hash of that file ("c84fa6b830e38ee8a551df61172d53d7").