Print a file's last modified date in Bash Print a file's last modified date in Bash unix unix

Print a file's last modified date in Bash


Isn't the 'date' command much simpler? No need for awk, stat, etc.

date -r <filename>

Also, consider looking at the man page for date formatting; for example with common date and time format:

date -r <filename> "+%m-%d-%Y %H:%M:%S"


You can use thestatcommand

stat -c %y "$entry"

More info

%y   time of last modification, human-readable


Best is

date -r filename +"%Y-%m-%d %H:%M:%S"