need to create a file with its name having system date

Hi,

Iam new to unix . I need to write a scritp which can create a file having sysdate as a part of it.and i also need to delete file which is created five days before in a directory.pls Help me out

thanks in advance

this will help you to create a filename that contains system date:

touch  my_file`date +%d-%m-%Y`contains_date

Thanks for the info.but how can i delete files in a directory that are created 5 days back.....

/usr/bin/find "Directory Path" -type f -mtime +5 -exec /bin/rm -f {};

Ex: /usr/bin/find /home/justsam -type f -mtime +5 -exec /bin/rm -f {};

Note: The above deletes only the files (mentioned by the type switch) in the directory /home/justsam wich are older than 5 days (mentioned by -mtime). If you want to delete files older than 3 days, make it -mtime +3

Thanks i want to delete a file based on the created time not modified.Will the above command works for this.

For ex if i modify a file which was created five days earlier will it also gets deleted

the mtime option of find command lets you select files based on their time of modification.

the atime option of find command lets you select files based on their time of access.

as far as i know, find command does not give you any option to select files based on time of creation.

do man find to know more.

Hello,

Just an addition to the question , can u pls tell if i want to find files created in last 20 mins then which find option should be used as i was not able to detect in man find.

KRgs,
Aparna

Following code crates a file with systemdate followed by filename

SYSDATE=`date +%d"-"%m"-"%y":"%H%M`
touch filename$SYSDATE

this code deletes the file which are older then 5 days

MYDIR=/home/sri/yourdir #give your desired directory
cd $MYDIR
find . -type f -name "*.*" -mtime +5 -exec rm {} \;

go thourgh this...if any assistant pls let me know...

Hi All,

My question is involved in this same question :

errdate=$(date +%m/%d-%H:%M:%S)
echo $errdate

I get the date in the numeric....
my requirement is i want to get Month as month name.

For this i tried by the following way :

errdate=$(date +%b %d %H:%M:%S)
echo $errdate

i was getting the output as 'Oct', nothing else.

but i want Oct 18 07:49:57 as output, plz help me.

Regards,
Ravi.

Hi
Use this:

errdate=$(date +%b" "%d" "%H:%M:%S) 
echo $errdate

Thanks Indalecio :slight_smile:
I got my wanted solution.

Try:

errdate=$(date +%b" "%d" "%H:%M:%S)