Advertisement
Guest User

Untitled

a guest
Jan 9th, 2020
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.43 KB | None | 0 0
  1. $ touch somefile.txt  # Create file
  2. $ sleep 10
  3. $ touch -a somefile.txt  # Update file's access time (causes a metadata update if done this way)
  4. $ echo 'import os, time, datetime
  5.  
  6. file = "somefile.txt"
  7. print(file)
  8.  
  9. print("Modified")
  10. print(os.stat(file)[-2])
  11. print(os.stat(file).st_mtime)
  12. print(os.path.getmtime(file))
  13.  
  14. print()
  15.  
  16. print("Created")
  17. print(os.stat(file)[-1])
  18. print(os.stat(file).st_ctime)
  19. print(os.path.getctime(file))
  20.  
  21. print()
  22.  
  23. modified = os.path.getmtime(file)
  24. print("Date modified: "+time.ctime(modified))
  25. print("Date modified:",datetime.datetime.fromtimestamp(modified))
  26. year,month,day,hour,minute,second=time.localtime(modified)[:-3]
  27. print("Date modified: %02d/%02d/%d %02d:%02d:%02d"%(day,month,year,hour,minute,second))
  28.  
  29. print()
  30.  
  31. created = os.path.getctime(file)
  32. print("Date created: "+time.ctime(created))
  33. print("Date created:",datetime.datetime.fromtimestamp(created))
  34. year,month,day,hour,minute,second=time.localtime(created)[:-3]
  35. print("Date created: %02d/%02d/%d %02d:%02d:%02d"%(day,month,year,hour,minute,second))' | python3
  36. somefile.txt
  37. Modified
  38. 1578600831
  39. 1578600831.4016254
  40. 1578600831.4016254
  41.  
  42. Created
  43. 1578600867
  44. 1578600867.805996
  45. 1578600867.805996
  46.  
  47. Date modified: Thu Jan  9 21:13:51 2020
  48. Date modified: 2020-01-09 21:13:51.401625
  49. Date modified: 09/01/2020 21:13:51
  50.  
  51. Date created: Thu Jan  9 21:14:27 2020
  52. Date created: 2020-01-09 21:14:27.805996
  53. Date created: 09/01/2020 21:14:27
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement