In OS X, I like my date to be in the format YYYY-MM-DD HH:MM in the output for the file.
So, to indicate the file, I would use:
stat -f "%Sm" -t "%Y-%m-%d %H:%M" [filename]
If I want to run it in a series of files, I can do something like this:
#!/usr/bin/env bash for i in /var/log/*.out; do stat -f "%Sm" -t "%Y-%m-%d %H:%M" "$i" done
This example will display the last time I ran the sudo periodic daily weekly monthly command when it refers to log files.
To add file names for each date, I would run the following instead:
#!/usr/bin/env bash for i in /var/log/*.out; do stat -f "%Sm" -t "%Y-%m-%d %H:%M" "$i" echo "$i" done
The output would be as follows:
2016-40-01 16:40 /var/log/daily.out 2016-40-01 16:40 /var/log/monthly.out 2016-40-01 16:40 /var/log/weekly.out
Unfortunately, I'm not sure how to prevent line breaks and keep the file name added to the end of the date without adding extra lines to the script.
PS - I am using #!/usr/bin/env bash since I am a Python user during the day and have different versions of bash installed on my system, not #!/bin/bash
Danijel-James W May 01 '16 at 7:21 a.m. 2016-05-01 07:21
source share