0

I've got the following command which should recursively go down folders and get the last modified date - which is perfect. However, sometimes it brings back more than one result for some reason. How can i just bring back the top one (the last modified file)

The command is:

find $1 -type f -exec stat --format '%Y :%y %n' "{}" \; | sort -nr | cut -d: -f2-  | head

The output is

2015-08-17 21:52:00.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-17 21:50:43.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-17 21:44:36.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-17 18:19:04.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-17 18:15:37.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-15 21:22:23.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-15 18:37:51.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-14 18:07:07.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-14 17:55:53.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-14 17:46:33.000000000 +0200 ./path/to/files/that/are/redacted.pdf
1
  • You just need to pipe the output to head -n 1 Aug 17, 2015 at 22:18

1 Answer 1

0

add -n 1 to the end of your command

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.