-->

Script to print the last modification time of file if exists

Posted by Admin on
Write a script that accepts a file name as arguments and display the last modification time if the file exists and a suitable message if it doesn't.


if [ -f $1 ]
then
ls -l $1 | awk '{print $5 $6 $7}'
else
echo "file does not exist"
fi

Note : the main logic in above script is this "ls -l $1 | awk '{print $5 $6 $7}' ". 

In this line ls -l $1  prints all the details of the file and awk command prints the 5,6 and 7th attribute. 
 


No comments:

Post a Comment