adding a date to the last of each file name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting adding a date to the last of each file name
# 1  
Old 04-01-2010
Data adding a date to the last of each file name

i have some files in my directory....wit names say aaa, bbb, ccc,,,,,
i want to make loop so that for each file name,,,,,,a sysdate should be appended in the end.........and the files should look like aaa_20100331

i knw date can be appended as `date +"%Y%m%d"`
but m nt able to make a loop. kindly help me

thanks in advance
# 2  
Old 04-01-2010
Code:
day=`date +"%Y%m%d"`
for files in `ls`
do
mv ${files} ${files}_${day}
done

you can change the `ls` part to show only the files you need
# 3  
Old 04-01-2010
thanx dat is working perfectly
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding an extra date column in UNIX file

Hi All, I have a file with only one column of data (without delimiter). For Ex: cat temp.txt 22055 21088 93840 30990 50990 50950 I want to insert an additional column with current date as value. So, i have used below command but didn't get the result as excepted. Could onyone over... (5 Replies)
Discussion started by: Suresh
5 Replies

2. 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

3. Shell Programming and Scripting

Adding Leading Zeros for date in a file

Hello, I have a pipe separated file with two major lines. One is header and another is detail line. Header starts with H and Detail start with D. Sample Content: H|123456|Joes Watson|UK|4/5/2016|12/5/2016|3456|HC|NW|||||| D|123456|Joes... (13 Replies)
Discussion started by: Mannu2525
13 Replies

4. UNIX for Dummies Questions & Answers

Move Multiple Files adding date timestamp before file type

There are files in a directory and I have to move multiple files adding datetimestamp before the file type. /Data/ abc.csv def.csv ghi.csv I have to move this files to archive directory adding datatimestamp before .csv /archive/ abc_YYYYMMDDHHMMSS.csv def_YYYYMMDDHHMMSS.csv... (7 Replies)
Discussion started by: eskay
7 Replies

5. Shell Programming and Scripting

Adding date to file

I want this: 0.0230769,0.407692,0.307692,0,0.1,1.4,1,0,ADD DATE HERE, im getting this: 11/02/12 0.00192308,0.0269231,0.0192308,0,0.1,1.4,1,0, my script: #!/bin/ksh DIR=/export/home/yani_m/scripts/scrip_out_put/ DIR2=/export/home/yani_m/scripts/scrip_out_put/calc/ Date=$1... (1 Reply)
Discussion started by: LucyYani
1 Replies

6. UNIX for Dummies Questions & Answers

Adding hours and minutes to current date (Only to date not to time)

Hi, I want to add some hours and minutes to the current date. For example, if the current date is "July 16, 2012 15:20", i want to add 5 hours 30 minutes to "July 16, 2012 00:00" not to "July 16, 2012 15:20". Please help. Thanks! (4 Replies)
Discussion started by: manojgarg
4 Replies

7. Shell Programming and Scripting

Adding date and time to file name

Hi All, i wanted to add date and time to the file names in the same directory so lets say a file in the directory is test.txt then after running the shell script it should be test-15-11-2010.txt. So I used the following script which works, #!/bin/bash thetime=`date +%Y-%m-%d--%H:%M:%S`... (7 Replies)
Discussion started by: cc_at_work
7 Replies

8. UNIX for Dummies Questions & Answers

adding date to a file during FTP

I have a very basic question here. I have to FTP a file from a AIX unix box to a windows server. But during that I have to rename the file. For example: I have to FTP a file called ORDER.TXT from unix and it should go as ORDER_20090101.TXT on to the windows server. It is not possible to... (5 Replies)
Discussion started by: vara32
5 Replies

9. UNIX for Dummies Questions & Answers

Adding date and time to a log file

Morning all Im hoping you can help me. We have a nice new oracle server :( and are needing to move some files around for EDI and BACS. The server runs windows but has an app called MKS toolkit installed which give unix commands. (Needed for the oracle stuff) I have had a go using dos commands... (2 Replies)
Discussion started by: ltodd2
2 Replies

10. Shell Programming and Scripting

Grabing Date from filename and adding to the end of each line in the file.

Hi, I have 24 .dat files something like below. The file name starts with “abc” followed by two digit month and two digit year. Is there a way to grab the month and year from each filename and append it to the end of each line. Once this is done I want to combine all the files into file... (1 Reply)
Discussion started by: rkumar28
1 Replies
Login or Register to Ask a Question