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

Commands tagged diff from sorted by
Terminal - Commands tagged diff - 51 results
diffxml() { diff -wb <(xmllint --format "$1") <(xmllint --format "$2"); }
2011-10-06 07:36:13
User: sharfah
Functions: diff
Tags: diff xml xmllint
13

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
0

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
7

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
0

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
1

M - current revision, N - older revision

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

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
2

**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
0

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
9

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
14

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
2

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
-1

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
-3

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
14

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
3

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
30

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)
diff <(nmap -sP 192.168.1.0/24 | grep ^Host | sed 's/.appears to be up.//g' | sed 's/Host //g') auth.hosts | sed 's/[0-9][a-z,A-Z][0-9]$//' | sed 's/</UNAUTHORIZED IP -/g'
2009-03-12 05:28:08
User: bandit36
Functions: diff grep sed
Tags: diff sed nmap grep
1

populate the auth.hosts file with a list of IP addresses that are authorized to be in use and when you run this command it will return the addresses that are pingable and not in the authorized list.

Can be combined with the "Command line Twitter" command to tweet unauthorized access.

svn diff ARGUMENTS_FOR_DIFF | source-highlight --out-format=esc --src-lang=diff