Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find todays files

Status
Not open for further replies.

dvknn

IS-IT--Management
Mar 11, 2003
94
US
I have directory. I have to find the files created ONLY today.

I tried the touch command. But, am lost. Can anybody help me??

Thanks,
 
Hi:

This finds all files in the last 24 hours from the current directory:

find . -type f -mtime 0 -print

Regards,

Ed
 
But, I want the files generated ONLY with today's DATE
 
Well, that's a little more difficult:

# not tested thoroughly
curday=$(date +"%d")
find . -type f -mtime 0 -print|while txtline=$(line); do
[ $curday -eq $(ls -l $txtline|awk ' { print $7 } ') ] && echo $txtline
done
 
In this case, all the file objects that find discovers gets piped to a while loop. 'txtline' (which could be any name) is each object inside the loop. The 7th field of a long listing is the day.

For hopefully obvious reasons, I don't look at the month or year. if the 7th field equals the current day, I echo the object.

 
This is what I use:

touch -t 200304280000 /tmp/time.txt
find / -newer /tmp/time.txt

This will find any files created after midnight of April 28.
 
ls -l | grep -i "Apr 29" will also show files created or modified today only.

Best Regards,
vivek
 
Hi,

I am trying to get the count in a variable. I am unable to do so. Can you please help?

COUNT=`ls -l dirname | grep `date +'%b %e'` | wc -l`
 
you can to use the nested back-ticks like this:

Code:
COUNT=`ls -l | grep "\`date +'%b %e'\`" | wc -l`

or better yet use $(....) as an alternative and the prefered method - they can be nested without having to be escaped:

Code:
COUNT=$(ls -l | grep "$(date +'%b %e')" | wc -l)

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top