Source From Here
Question
Sometimes, I reboot the machine and I want to list the latest file(s) being modified before reboot under specific directory. How to achieve this?
How-To
To achieve this purpose, you need to combine commands find/sort/cut/head. e.g.:
Question
Sometimes, I reboot the machine and I want to list the latest file(s) being modified before reboot under specific directory. How to achieve this?
How-To
To achieve this purpose, you need to combine commands find/sort/cut/head. e.g.:
# find ./ -type f // Locate all files recursively under current directory
./a/2017-06-08_13-39-41
./a/2017-06-08_13-40-23
./b/2017-06-08_13-39-56
./b/2017-06-08_13-40-26
./c/2017-06-08_13-40-05
./c/2017-06-08_13-40-20
// Format of stat command:
// %Y: time of last modification, seconds since Epoch
// %y: time of last modification, human-readable
// %n: file name
# find ./ -type f -print0 | xargs -0 stat --format '%Y :%y %n' // Bring in modification time information
1496900381 :2017-06-08 13:39:41.837791854 +0800 ./a/2017-06-08_13-39-41
1496900423 :2017-06-08 13:40:23.508391763 +0800 ./a/2017-06-08_13-40-23
1496900396 :2017-06-08 13:39:56.461353308 +0800 ./b/2017-06-08_13-39-56
1496900426 :2017-06-08 13:40:26.210495508 +0800 ./b/2017-06-08_13-40-26
1496900405 :2017-06-08 13:40:05.874714732 +0800 ./c/2017-06-08_13-40-05
1496900420 :2017-06-08 13:40:20.233266018 +0800 ./c/2017-06-08_13-40-20
// Argument of command sort:
// -n, --numeric-sort: compare according to string numerical value
// -r, --reverse: reverse the result of comparisons
# find ./ -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr // Sorting the result
1496900426 :2017-06-08 13:40:26.210495508 +0800 ./b/2017-06-08_13-40-26
1496900423 :2017-06-08 13:40:23.508391763 +0800 ./a/2017-06-08_13-40-23
1496900420 :2017-06-08 13:40:20.233266018 +0800 ./c/2017-06-08_13-40-20
1496900405 :2017-06-08 13:40:05.874714732 +0800 ./c/2017-06-08_13-40-05
1496900396 :2017-06-08 13:39:56.461353308 +0800 ./b/2017-06-08_13-39-56
1496900381 :2017-06-08 13:39:41.837791854 +0800 ./a/2017-06-08_13-39-41
# find ./ -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- // Use command cut to remove the first segment
2017-06-08 13:40:26.210495508 +0800 ./b/2017-06-08_13-40-26
2017-06-08 13:40:23.508391763 +0800 ./a/2017-06-08_13-40-23
2017-06-08 13:40:20.233266018 +0800 ./c/2017-06-08_13-40-20
2017-06-08 13:40:05.874714732 +0800 ./c/2017-06-08_13-40-05
2017-06-08 13:39:56.461353308 +0800 ./b/2017-06-08_13-39-56
2017-06-08 13:39:41.837791854 +0800 ./a/2017-06-08_13-39-41
# find ./ -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head -n 1 // Finally, use command head to show first line
2017-06-08 13:40:26.210495508 +0800 ./b/2017-06-08_13-40-26
沒有留言:
張貼留言