I use AIX via telnet here at work, and I'd like to know how to find files in a specific folder between a date range. For example: I want to find all files in folder X that were created between 01-Aug-13 and 31-Aug-13.
Observations:
- The
touch
trick (where you create two empty files to use the -newer option) does not work for me, once the user roles that I have on the server does not allow me to create files. - I need to find between specific dates, not days (like: files that were created more than 30 days ago, etc...)
Explanation: Use unix command
find
with-ctime
(creation time) flagThe find utility recursively descends the directory tree for each path listed, evaluating an expression (composed of the 'primaries' and 'operands') in terms of each file in the tree.
Solution: According to documenation
Formula:
find <path> -ctime +[number][timeMeasurement] -ctime -[number][timeMeasurment]
Examples:
1.Find everything that were created after 1 week ago ago and before 2 weeks ago
find / -ctime +1w -ctime -2w
2.Find all javascript files (
.js
) in current directory that were created between 1 day ago to 3 days agofind . -name "*\.js" -type f -ctime +1d -ctime -3d
Script oldfiles
I've tried to answer this question in a more complete way, and I ended up creating a complete script with options to help you understand the
find
command.The script
oldfiles
is in this repositoryTo "create" a new find command you run it with the option
-n
(dry-run), and it will print to you the correctfind
command you need to use.Of course, if you omit the
-n
it will just run, no need to retype thefind
command.Usage:
$ oldfiles [-v...] ([-h|-V|-n] | {[(-a|-u) | (-m|-t) | -c] (-i | -d | -o| -y | -g) N (-\> | -\< | -\=) [-p "pat"]})
Example:
$ oldfiles -a -i 10 -p"*.c" -\> -nvvv Starting oldfiles script, by beco, version 20170706.202054... $ oldfiles -vvv -a -i 10 -p "*.c" -\> -n Looking for "*.c" files with (a)ccess time newer than 10 minute(s) find . -name "*.c" -type f -amin -10 -exec ls -ltu --time-style=long-iso {} + Dry-run
$ oldfiles -m -o 1 -p"*.h" -\< -nvv Starting oldfiles script, by beco, version 20170706.202054... $ oldfiles -vv -m -o 1 -p "*.h" -\< -n find . -name "*.h" -type f -mtime +30 -exec ls -lt --time-style=long-iso {} + Dry-run
$ oldfiles -mng "2016-12-01" -\= find . -name "*" -type f -newermt "2016-11-30 23:59:59" ! -newermt "2016-12-01 23:59:59" -exec ls -lt --time-style=long-iso {} +
Of course, removing the
-n
the program will run thefind
command itself and save you the trouble.I hope this helps everyone finally learn this
{a,c,t}{time,min}
options.the LS output:
You will also notice that the "ls" option
ls OPT
changes to match the type of time you choose.Link for clone/download of the
oldfiles
script:https://github.com/drbeco/oldfiles
Some good solutions on here. Wanted to share mine as well as it is short and simple.
I'm using find (GNU findutils) 4.5.11
You can use the below to find what you need.
Find files older than a specific date/time:
Or you can find files between two dates. First date more recent, last date, older. You can go down to the second, and you don't have to use mtime. You can use whatever you need.
Use
stat
to get the creation time. You can compare the time in the formatYYYY-MM-DD HH:MM:SS
lexicographically.This work on Linux with modification time, creation time is not supported. On AIX, the
-c
option might not be supported, but you should be able to get the information anyway, usinggrep
if nothing else works.Try this:
find /var/tmp -mtime +2 -a -mtime -8 -ls
to find files older than 2 days but not older than 8 days.