Hi,
How can we search for a file with current date(sysdate).
Actually i want the file name from a directory which was created today(current date).
For example i have a dir /home/arch and i have files with name aglito03axyz.datetimestamp in this directory, but all these files were created on different dates. suppose we have 3 files :
dba May 18 00:06 aglito03axyz.20090518000506.arc
dba May 19 00:07 aglito03axyz.20090519000511.arc
dba May 20 00:07 aglito03axyz.20090520000506.arc
from the above we have 3 files with name aglito03axyz.datetimestamp and were created on different days, suppose i want the file created today(May 20th 2009) then i should get the file name as aglito03axyz.20090520000506.arc.
How can this be achieved.
Thanks
Sandeep
I think Padow meant "find /home/arch -mtime 0" , though I don't think this will give you what you require either because it will still include files created yesterday.
Maybe try generating today's date and using it to match filenames:
cd /home/arch
YYYYMMDD="`date +%Y%m%d`"
ls -1 aglito03axyz.${YYYYMMDD}??????.arc 2>/dev/null | while read FILENAME
do
echo "${FILENAME}"
done
methyl,
padow code works perfectly in my case.
If i use "find /home/arch -mtime 1" i am getting the file created today(May20th) and if i use "find /home/arch -mtime 0" i do not get any results.
But if we see the syntax of "find" command, if we use "-mtime 0" then it should give the files created today. I dont know why "0" is not working here.
The -mtime parameter to "find" is in multiples of 24 hours. The results will depend on what time you run the command relative to when the files were last changed. I still think that find is not the right program for this job.
methyl,
You are right -mtime does not always work. The solution you suggested was to search for the file name which contains date.
I do not want to go in that way.
Is there any solution where we can find for a particular file which was created today.( I do not want to go by searching the filename).
Thanks
Another approach. Create a file dated exactly midnight and find files newer than that file.
#!/bin/ksh
cd /home/arch
REF_DATE=/tmp/my_reference_date.$$
YYYYMMDD="`date +%Y%m%d`"
SEARCH='aglito03axyz.??????????????.arc'
touch -t "${YYYYMMDD}0000.00" ${REF_DATE}
find . -type f -name "${SEARCH}" -newer ${REF_DATE} -print | while read FILENAME
do
echo "${FILENAME}"
done
#
rm ${REF_DATE}
It's not particularly efficient, but you could
TODAY=`date +'%b %d'`
find /home/arch -ls | grep "$TODAY"