Reputation: 639
I want to get all files after a specific date. I tried with:
ls -ltr | awk {'print $6'} | sed s/-//g | awk {'if ($1-20110415 > 0 ) {print $1}'}
which works 50% fine. The last command prints only date of file. How to print date of file and filename? In the awk $8
is the filename, but I don't know how to transfer till last print
in the command line.
Thank you, Luke
Upvotes: 14
Views: 18722
Reputation: 724
I ran an experiment on my web server looking for files newer than a certain time.
$ find . -name "*.html" -newermt 2023-09-13T01:47 -ls | wc -l
1214
$ find . -name "*.html" -newermt 2023-09-13T01:47:30 -ls | wc -l
1177
$ find . -name "*.html" -newermt 2023-09-13T01:47:40 -ls | wc -l
1087
$ find . -name "*.html" -newermt 2023-09-13T01:47:50 -ls | wc -l
1016
$ find . -name "*.html" -newermt 2023-09-13T01:48 -ls | wc -l
929
$ find . -name "*.html" -newermt 2023-09-13T01:49 -ls | wc -l
665
$ find . -name "*.html" -newermt 2023-09-13T01:49:10 -ls | wc -l
665
$ find . -name "*.html" -newermt 2023-09-13T01:49:12 -ls | wc -l
665
$ find . -name "*.html" -newermt 2023-09-13T01:49:20 -ls | wc -l
634
$ find . -name "*.html" -newermt 2023-09-13T01:49:21 -ls | wc -l
624
$ find . -name "*.html" -newermt 2023-09-13T01:49:21.5 -ls | wc -l
616
$ find . -name "*.html" -newermt 2023-09-13T01:49:21.6 -ls | wc -l
616
$ find . -name "*.html" -newermt 2023-09-13T01:49:21.8 -ls | wc -l
612
$ find . -name "*.html" -newermt 2023-09-13T01:49:21.9 -ls | wc -l
611
$ find . -name "*.html" -newermt 2023-09-13T01:49:22 -ls | wc -l
610
$ find . -name "*.html" -newermt "13-Sep-2023 1:49" | wc -l
665
$ find . -name "*.html" -newermt "13-sep-2023 1:49:21" | wc -l
624
$ find . -name "*.html" -newermt "13-sep-2023 1:49:21.6" | wc -l
616
$ find . -name "*.html" -newermt "13-sep-2023 1:49:21.7" | wc -l
614
$ find . -name "*.html" -newermt "13-sep-2023 1:49:21.75" | wc -l
613
$ find . -name "*.html" -newermt "13-sep-23 1:49:21.75" | wc -l
613
$ find . -name "*.html" -newermt "09/13/23 1:49:21.75" | wc -l
613
$ find . -name "*.html" -newermt "09/13/2023 1:49:21.75" | wc -l
613
$ find . -name "*.html" -newermt "13/09/2023 1:49:21.75" | wc -l
find: I cannot figure out how to interpret ‘13/09/2023 1:49:21.75’ as a date or time
There might be other formats for time.
Upvotes: 0
Reputation: 87
ls -ltr --time-style=long-iso <path> | awk '$6 >= "2018-10-10" {print $6,$8}'
This gives me all files on the specified path that have been modified on 2018-10-10
or later.
--time-style=long-iso
is a good way of making sure the time includes the year, month and date. This helped me exclude old files if you keep multi year files.
Upvotes: 2
Reputation: 6877
If you are looking for a way to find updated files and process them, you could touch
a file after your process ends and use find's -newer
:
-newer file
File was modified more recently than file.
So when you need an updated files list, you'd want to do this:
find /path/to/dir -newer touched.file
This would recursively list all files in /path/to/dir that have a modification date that is later than that of touched.file. Don't forget to touch that touched.file again when you finish processing the updated files or make note of which file to test on your next iteration.
Upvotes: 4
Reputation: 784918
Try find command like this:
find /my/path -mtime -1 # to get files modified in last 1 day
find /my/path -mtime -1.5 # to get files modified in last 1.5 day
Upvotes: 25
Reputation: 29953
How about using find with one of its various time-based switches, then using the printf to specify what fields you wish to display? You can find all the options in the man pages.
EDIT - I'm not on a suitable environment to give you an example right now - I'll try to update the answer tomorrow
Upvotes: 0
Reputation: 1525
What about this slightly modified version ?
ls -ltr | awk {'print $6 " " $8 '} | sed s/-//g | awk {'if ($1-20110426 > 0 ) {print $1 " " $2}'}
Seems to do the trick for me... ?
Upvotes: 0