Mich
Mich

Reputation: 3743

Locate and compare the most recent 02 files

Is there a way to compare the most recent 02 files that is located in the same folder?

Upvotes: 2

Views: 77

Answers (2)

SiegeX
SiegeX

Reputation: 140347

#!/bin/bash

diff_latest(){ 
  local file latest second
  for file in "${1:-.}"/*; do
    [[ $file -nt $latest ]] && second="$latest" && latest="$file"
  done  
  diff "$latest" "$second"
}

Usage

diff_latest /path/to/some/dir

Upvotes: 1

johnsyweb
johnsyweb

Reputation: 141810

Using Zsh:

% diff *(.om[1,2])

Explanation.

Upvotes: 0

Related Questions