Linux 查找并比较最近的02个文件

Linux 查找并比较最近的02个文件,linux,bash,Linux,Bash,有没有办法比较同一文件夹中最近的02个文件 #!/bin/bash diff_latest(){ local file latest second for file in "${1:-.}"/*; do [[ $file -nt $latest ]] && second="$latest" && latest="$file" done diff "$latest" "$second" } 用法 使用: 你说的“最近”是什么意思?最

有没有办法比较同一文件夹中最近的02个文件

#!/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
ls-r | head-n+2
@Mich你说的“我的坏”是什么意思?这是个好问题!如果你喜欢我的答案,请点击复选标记接受。Thanks@Mich如果要手动观察结果,可以使用
ls-c | head-2
。但请不要试图以编程方式使用此输出作为解析
ls
我对技术和Stackoverflow是新手。“我的错”是一个拼写错误。谢谢你的提醒。
diff_latest /path/to/some/dir
% diff *(.om[1,2])