找到并比较最新的02文件

时间:2012-01-14 08:39:36

标签: linux bash

有没有办法比较位于同一文件夹中的最新02文件?

2 个答案:

答案 0 :(得分:1)

#!/bin/bash

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

用法

diff_latest /path/to/some/dir

答案 1 :(得分:0)

使用Zsh

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

Explanation.