Shell Script That Display The Last Modification Time Of Any File

in Categories File-management last updated September 13, 2008
#!/bin/bash
# Write a shell script that displays the last modification time of any file.
# -------------------------------------------------------------------------
# Copyright (c) 2008 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
echo -n "Enter a filename to see last modification time : "
read fileName
 
# make sure file exits
if [ ! -f $fileName ]
then
	echo "$fileName not a file"
	exit 1
fi
 
# use stat command to display 
echo "$fileName was last modified on $(stat -c %x $fileName)"

Share this on:

1 comment

  1. % x will NOT give time modified it will give time of last ACCESS its %y that gives time of last modification this i think though might vary across bash versions i am just going off the Manual pge in my possession

    Have a question? Post it on our forum!