Wednesday, November 19, 2014

Shell Script That Display The Last Modification Time Of Any File

  1. #!/bin/bash
  2. # Write a shell script that displays the last modification time of any file.
  3. # -------------------------------------------------------------------------
  4. # Copyright (c) 2008 nixCraft project <http://cyberciti.biz/fb/>
  5. # This script is licensed under GNU GPL version 2.0 or above
  6. # -------------------------------------------------------------------------
  7. # This script is part of nixCraft shell script collection (NSSC)
  8. # Visit http://bash.cyberciti.biz/ for more information.
  9. # -------------------------------------------------------------------------
  10.  
  11. echo -n "Enter a filename to see last modification time : "
  12. read fileName
  13.  
  14. # make sure file exits
  15. if [ ! -f $fileName ]
  16. then
  17. echo "$fileName not a file"
  18. exit 1
  19. fi
  20.  
  21. # use stat command to display
  22. echo "$fileName was last modified on $(stat -c %x $fileName)"

0 comments: