Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a quick way to determine what is different between two users? Presently I am "sudo -u otheruser env >>out.txt" for each user to a file, and then diffing the two files.

Is there an easier way?

share|improve this question
up vote 1 down vote accepted

If you use bash, you can also do it in one line, avoiding the different temporary files.

diff <( sudo -u user1 env | sort ) <( sudo -u user2 env | sort )

You can also create a function, and put it in your .bashrc (.bash_profile)

function envdiff() {

    if [ -z ${2} ] ; then echo "Usage: envdiff user1 user2" ; fi
    diff <( sudo -u user1 env | sort ) <( sudo -u user2 env | sort )

This should work provided that you don't have to type the other user's passwords. If you do, then maybe it ask for them one after the other; I haven't tested it.

For convenience, you could also use tkdiff instead of diff.

share|improve this answer
note that as env prints the variables in the order they were set, you might want to add |sort after sudo -u user env. – Dan D. Jan 26 '12 at 16:09
@DanD.: Good point! Thanks. I updated my answer. – Karolos Jan 26 '12 at 16:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.