Date Stamp on new file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date Stamp on new file
# 8  
Old 09-08-2006
Quote:
Originally Posted by lweegp
This is my final script. Do u think it will work? Smilie Thanks. Smilie

#! /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 .....
# 9  
Old 09-08-2006
Quote:
Originally Posted by ghostdog74
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! Smilie
# 10  
Old 09-08-2006
no prob.have fun.
# 11  
Old 10-03-2006
Quote:
Originally Posted by ghostdog74
no prob.have fun.
hi ghostdog,

tried but it seems my command is not working: Smilie

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? Smilie

thanks

wee
# 12  
Old 10-03-2006
Quote:
Originally Posted by lweegp
hi ghostdog,

tried but it seems my command is not working: Smilie

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? Smilie

thanks

wee
what error you encountered? at least post the error messages you have and what unexpected behaviour you seen...
# 13  
Old 10-04-2006
Quote:
Originally Posted by ghostdog74
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. Smilie

% 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 Smilie

Last edited by lweegp; 10-04-2006 at 12:09 AM..
# 14  
Old 10-04-2006
Quote:
Originally Posted by lweegp
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. Smilie

% 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 Smilie
the -name "GW*" -type d : means find directories with name starting
with GW. your directories are not starting with GW.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Adding Date Stamp To File Name With sed

trying to add a date stamp to the name of a file with sed. can't seem to comment out the date command so that sed does not only see it as a literal text string this is what I'm trying ls file.txt | sed 's/file.txt/file\/`date`\/.txt/g'but it's giving this file/`date`/.txtlooking for something... (1 Reply)
Discussion started by: jimmyf
1 Replies

2. Red Hat

Logrotate to delete file which has date stamp

Hello, can someone please suggest how to create an logrotate for this scenario. Need to delete all log file which are created more than 30 days ago, and all the log file have date stamp on it. I dont want to create a cron job for this task. here is the example -rw-r--r-- 1 tomcat tomcat ... (2 Replies)
Discussion started by: bobby320
2 Replies

3. Shell Programming and Scripting

If(Condition) Rename a file with (Date+Time) Stamp

Hi! Please see our current script: #!/usr/bin/ksh if (egrep "This string is found in the log" /a01/bpm.log) then mailx -s "Error from log" me@email.com, him@email.com </a01/bpm.log fi To the above existing script, we need to add the following change: 1) After finding the string,... (7 Replies)
Discussion started by: atechcorp
7 Replies

4. Shell Programming and Scripting

Set date and time stamp of one file to another

Hi I use "touch -t xxxxxxxx" command to set date/time stamp of a file. My requirement is to read the date/time stamp of a file and apply it to another file. Is there anyway to do it simple instead of manually taking date/stamp of first file? TIA Prvn (2 Replies)
Discussion started by: prvnrk
2 Replies

5. UNIX for Dummies Questions & Answers

ls -ltr for a future date/time stamp file

Hi When i do ls -ltr <file1> then it shows me the date and time of the file if - for whatever reason file has future date/time stamp then ls -ltr is not showing the time, it just shows only date part ... even if time is ahead by 2 hr than current time. suppose a file was copied from INDIA... (3 Replies)
Discussion started by: reldb
3 Replies

6. UNIX for Dummies Questions & Answers

sed a file and maintain date stamp and permissions

I need to alter a file. I'm using sed then passing output to temp file then using touch -r to maintain the date but the permissions do not get preserved How can I sed a file and maintain date and permissions currently it's preserving the date but the permissions revert back to the... (3 Replies)
Discussion started by: andyatit
3 Replies

7. Shell Programming and Scripting

copying a file without changing date stamp.

Hi, I am using the below copy command, to copy the file sbn to sbn1, cp sbn sbn1 but its changing the date stamp of file sbn1, but i dont want to change the date stamp of sbn1. Could you please help me out in this. (3 Replies)
Discussion started by: shivanete
3 Replies

8. UNIX for Dummies Questions & Answers

How to Zip the files from date Stamp to end date Stamp

Hi, I need to zip the list of files using from date Stamp to end date Stamp, How can I filter and make FromDate_EndDate.gzip? any idea? (1 Reply)
Discussion started by: redlotus72
1 Replies

9. Shell Programming and Scripting

creating a new file with date stamp

Hi, can any one tell me how to achieve this...I will input the path and file name and it should rename it to current date and time... this is what I tried... #! /usr/bin/sh set -x cd /info_stg/vul/Scripts TODAY_DATE_TIME=`date +%Y%m%d%H%M%S` IN_FILE_PATH=`cat file.txt | awk -F, '{... (2 Replies)
Discussion started by: mgirinath
2 Replies

10. UNIX for Dummies Questions & Answers

File date and time stamp

I have to capture the creation date and time stamp for a file. The ls command doesn't list all the required information. I need year, month, day, hour, minute and second. Any ideas... (1 Reply)
Discussion started by: Xenon
1 Replies
Login or Register to Ask a Question