Antwoorden (7)
Oplossing gevonden!
Zoals vermeld door @edvinas.me, stat vertelt je verschillende informatie over het bestand inclusief de laatst gewijzigde datum.
In het begin was ik verward met Modify en Change, ter verduidelijking, stat uitvoerlijsten:
- Toegang toont het tijdstip van de laatste gegevenstoegang (e. g. lezen).
- Wijzigen toont het tijdstip van laatste gegevensaanpassing.
- Wijzigen toont het tijdstip waarop de bestandsstatus voor het laatst is gewijzigd.
bijvoorbeeld:
~ $ 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: -
Een andere manier die flexibeler is, is het gebruik van date -r. Van man date:
-r, --reference=FILE
display the last modification time of FILE
Dit heeft het voordeel dat u het uitvoerformaat kunt specificeren, bijv.
$ 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
ls -l moet het werk doen.
Voorbeeld:
#> 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
_Bouwen van @Adam Taylor ‘s commentaar in @phoops ’s antwoord en @Sparhawk ’s antwoord.
Om precies te zijn _krijg de datum (met behulp van 3 oktober 2019 voor voorbeelden omdat het mijn laatste verjaardag was, hier is mijn venmo als je het gevoel hebt dat het leidde tot mij financieel te zegenen: @levi_uzodike)
stat -c %y file | cut -d' ' -f1geeft je2019-10-03date +%F -r filegeeft je ook2019-10-03date +%D -r filegeeft je10/03/19date +%x -r filegeeft je waarschijnlijk ofwel10/03/2019, of10/03/19als je in de V.S. bent en ofwel03/10/2019, of03/10/19als je in de V.K. bent, om maar een paar voorbeelden te noemen (er zijn natuurlijk meer mogelijkheden)
Deze date formaat opties zijn, naar mijn mening, combinaties van andere formaat opties. Hier zijn enkele verklaringen van de man pagina :
%b locale’s verkorte maandnaam (bijv. Jan) %B locale’s volledige maandnaam (bijv, Januari) … %d dag van de maand (bv. 01) %D datum; zelfde als %m/%/%y %e dag van de maand, gevuld met ruimte; zelfde als %_d %F volledige datum; zelfde als %Y-%m-%d … %m maand (01..12) … %x locale’s datumweergave (bv, 12/31/99) … %y laatste twee cijfers van het jaar (00..99) %Y year … Standaard, datumvelden numeriek met nullen.
De volgende optionele vlaggen kunnen volgen `%’:
- (hyphen) do not pad the field
_ (underscore) pad with spaces
0 (zero) pad with zeros
^ use upper case if possible
# use opposite case if possible
N.B.: These flags don’t work on the “combo formats” like %F, %D and %x. They are for the “singular field formats”.
Apparently this last flag ( # ) does not work as I’d expect (e.g., if date +%b gives Oct, date +%#b gives OCT as opposed to oCT) I guess this would be useless, but I’d think a lower case option would be more useful. date +%#pdoes turn date +%p which might give PM or AM into pm or am, respectively. So I guess it’s not a ‘per-character’ case switch but sets the case of all the characters in the string to the opposite case of the majority of the characters? Also date +%P gives pm or am, but neither date +%^P nor date +%#P change its output. My guess for this case is that %P is just an alias for %#p, and it seems that whenever you add more than one flag, the behavior is undefined/unpredictable ( e.g., date +%0- e gives the same as date +%-e: 3 and date +%-0e gives the same as date +%0e: 03, which makes you think that only the flag next to the letter works or that it goes left to right, but both date +%#^p and date +%^#p give pm or am, [depending on the time of course] ) unless there’s some hidden order of operations? Sorry for digressing…
Also, if you run the command locale -k LC_TIME | grep ^d_fmt, you can see the combo for the specific locale of your system (e.g., d_fmt="%m/%d/%Y").
And you can make your own combo. For example,
date +%^b\ %-e\ %Y -r filewill give youOCT 3 2019.
Als het bestand op een andere webserver staat, vind ik httpie docs ) leuk.
Installatie
pip install httpie --user
Gebruik
Het -h-commando geeft alleen de header. Het patroon is
http -h [url] | grep 'Last-Modified\|Date'
Voorbeeld:
$ http -h https://martin-thoma.com/author/martin-thoma/ | grep 'Last-Modified\|Date'
Date: Fri, 06 Jan 2017 10:06:43 GMT
Last-Modified: Fri, 06 Jan 2017 07:42:34 GMT
De Date is belangrijk omdat dit de servertijd rapporteert, niet uw lokale tijd. Ook stuurt niet elke server Last-Modified (b.v. superuser lijkt het niet te doen).
1) Bestandenlijst met laatst gewijzigde datum/tijd
Om bestanden op te sommen en de laatst gewijzigde bestanden bovenaan te tonen, gebruiken we
-lt-opties met het commandols.$ ls -lt /run output total 24 -rw-rw-r--. 1 root utmp 2304 Sep 8 14:58 utmp -rw-r--r--. 1 root root 4 Sep 8 12:41 dhclient-eth0.pid drwxr-xr-x. 4 root root 100 Sep 8 03:31 lock drwxr-xr-x. 3 root root 60 Sep 7 23:11 user drwxr-xr-x. 7 root root 160 Aug 26 14:59 udev drwxr-xr-x. 2 root root 60 Aug 21 13:18 tunedhttps://linoxide.com/linux-how-to/how-sort-files-date-using-ls-command-linux/