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 <(cd /path-1; find . -type f -print | egrep -i '\.m4a$|\.mp3$') <(cd /path-2; find . f -print | egrep -i '\.m4a$|\.mp3$')
2009-08-17 00:49:31
User: drewk
Functions: cd diff egrep find
3

diff is designed to compare two files. You can also compare directories. In this form, bash uses 'process substitution' in place of a file as an input to diff. Each input to diff can be filtered as you choose. I use find and egrep to select the files to compare.

svn diff | view -
diff <(echo "$a") <(echo "$b")
2009-07-15 07:26:23
User: olorin
Functions: diff echo
25

You got some results in two variables within your shell script and would like to find the differences? Changes in process lists, reworked file contents, ... . No need to write to temporary files. You can use all the diff parameters you'll need. Maybe anything like $ grep "^>"

is helpful afterwards.

tar cvfz changes.tar.gz --exclude-vcs `svn diff -rM:N --summarize . | grep . | awk '{print $2}' | grep -E -v '^\.$'`
2009-07-13 19:39:10
User: jaysee
Functions: awk diff grep tar
2

Handy when you need to create a list of files to be updated when subversion is not available on the remote host. You can take this tar file, and upload and extract it where you need it. Replace M and N with the revisions specific to yours. Make sure you do this from an updated (svn up) working directory.

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 -urp /originaldirectory /modifieddirectory
URL=http://svn.example.org/project; diff -u <(TZ=UTC svn -q log -r1:HEAD $URL | grep \|) <(TZ=UTC svn log -q $URL | grep \| | sort -k3 -t \|)
2009-06-03 14:26:55
User: sunny256
Functions: diff grep sort
Tags: bash svn
2

Lists revisions in a Subversion repository with a timestamp that doesn't follow the revision numbering order. If everything is OK, nothing is displayed.

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
git diff --cached
svn diff $* | colordiff | less -r
2009-02-18 16:19:08
User: introp
Functions: diff less
2

I put this in a shell script called "svndiff", as it provides a handy decorated "svn diff" output that is colored (which you can't see here) and paged. The -r is required so less doesn't mangle the color codes.

diff <(sort file1.txt) <(sort file2.txt)
2009-02-18 15:17:59
Functions: diff sort
4

Sees if two records differ in their entries, irrespective of order.

diff dir1 dir2 | diffstat
2009-02-16 21:21:16
User: raphink
Functions: diff
0

See which files differ in a diff, and how many changes there are. Very useful when you have tons of differences.

diff <(head -500 product-feed.xml) <(head -500 product-feed.xml.old)
2009-02-11 09:24:38
User: root
Functions: diff head
3

Useful for massive files where doing a full diff would take too long. This just runs diff on the first 500 lines of each. The use of subshells to feed STDIN is quite a useful construct.

svn diff --diff-cmd diff -x -uw /path/to/file
2009-02-10 20:39:54
User: katylava
Functions: diff
0

get subversion diff output without distracting whitespace changes. good for when you are cleaning up code to make sure you didn't change anything important. also useful when working with old code, or someone else's code.

diff <(ssh nx915000 "rpm -qa") <(ssh nx915001 "rpm -qa")
git diff HEAD..rev | git apply --index; git commit
2009-02-06 17:29:46
User: Pistos
Functions: diff
4

Use this to make a new commit that "softly" reverts a branch to some commit (i.e. squashes the history into an inverse patch). You can review the changes first by doing the diff alone.

diff -q dir1/ dir2/ | grep differ | awk '{ print "vimdiff " $2 " " $4 }'
2009-02-05 12:37:00
User: binaryslate
Functions: awk diff grep
1

We use this to quickly highlight differences and provide a quick way to cut and paste the command to view the files using the marvellous vimdiff

diff <(sort file1) <(sort file2)
2009-02-04 22:20:13
User: systemj
Functions: diff sort
77

bash/ksh subshell redirection (as file descriptors) used as input to diff

ssh user@host cat /path/to/remotefile | diff /path/to/localfile -
2009-02-04 11:33:19
User: root
Functions: cat diff ssh
145

Useful for checking if there are differences between local and remote files.