0
点赞
收藏
分享

微信扫一扫

Print a file's last modified date in Bash

精进的医生 2023-11-06 阅读 44

 

date -r <filename>

#!/usr/bin/env bash
for i in /var/log/*.out; do
  stat -f "%Sm" -t "%Y-%m-%d %H:%M" "$i"
  echo "$i"
done

echo "Please type in the directory you want all the files to be listed with last modified dates" #bash can't find file creation dates

read directory

for entry in "$directory"/*

do
modDate=$(stat -c %y "$entry") #%y = last modified. Qoutes are needed otherwise spaces in file name with give error of "no such file"
modDate=${modDate%% *} #%% takes off everything off the string after the date to make it look pretty
echo $entry:$modDate

REF:

https://stackoverflow.com/questions/16391208/print-a-files-last-modified-date-in-bash



举报

相关推荐

0 条评论