Date format

Hi,
I need to conver the date format to binary and then subract it by one which will result me an output with yesterdays date and use it..
So that i will use the out and delete all the folders which are of minus one days.i.e if today is 2010-03-18 (this is a folder format at some xyz location).
Now the script will search for the previous days folder and files in it and simply delete it....
Please help..

Regards,
PAN

date --date='1 day ago' #full date format

execute this command this command itself will give the yesterdays date

date +%d --date='1 day ago'  #only the yesterday's date

And you can have a look at this amazing thread...

http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html

To get the yesterday's date there is a way in date command ,

echo `date "+%d/%m/%Y" -d "-1 day"`

gr8...Thanks...
Now with that yesterdays date, a date folder gets created by some other script..
How to delete that folder and files in it.

Store that date in a variable.
Say

$dir=`date +%d --date='1 day ago'`

Now the variable $dir will have the yesterday's date value. This will be a directory name
means you can delete this directory and files in it using the following command

rm -rf ${dir}

If that directory is in some other path you need to specify the path exactly in the rm command's parameter.

Example:

rm -rf /home/user1/${dir}

but if this dir is at location say /usr/sam/pan/2010-03-17,
how will the script looks like..
I just need to put this is cront in such a way that it will search this folder 2010-03-17 and delete that and files in it..
This will be an on going process as deleting the folder and files manually i a big pain..
Also this folder get created everyday with todays date, so need to automate it and put in cron..

You need to use like

rm -rf /usr/sam/pan/${dir}

As I mentioned in the previous post. Then put this entry in the crontab.
This will delete that directory and files in it

Try this ,

date=`date "+%d-%m-%Y" -d "-1 day"`
find /usr/sam/pan -iname $date -exec rm -rf {} \;

hi,
i created a shell with name call cross.ksh
In that i kept only one line
$dir=`date +%Y-%m-%d --date='1 day ago'`

Now when i execute this shell wit ./cross.ksh
it throws and error saying
./cross.ksh: line 1: =2010-03-17: command not found

Please suggest.

change $dir to dir

dir=`date +%Y-%m-%d --date='1 day ago'`

In line 1

dir=`date +%Y-%m-%d --date='1 day ago'`
rm -rf /home/uat/${$dir}

ERROR - ./cross.ksh: line 5: /home/uat/${$dir}: bad substitution

Change like this.
rm -rf /home/uat/${dir}

dir=`date +%Y-%m-%d --date='1 day ago'`
rm -rf /home/uat/{$dir}

--------
after executing this, the folder 2010-03017 still exists..

date +%Y-%m-%d --date='1 day ago'

Actually the output of the above command will be

  
2010-03-17

So the $dir will contain 2010-03-17.
But your directory name is 2010-03017.

Both are different. so that only it is not removing.
Try to change the directory name format.

oppsss sorry....
typo error - missied hyper above..
both , my directory name is 2010-03-17 and the script are same..
but still 2010-03-17 exist...

Have you checked the permissions for that directory?
And can you tell me... You told that one process is creating these directory and whether that process is owned by you?

yes ofcourse one proces creates this directory...
but as a trial iam creating the carbon copy of this directory at the root i.e/home/uat and then trying your script.

---------- Post updated at 03:21 PM ---------- Previous update was at 03:19 PM ----------

again i tried to change the permissions of the directory chmod 777 2010-03-17 and then again excuted, but still the directory exists there..

---------- Post updated at 03:33 PM ---------- Previous update was at 03:21 PM ----------

when is use the below code -
dir=`date +%Y-%m-%d --date='1 day ago'`
find /home/uat -iname $dir -exec rm -rf {} \;

This Delete the folder 2010-03-17
but throws an
ERROR -
find: /home/uat/2010-03-17: No such file or directory

Because it is trying to find a file in path /home/uat/2010-03-17 under
/home/uat.

so how to proceed..

---------- Post updated at 03:40 PM ---------- Previous update was at 03:38 PM ----------

but it deletes the folder which is my requirement...but with an error as above