Hi I want a list of files modified within 60 minutes.
bash-3.2$ find . -mmin 60 -type f
find: bad option -mmin
find: [-H | -L] path-list predicate-list
bash-3.2$ /usr/xpg4/bin/find . -mmin 60 -type f
/usr/xpg4/bin/find: bad option -mmin
/usr/xpg4/bin/find: [-H | -L] path-list predicate-list
bash-3.2$
utibbwdev1#uname -a
SunOS utibbwdev1 5.10 Generic_150400-13 sun4v sparc SUNW,T5240
I am getting the above error. My OS is sun version 5.10.
You can do that using this command.
$ find . -mtime -1
where,
.
is the search path
-mtime
time parameter
-1
list files modified in last 1 hours
also
$ find . -amin -60
-amin
time parameter (minute wise)
-60
list files modified in last 1 hours
Here is an output from my system:
Find command can do that.
find . -newermt "1 hour ago"
You can further filter it with -type f
As you are on SunOS, probably you are not using GNU find, so -mmin
option is not allowed. Try
find -mtime -1
to get files/dirs of modification time under (that's the meaning of the minus sign in front of the number) 1 hour from now. GNU finds makes it possible to ask for times in minutes as an extension to normal find.
Also, the man page is very useful, but perhaps, if you have the GNU findutils package installed on your system, you have to do some PATH
adjustements before to get the correct find program called. Just look as GNU utils normally get installed under /opt/gnu directory and you'll need to put that directory in the PATH before the normal bin dirs. A good way to check this is to do
which find
that will tell you which find it is using and where in the filesystem it is located. A common mistake is to put man pages first in the MANPATH environment variable, but last in the PATH variable, so you get the manpage from GNU findutils package but execute the standard system command. find in SunOS comes from Berkeley Unix and is not related to GNU.
For a POSIX compatible method you can make a temporary file with touch
, using the time from date
, after subtracting one hour with awk
, and use find
's -newer
operand to compare files with the temporary file.
TIME=`date "+%Y %m %d %H %M" | awk '
BEGIN{split("31 28 31 30 31 30 31 31 30 31 30 31",M)}
{
if ($4 == 0) { # hour underflow
if ($3 == 1) { # day underflow
if ($2 == 1) { # month underflow
$1--;
$2 = 12;
} else $2--;
if ($1 % 4 == 0 && $2 == 2) $3 = 29; # leap year
else $3 = M[$2];
} else $3--;
$4 = 23;
} else $4--;
printf "%04u%02u%02u%02u%02u\n", $1, $2, $3, $4, $5;
}'`
touch -t "$TIME" some-temporary-file
find . -type f -newer some-temporary-file
rm some-temporary-file
To get a temporary file name you can use a utility such as mktemp
, you can specify a file, or you can append random numbers to a file name.
Quite a few versions of find
have the -mmin
extension, or something like it.
find . -type f -mmin -60
Some versions of date
have a variable output.
FILE=`mktemp -t one-hour-ago-`
touch -t `date -v -1h +%Y%m%d%H%M` "$FILE"
find . -type f -newer "$FILE"
rm "$FILE"
And some versions of touch
have adjustment flags.
FILE=`mktemp -t one-hour-ago-`
touch "$FILE"
touch -A -010000 "$FILE"
find . -type f -newer "$FILE"
rm "$FILE"