Print a file's last modified date in Bash

 

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

posted @ 2018-04-25 04:59  emanlee  阅读(201)  评论(0编辑  收藏  举报