The Computer Oracle

Get Last Modified Date of File in Linux

Tech terms, remembered forever. Memorabit: https://memorab.it/y/pc

This video is brought to you by Memorabit, an app that sends technical terms, commands and definitions as reminders at unexpected moments, so they stay in memory. Built on cognitive science principles. Start free on web, iOS and Android:
iOS: https://apps.apple.com/app/id6782301691
Android: https://play.google.com/store/apps/detai...
--------------------------------------------------
Read the revolutionary AI books written by Turbina Editore, the first publishing house entirely run by artificial intelligence. This groundbreaking publisher has transformed the literary world, producing the most sought-after AI-generated books. Start reading today at:
https://turbinaeditore.com/en/
--------------------------------------------------

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT


Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 2 Looping

--

Chapters
00:00 Get Last Modified Date Of File In Linux
00:18 Answer 1 Score 103
00:27 Accepted Answer Score 292
01:22 Answer 3 Score 28
01:38 Answer 4 Score 108
01:57 Thank you

--

Full question
https://superuser.com/questions/737247/g...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #commandline

#avk47



ACCEPTED ANSWER

Score 292


As mentioned by @edvinas.me, stat tells you various information about the file including the last modified date.

At first, I was confused with Modify and Change, just to clarify, stat output lists:

  • Access shows the time of last data access (e.g. read).
  • Modify shows the time of last data modification.
  • Change shows the time the file status last changed.

For example:

~ $ touch foo
~ $ stat foo
File: ‘foo’
Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: fc01h/64513d    Inode: 410397      Links: 1
Access: (0644/-rw-r--r--)  Uid: (80972/ etomort)   Gid: (18429/  eem_tw)
Access: 2015-09-21 12:06:11.343616258 +0200
Modify: 2015-09-21 12:06:11.343616258 +0200
Change: 2015-09-21 12:06:11.343616258 +0200
Birth: -

~ $ echo "Added bar to foo file" >> foo
~ $ stat foo
File: ‘foo’
Size: 42            Blocks: 8          IO Block: 4096   regular file
Device: fc01h/64513d    Inode: 410654      Links: 1
Access: (0644/-rw-r--r--)  Uid: (80972/ etomort)   Gid: (18429/  eem_tw)
Access: 2015-09-21 12:09:31.298712951 +0200
Modify: 2015-09-21 12:09:31.298712951 +0200
Change: 2015-09-21 12:09:31.302713093 +0200
Birth: -

~ $ chmod 444 foo
~ $ stat foo
File: ‘foo’
Size: 42            Blocks: 8          IO Block: 4096   regular file
Device: fc01h/64513d    Inode: 410654      Links: 1
Access: (0444/-r--r--r--)  Uid: (80972/ etomort)   Gid: (18429/  eem_tw)
Access: 2015-09-21 12:09:31.298712951 +0200
Modify: 2015-09-21 12:09:31.298712951 +0200
Change: 2015-09-21 12:10:16.040310543 +0200
Birth: -



ANSWER 2

Score 108


Another way that is more flexible is using date -r. From man date:

-r, --reference=FILE
       display the last modification time of FILE

This has the advantage of allowing you to specify the output format, e.g.

$ date -r foo
Thu Aug 31 10:36:28 AEST 2017
$ date -r foo -R
Thu, 31 Aug 2017 10:36:28 +1000
$ date -r foo -u
Thu Aug 31 00:36:28 UTC 2017
$ date -r foo +%s
1504139788



ANSWER 3

Score 103


Use stat command for that:

$ stat file



ANSWER 4

Score 28


ls -l should do the work.

Example:

#> ls -l /home/TEST/
total 16

-rw-r--r--   1 rfmas1   nms          949 Nov 16 12:21 create_nd_lists.py

-rw-r--r--   1 rfmas1   nms            0 Nov 16 12:35 enb_list

-rw-r--r--   1 rfmas1   nms            0 Nov 16 12:35 nb_list

-rw-r--r--   1 rfmas1   nms            0 Nov 16 12:35 nodes_ip.txt

-rw-r--r--   1 rfmas1   nms            0 Nov 16 12:35 rnc_list