Shell Scripts - Append a filename with date and time....


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shell Scripts - Append a filename with date and time....
# 1  
Old 05-03-2011
Shell Scripts - Append a filename with date and time....

Hello,

I need to create a shell script that appends a filename to create a name with the date and time appended that is guaranteed to not exist. That is, the script insures you will not overwrite a file with the same name. I am lost with this one. I know I need to use date but after that I am not sure what options to use. Thanks for your help, citizencro

---------- Post updated at 08:53 PM ---------- Previous update was at 08:47 PM ----------

I also need to create a backup script that uses the above to create a backup of my files using the tar command.
# 2  
Old 05-04-2011
man date

Other than that: what have you got so far, where are you stuck? We're not going to give you a complete script just because you ask, you'll have to show some effort.
# 3  
Old 05-04-2011
I have written the code to create a file named backup which can append the date and time with the following code;

FILE="backup_$(date +%b)_$(date +%d)_$(date +%Y)"
echo $FILE

I can't figure out how to make it so it insures not to overwrite a file with the same name.
# 4  
Old 05-04-2011
add second in file name.

Code:
FILE="backup_$(date +%Y%m%d_%H%M%S)"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to extract date and time from filename?

Hi, I'm totally new in sell script and working with a shell code. I want to extract the date and time from the filenames. The filenames are different but all of them begins with WI_ SCOPE_: WI_SCOPE_DATA_CHANGE_2017-09-12_15-30-40.txt WI_SCOPE_BACK_COMPLETE_QUEUE_2017-09-12_15-31-40.txt... (5 Replies)
Discussion started by: Home
5 Replies

2. Shell Programming and Scripting

How to append date to filename, but base it on yesterday's date?

Hello, I'd like to write a monthly archive script that archives some logs. But I'd like to do it based on yesterday's date. In other words, I'd like to schedule the script to run on the 1st day of each month, but have the archive filename include the previous month instead. Here's what I... (5 Replies)
Discussion started by: nbsparks
5 Replies

3. Shell Programming and Scripting

append a filename with system date and time

Hi, There are similar kind of posts, but none seems like working for me. Please correct me if I'm wrong. I need append/rename file abc.txt with file processed date and time like abc_systemdatetimestamp.txt and move it to different folder. for example I have /source/data/abc.txt ... (1 Reply)
Discussion started by: amsn08
1 Replies

4. Shell Programming and Scripting

how to append current date to filename.tgz in perl

i would like to know how to append current date in a filename with .tgz extension. #!/usr/bin/perl my $date = `date + %Y%m%d`; system("sudo mv /tmp/nyucs01_config_backup.tgz /misc/nyucs01_config_backup_$date.tgz"); im getting this error message: sh: line 1: .tgz: command not found (7 Replies)
Discussion started by: linuxgeek
7 Replies

5. UNIX for Dummies Questions & Answers

shell scripts - create a filename with the date appended

I am looking to do something where if I created a file named backup,or whatever it would print a name like “backup_Apr_11_2011”. Thanks citizencro (1 Reply)
Discussion started by: citizencro
1 Replies

6. UNIX for Dummies Questions & Answers

Shell Scripts - shows today’s date and time in a better format than ‘date’ (Uses positional paramete

Hello, I am trying to show today's date and time in a better format than ‘date' (Using positional parameters). I found a command mktime and am wondering if this is the best command to use or will this also show me the time elapse since 1/30/70? Any help would be greatly appreciated, Thanks... (3 Replies)
Discussion started by: citizencro
3 Replies

7. UNIX for Dummies Questions & Answers

Append Previous Days date to filename

I need to append previous days date to my file which is generated using a script. I am working on Solaris 10. Thanks! (2 Replies)
Discussion started by: Twisha
2 Replies

8. UNIX for Dummies Questions & Answers

Append current date to filename

In C Shell programming I haven't successfully been able to append the date in the format mmddyyyy to a filename. I've tried the following: I can print out the date in the correct format: date +%x | sed ‘s/\///g I can create a variable with the filename: set newfile=changedfiles I can... (3 Replies)
Discussion started by: gigigi
3 Replies

9. UNIX for Dummies Questions & Answers

Append date to filename

What is the easiest way to append the date (year, month, day) to a filename? (5 Replies)
Discussion started by: hshapiro
5 Replies

10. Shell Programming and Scripting

Determine date and time the file was created through shell scripts

Can I determine when the particular file was created, in korn-shell. Can please someone help me. If possible please mail the solution to me. my mail id: bharat.surana@gmail.com (1 Reply)
Discussion started by: BharatSurana
1 Replies
Login or Register to Ask a Question