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 using diff from sorted by
Terminal - Commands using diff - 98 results
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
0

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
1

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
0

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
0

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
0

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
6

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

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
0

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
1

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
0

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
0

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'.

SUBNET="192.168.41" ; diff -y <(nmap -sP -n ${SUBNET}.0/24 | grep ${SUBNET}. | awk '{print $5}' | sort -t"." -k4 -n) <(for i in $(seq 1 254); do echo ${SUBNET}.$i; done)
2012-08-28 09:11:18
User: michel_p
Functions: awk diff echo grep seq sort
0

The command will make it easy to determine free IP ranges in a crowded sub-net.

git diff -U10|dwdiff --diff-input -c|less -R
git diff -U10 |wdiff --diff-input -a -n -w $'\e[1;91m' -x $'\e[0m' -y $'\e[1;94m' -z $'\e[0m' |less -R
2012-08-15 01:42:16
Functions: diff less
2

I've been using colordiff for years. wdiff is the new fav, except its colors. Word delimited diffs are more interleaved, easing the chore of associating big blocks of changes.

diff <(ssh user@host cat /path/to/remotefile) /path/to/localfile
git diff | git apply --reverse
while true; do iptables -nvL > /tmp/now; diff -U0 /tmp/prev /tmp/now > /tmp/diff; clear; cat /tmp/diff; mv /tmp/now /tmp/prev; slee p 1; done
2012-04-15 00:02:33
Functions: cat diff iptables mv
0

this alternative shows the differences as they occur so that they are made plain