I needed to display a list of directories sorted by their creation date and I came up with this code snippet that I thought was kind of clever. Is there a more obvious way to do this that I'm missing?
printf "%-20s\t\t\t%-s\n" "DATE" "CASE"
printf "%-20s\t\t\t%-s\n" "----" "----"
find $idir -mindepth 3 -maxdepth 3 -type d -printf "%T@ %Tc\t\t%p\n" \
| sed "s#${idir}/##" \
| sort -h \
| sed "s#^[^ ]* ##"
Sample output
DATE CASE
---- ----
Fri 06 Sep 2013 11:17:41 AM EDT dir1/Baseline/2013_09_06_11_16_10
Fri 06 Sep 2013 01:44:38 PM EDT dir2/Baseline/2013_09_06_13_42_48
Sun 08 Sep 2013 05:02:46 PM EDT dir3/6 Month/2013_09_08_17_02_05
Fri 13 Sep 2013 02:28:30 PM EDT dir4/Baseline/2013_09_13_14_25_09
Details
The above will look exactly 3 directories deep from the directory $idir
. It then prints the creation time of any directories that are found at this depth. I then strip the $idir
portion of the path off of the output (don't need it), sort it, and then chop off the %T@
portion of the output. This was only so that I could more easily sort the output.
Without the trailing sed
the output looks like this:
DATE CASE
---- ----
1378480661.2612650000 Fri 06 Sep 2013 11:17:41 AM EDT dir1/Baseline/2013_09_06_11_16_10
1378489478.3223970000 Fri 06 Sep 2013 01:44:38 PM EDT dir2/Baseline/2013_09_06_13_42_48
1378674166.7427782000 Sun 08 Sep 2013 05:02:46 PM EDT dir3/6 Month/2013_09_08_17_02_05
1379096910.4431689000 Fri 13 Sep 2013 02:28:30 PM EDT dir4/Baseline/2013_09_13_14_25_09
Showing me a cleaner method!
find
doesn't give you access to the create time? Any idea why that is? Seems odd that that would be omitted. – slm Oct 10 '13 at 01:25\n
. Is that really a concern? Until this week I hadn't even realized that\n
was a valid character in a file name. – slm Oct 10 '13 at 01:28stat
syscall, unlike the classic time trilogy (access, modification, inode change) — you need to use the recentxstat
syscall. On OSX,-Btime
and friends work, butfind
has no-printf
option. – Gilles 'SO- stop being evil' Oct 10 '13 at 01:40