I assume you mean a calendar day, starting at midnight.
The format for the date in the touch command is YYYYMMDDHHMI; the date command format string gives you midnight when run any time during the day
cd /log/directory
# be sure to make the new day's directory before all this below
touch -t `date +%Y%m%d0000` dummy
find . -newer dummy -type f |
while read fname
do
mv $fname [new directory name goes here]
done
Many thanks it is working. I need few clarification here , what does touch -t is doing here. scripts looks like can be run any day and it will bring the data for current day. can it be modied according to the need let say once in month if i want to move all the file for yesterday or may be 3 days back one. how can we amend here in this file.
My OS is solaris 64 bit 10, I have many files in a logs directory where we recive 40-50 logs every day. i have last 20 days file present in this directory. I want to move each day file to a particulaar directory whose name is appended with the date of file.
eg
1.txt file date 31-jul-2012
2.txt file date 31-jul-2012
3.txt file date 01-Aug-2012
then create a directory for old files of 31-jul RIO_31-Jul-2012 and move them and like wise for 01-aug files.
I have written a scripts which is running fine for current date but i don't know how t modify it to accomdate old date.
---------- Post updated at 10:55 AM ---------- Previous update was at 10:54 AM ----------
My scripts is as below
NEWDIR=RIO_31-Jul-2012
mkdir /ersdg3/ERS/ERS_INPUT_LOGS/RIO/LOGS/$NEWDIR
cd /var/opt/ers/logs/rio
touch -t `date +%Y%m%d0000` dummy
find . -newer dummy -type f |
while read fname
do
mv $fname /ersdg3/ERS/ERS_INPUT_LOGS/RIO/LOGS/$NEWDIR
done