File Last Modification Information in SHELL Script

SHELL Script Example: File Last Modification Information in Seconds

SHELL Script Example: how to get file last modification information in seconds by using SHELL script?

Make a file "file-last-modify.sh" then copy & past the bellow code then Logon to command prompt to get some interesting result:

#!/bin/bash
. $HOME/.bash_profile

TheFile="test.txt"
CurrentTimeInSeconds=`date +%s`
FileLastModificationTimeInSeconds=`date -r $TheFile +%s`

LastActivityInSeconds=$((CurrentTimeInSeconds-FileLastModificationTimeInSeconds))
LastActivityInMinutes=$((LastActivityInSeconds/60))

echo ""
echo "Display File Activity Information With Reference to Current Date Time"
echo ""
echo "TheFile :"$TheFile
echo "---------------------------------------------------------------------"

echo "CurrentTimeInSeconds :"$CurrentTimeInSeconds
echo "FileLastModificationTimeInSeconds :"$FileLastModificationTimeInSeconds
echo "LastActivityInSeconds :"$LastActivityInSeconds
echo "LastActivityInMinutes :"$LastActivityInMinutes

echo "---------------------------------------------------------------------"

echo ""

if everything went well you should get some result as desired as follows:

SHELL Script Example: File Last Modification Information in Seconds - output in the unix shell command prompt

 

Related Tutorial Examples

  1. AWK SHELL Script File Last Modification Information Changing Delimiter
  2. Get File Last Modification Time Information in SHELL Script
  3. File Last Modification Information in SHELL Script
  4. UNIX Command Example: File Last Modification Information
  5. UNIX Command Example: GMT Date Time File Last Modification Information
  6. UNIX Command Example: File Last Modification UTC GMT Information
  7. UNIX Command Example: Display File Last Modification Information
  8. 19 Examples to Learn MySQL
  9. 28 Tutorials to Learn Oracle
  10. 20 Steps to Make CakePHP Blog Project

No comments:

Post a Comment

leave your comments here..