diff

Table of content

Commands

CommandDescription
diff [file(descriptor)1] [file(descriptor)2]compares two files/file descriptors
diff -y [f(d)1] [f(d)2]compares with side-by-side view
diff -r [f(d)1] [f(d)2]recursively compare any subdirectories found
diff -q [f(d)1] [f(d)2]report only when files differ
diff --no-dereferencedon’t follow symbolic links

Samples

Compare output of commands

To compare the output of two commands, you need to use file descriptors (fd) which can be done like this diff <(command1) <(command2)

$ diff -y <(find /data/scripts/old -type f -ianme "*.sh" -exec basename {} \; | sort) <(find /data/scripts/new -type -f -iname "*.sh" -exec basename {} \; | sort)
backup_all.sh                       backup_all.sh
                                  > changeBG_dualscreen.sh
                                  > changeBG.sh
change_keyboard_definitions.sh      change_keyboard_definitions.sh
configmanagement.sh                 configmanagement.sh
connect_socks5.sh                   connect_socks5.sh
fstrim.sh                           fstrim.sh
get-gpg-keys.sh                     get-gpg-keys.sh
get-keys.sh                         get-keys.sh
get_sound_vol.sh                    get_sound_vol.sh
git-status.sh                       git-status.sh
git-update.sh                     <
google-chrome.sh                    google-chrome.sh
gource.sh                           gource.sh
load_prompt.sh                      load_prompt.sh
                                  > lockscreen.sh

Alternatives

  • vimdiff: As you could guess, it gives you the diff in vim (in split view) allowing you to perform also changes
  • git: Yes, also with git you can perform diffs using the command git diff --no-index [path/file/1] [path/file/2]