sh 将子目录结构的上次修改日期更新为当前时间

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 将子目录结构的上次修改日期更新为当前时间相关的知识,希望对你有一定的参考价值。

#!/bin/bash

# script to recursively traverse a directory and update all last modified dates
function traverse() {   

for file in "${1}"/*
do
 if [ ! -d "${file}" ] ; then
  echo "Found file ${file} in ${1}."
  touch ${file}
  printf "Updated its modification date to: " | sed 's/^/   /'
  stat -c %y ${file}
 else
  echo "Entering directory ${file}..."
  touch "${file}"/a.a
  rm "${file}"/a.a
  printf "Updated its modification date to: " | sed 's/^/   /'
  stat -c %y ${file}
  traverse "${file}"
  echo "Leaving directory ${file}..."
 fi
done
}

function main() {
 traverse "$1"
}

main "$1"

以上是关于sh 将子目录结构的上次修改日期更新为当前时间的主要内容,如果未能解决你的问题,请参考以下文章