How to find files created today in a particular directory?

Dear All,

I want a Hp Ux command to find out the files created today in a particular directory or mountpoint.

Kindly help.

Thanks
Bhaskar

$ find dir_name -mtime 0
1 Like

It is displaying the todays files and also previous days files. Below is the proof--

************************************************************
$ pwd
/log/hira
$ find /log/hira -mtime 0
/log/hira
/log/hira/testhira
/log/hira/dba_scripts/awrreports/aces
/log/hira/dba_scripts/tmp
/log/hira/dba_scripts/awrrpt_dump24Hrs_rpt.sql
/log/hira/security
/log/hira/security/test.sh
/log/hira/security/tmp.exe
/log/hira/security/t_part1.txt
/log/hira/security/t_part2.txt
/log/hira/security/t_all.txt
/log/hira/security/pexcap02data.txt
/log/hira/security/pexcap01data.txt
/log/hira/security/commrt.sql
/log/hira/security/commr.txt
/log/hira/security/all_commr.txt
/log/hira/security/all_mastr.txt
/log/hira/security/all_nodes.txt
/log/hira/security/finalout.txt
/log/hira/security/out_comm.txt
/log/hira/security/t_all_nodes.txt
/log/hira/security/t_all_commr.txt
/log/hira/security/hira_1.sh
/log/hira/security/junk_hira_1.sh
/log/hira/junsk
/log/hira/junsk/abc.sh
$ ls -ld /log/hira/testhira
-rw-r--r-- 1 143 sisips 0 Jun 28 14:03 /log/hira/testhira
$ ls -ltr /log/hira/security/all_commr.txt
-rw-r--r-- 1 sisips sisips 1439573 Jun 27 15:54 /log/hira/security/all_commr.txt
$ ls -ltr /log/hira/junsk/abc.sh
-rw-r--r-- 1 oracle dba 26 Jun 28 14:38 /log/hira/junsk/abc.sh
$
****************************************************************

Waiting for your reply

find /log/hira -mmin -1440

It is not working. Below is the response
***************************************
$ pwd
/log/hira
$ find /log/hira -mmin -1440
find: bad option -mmin
$


-mtime 0 will pick latest 24 hrs modified files .. Thats y it picks yours yesterday dates files too ..

Then try with the below ..

$ find dir_path -mtime 0 -type f -exec ls -ltr {} \; | grep "$(date +%d|sed 's,^0,,g') ..:.."
1 Like

Dear All,

I want a Hp Ux command to find out the files created today in a particular directory or mountpoint.

Kindly help.

Thanks
Bhaskar

One way: Create a reference file dated at the start of the day and find all files newer than that file:
This script is designed to take a directory name as a parameter and contains code to clean up after itself.

DIR="$1"
if [ "${DIR}""X" = "X" ]
then
        DIR=`pwd`
fi
YYYYMMDD="`date +%Y%m%d`"       # Reversed date yyyymmdd
REFERENCE=/var/tmp/reference.${YYYYMMDD}.$$
touch -t ${YYYYMMDD}0000 ${REFERENCE}
#
MYEXIT ()
{
if [ -f "${REFERENCE}" ]
then
        rm "${REFERENCE}"
fi
#
exit
}
#
trap 'MYEXIT' 1 2 3 15
#
(
find "${DIR}" -type f -newer "${REFERENCE}" -exec ls -lad {} \;
) 2>&1 | pg
#
MYEXIT
1 Like

Thanks a lot jayan_jay. It is very much working.

Hi Jayan,

Can you pls explain what exactly logic you have taken specially grep one?

find dir_path -mtime 0 -type f -exec ls -ltr {} \; | grep "$(date +%d|sed 's,^0,,g') ..:.."

Thanks
Krsnadasa

Further to @jayan_jay, it would be better to match on the Month and Day, though I think I now see what your RE is doing. In most versions of date , the day field is available in various formats - including with a leading space character for single digit days:

TODAY="`date '+%b %e'`"        # Mmm dD
find dir_path -type f -mtime 0 -exec ls -lad {} \; | grep "${TODAY}"

My earlier post with find -newer is the most efficient.