Date Stamp on new file

Dear Gurus,

I'm trying to move a number of files from one directory to another directory with a new date stamp. This is my script:

#! /bin/csh

Today_Date=`date +%Y%M%D`
mv /usr/TRS/data/TS* /usr/TRS/backup/TS*.${Today_Date}

when i run the script i'm getting the following errors:

mv: /usr/TRS/backup/TS*.20062309/08/06 not found

Any advise?

Thanks :slight_smile:

wee

what is the date format that u want exactly ?

date +%Y%M%D

%M - minute format

is of the format

YYYYMMMM/DD/YY

YYYYMMDD
try this,

date +%Y%m%d

hi thanks for the help. i get the date though (see below), but getting another error message:

mv: /usr/TRS/backup/TS*.20060908 not found

any advise? thanks again.

wee :slight_smile:

i think the destination should not have a '*' ... it should be a valid directory, or a filename.

thanks. somehow it solved my problem. this is how my script looks like:

#! /bin/sh

Today_Date=`date +%Y%m%d`

mkdir /usr/TRS/backup/${Today_Date}

mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date}

so now i will create today's date as a directory and put all the files in.

the question is how do i remove those directory when they are more than 10 days old? thanks again. :slight_smile:

you can use the find command with -mtime switch. Please do "man find" and see how it is used or you can search the forum

This is my final script. Do u think it will work? :confused: Thanks. :slight_smile:

#! /bin/sh

Today_Date=`date +%Y%m%d`

mkdir /usr/TRS/backup/${Today_Date}

mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date}

find /usr/TRS/backup/. -name 'T*' -mtime +1 -exec rm -f {} \;

you can try it out by running the script..
if you want to make sure, then use the shell prompt and do it step by step and you can also list the files found first, before using the actual command

listing the files more than 10 days..
find /usr/TRS/backup/. -name 'T*' -mtime +10 -ls

i thought you want to delete directories more than 10 days?
find /usr/TRS/backup/. -name 'T*' -type d -mtime +10 -ls

Then once you are sure those files listed are the ones to delete, use the actual command , eg
find /usr/TRS/backup/. -name 'T*' -type d -mtime +10 -exec .....

ghostdog74
many thanks to u. will try it out n let u knw the results. cheers! :slight_smile:

no prob.have fun.

hi ghostdog,

tried but it seems my command is not working: :eek:

find /usr/TRS/backup/. -name 'GW*' -type d -mtime +10 -exec rm -f {} \; >> abc.log

even try to run it manually but not working at all. anything wrong with it? :confused:

thanks

wee

what error you encountered? at least post the error messages you have and what unexpected behaviour you seen...

hi ghostdog

there are no error messages. just that when i run the command nothing has take place.

i run this command

% find /usr/TRS/backup/. -name 'GW*' -type d -mtime +1 -exec rm -rf {} \;

and the following directory (in bold) should be remove but it's still there. :frowning:

% ls -ltr
total 4
drwxrwxrwx 2 hulft hulft 512 Oct 2 23:02 20061002
drwxr-xr-x 2 hulft hulft 512 Oct 3 23:02 20061003

let me know if u need additional information.

thanks :slight_smile:

the -name "GW*" -type d : means find directories with name starting
with GW. your directories are not starting with GW.

ohh my...thanks for pointing out....i missed out the -d...thanks thanks! :slight_smile: