What is the command to list files in a directory of today's date in AIX? The commands from Unix and Linux don't all work in AIX.
Asked
Active
Viewed 699 times
1
-
1What's wrong with `find directory -type f -mtime 0`? – Darkman Jun 30 '21 at 19:28
-
Mind you, file dates are stored as unix timestamp, so the meaning of 'today' depends on your timezone; for example the file might have been created on 2021-07-02 in Australia, while there is 2021-07-01 in my timezone. – Zsigmond Lőrinczy Jul 01 '21 at 03:42
-
@Darkman — See [Explaining the `find -mtime` command](https://stackoverflow.com/q/25599094/15168) for a description of how `-mtime` works (based on POSIX; maybe that should be "how `-mtime` should work"), and therefore you can work out what's wrong with using `find directory -type f -mtime 0`. TL;DR — `-mtime 0` means "in the last 24 hours", not "during the current day measured from midnight local time" (which is what I think the OP wants). – Jonathan Leffler Jul 02 '21 at 14:38
-
@JonathanLeffler - Yes I know that. I just want to know what the OP mean by ***"don't all work in AIX."***. What the OP wants is probably: `find directory -type f -daystart -ctime 0` – Darkman Jul 02 '21 at 14:44
-
Using `-daystart` wouldn't work on macOS unfortunately. And it doesn't work on AIX either. According to the man page for `find` on AIX 7.2, it supports the conditions `-amin`, `-atime`, `-cmin`, `-cpio`, `-ctime`, `-depth`, `-ea`, `-follow`, `-fstype`, `-group`, `-inum`, `-links`, `-iregex`, `-long`, `-ls`, `-mmin`, `-mtime`, `-name`, `-newer`, `-nogroup`, `-nouser`, `-perm`, `-size`, `-regex`, `-regextype`, `-size`, `-type`, `-user`, `-xdev`. Using `-newer` is likely the best option. as shown in this [answer](https://stackoverflow.com/a/68226289/15168). – Jonathan Leffler Jul 02 '21 at 14:53
1 Answers
1
Taking inspiration from a POSIX solution at U&L to a similar problem by Stéphane Chazelas, this will find files (-type f
) under /path/to/directory, recursively, that have a modification time of today's date (starting from midnight):
touch -t "$(date +%Y%m%d0000)" ~/.today &&
find /path/to/directory -type f -newer ~/.today
rm ~/.today
... where you put the ~/.today timestamp file outside of /path/to/directory, of course.
Alternatively, the AIX Toolbox for Linux Applications site has packaged zsh and its dependencies, so you could download and install those, then use the "age" function as a glob qualifier:
zsh
autoload age
print -- /path/to/directory/*(.e:age today:) ## non-recursive
print -- /path/to/directory/**/*(.e:age today:) ## recursive
The .
in the glob qualifier restricts matches to files; the e: ...:
creates an expression that is called for each file to determine inclusion/exclusion.
Hat tip again to Stéphane for demonstrating that age function in this U&L answer.

Jeff Schaller
- 2,352
- 5
- 23
- 38