Add timestamp and copy files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add timestamp and copy files
# 1  
Old 07-11-2012
Add timestamp and copy files

Please help me with a command to find all files in directory and copy them into another with a timestamp. I have
the code to find and copy the files but unable to add timestamp to the files.
Below is the find and copy code which i am using(need to add timestamp)

Code:
find /root/files -name "*.gz" -exec cp {} /root/com \;

# 2  
Old 07-11-2012
Code:
 
find /root/files -name "*.gz" 2>dev/null |while read filename; do cp $filename $filename`date +%Y%m%d_%H%M%S` ; done

# 3  
Old 07-11-2012
It errors with dev/null is not a directory. Not sure if i am doing anything wrong here
# 4  
Old 07-11-2012
i missed the /

Code:
 
find /root/files -name "*.gz" 2>/dev/null |while read filename; do cp $filename /root/com/$filename`date +%Y%m%d_%H%M%S` ; done

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 07-13-2012
Its difficult for me to understand, how your code works? can you explain it?
# 6  
Old 07-13-2012
Quote:
Originally Posted by itkamaraj
i missed the /

Code:
 
find /root/files -name "*.gz" 2>/dev/null |while read filename; do cp $filename /root/com/$filename`date +%Y%m%d_%H%M%S` ; done

This will not work. You'll need to tweak it a bit:

Code:
 
find /root/files -name "*.gz" 2>/dev/null |while read filename; do cp $filename /root/com/${filename##*/}`date +%Y%m%d_%H%M%S` ; done

This User Gave Thanks to elixir_sinari For This Post:
# 7  
Old 07-13-2012
What does this code do,

Code:
find /root/files -name "*.gz" 2>/dev/null

Please explain
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Identifying files with a timestamp greater than a given timestamp

I need to be able to identify files with file timestamps greater than a given timestamp. I am using the following solution, although it appears to compare files at the "seconds" granularity and I need it at the milliseconds. When I tested my solution, it missed files that had timestamps... (3 Replies)
Discussion started by: nkm0brm
3 Replies

2. Shell Programming and Scripting

sort the files based on timestamp and execute sorted files in order

Hi I have a requirement like below I need to sort the files based on the timestamp in the file name and run them in sorted order and then archive all the files which are one day old to temp directory My files looks like this PGABOLTXML1D_201108121235.xml... (1 Reply)
Discussion started by: saidutta123
1 Replies

3. Shell Programming and Scripting

copy files based on creation timestamp

Dear friends.. I have the below listing of files under a directory in unix -rw-r--r-- 1 abc abc 263349631 Jun 1 11:18 CDLD_20110603032055.xml -rw-r--r-- 1 abc abc 267918241 Jun 1 11:21 CDLD_20110603032104.xml -rw-r--r-- 1 abc abc 257672513 Jun 3 10:41... (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

4. Shell Programming and Scripting

Shell Script to Search for a particular String and copy the timestamp to a variable

Hi, We Perfrom Loads to the database through a Perl script which generates a statistics file. I need to read the statistics. the Statistics file looks something like below: Process Beginning - 08-26-2010-23.41.47 DB2 CONNECTION SUCCESSFUL! Ready to process and load file: FILENAME # of... (2 Replies)
Discussion started by: Praveenkulkarni
2 Replies

5. UNIX for Advanced & Expert Users

How to copy a file from remote server and preserve timestamp

Hi How to copy a file from remote server and preserve timestamp. Please not, i have to pass username and password to connect to the remote server in the shell script. Can this be achieved with simple ftp ? are there any options in ftp ? Thanks (4 Replies)
Discussion started by: skumar75
4 Replies

6. Shell Programming and Scripting

copy lines from log files based on timestamp and sysdate

I'm looking for a command or simple script that will read lots of audit log file (*.aud) in log fold every 10 minutes, and will output to one file based on sysdate - 10 minutes. assume the script is run at 11:12:20, and it should grep the line from Wed Jun 17 11:02:43 2009 to end of file. after... (4 Replies)
Discussion started by: percvs88
4 Replies

7. Shell Programming and Scripting

copy lines from log files based on timestamp and sysdate

I am sorry to repost this question. it was not clear, and I had the meeting and didn't response the question on time. I do really need help and appreciate your help very much. I'm looking for a simple shell script that will read lots of audit log file (*.aud) in a log fold every 10 minutes,... (1 Reply)
Discussion started by: percvs88
1 Replies

8. UNIX for Advanced & Expert Users

Copy lines from a log file based on timestamp

how to copy lines from a log file based on timestamp. INFO (RbrProcessFlifoEventSessionEJB.java:processFlight:274) - E_20080521_110754_967: rbrAciInfoObjects listing complete! INFO (RbrPnrProcessEventSessionEJB.java:processFlight:197) - Event Seq: 1647575217; Carrier: UA; Flt#: 0106; Origin:... (1 Reply)
Discussion started by: ranjiadmin
1 Replies

9. HP-UX

to get the timestamp of files from the files and folders in Unix

Hi, I had a directory and many subdirectories and files with in it. Now i want to get the timestamp of files from the files and folders recursively. :( Please help me to generate a script fort he above mentioned requirement! Appreciate for ur qick response Thanks in advance! ... (2 Replies)
Discussion started by: kishan
2 Replies

10. UNIX for Advanced & Expert Users

Retaining timestamp on copy of a file

While copying, how we can retain the same date for new file as it was on the old file. (1 Reply)
Discussion started by: param_it
1 Replies
Login or Register to Ask a Question