search files and copy them to a directory with datestamp attached to it


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers search files and copy them to a directory with datestamp attached to it
# 1  
Old 08-21-2008
search files and copy them to a directory with datestamp attached to it

Hi I need to search the some ftp files created in last 24 hours and copy them to a directory with date stamp attached to it.

Iam using following command to search the files
find $CA_OUT_PATH/*/ftp_out -type f -mtime -1

but now how to copy these files to some other directory one by one
with date stamp attached to each file.

Please reply ...its urgent

thanks in advance
# 2  
Old 08-21-2008
If you just want them datstamped with today's date/time, you can add an -exec parameter to your find command to do this:
Code:
find $CA_OUT_PATH/*/ftp_out -type f -mtime -1 -exec cp -p {} /some/other/directory/{}.`date +%y%m%d.%H%M%S` \;

(Untested, try it someplace safe first)
edit: Ok that didn't work Smilie
Instead, pipe the find output for a while-read loop:
Code:
find $CA_OUT_PATH/*/ftp_out -type f -mtime -1 | while read filename ; do cp -p $filename /some/other/directory/${filename}.`date +%y%m%d.%H%M%S` ; done


Last edited by Smiling Dragon; 08-21-2008 at 09:11 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search and Copy Files

Hi All Need your help, I am looking for a script to search for files with specific extension as .log and then copy the latest one to a different folder. Here is the scenario /dev/abc/xyz/a_2_122920131.log /dev/abc/xyz/a_2_123020131.log /dev/abc/xyz/b_2_12302013.log... (2 Replies)
Discussion started by: jimmun
2 Replies

2. Shell Programming and Scripting

Copy the files in directory and sub folders as it is to another directory.

How to copy files from one directory to another directory with the subfolders copied. If i have folder1/sub1/sub2/* it needs to copy files to folder2/sub1/sub2/*. I do not want to create sub folders in folder2. Can copy command create them automatically? I tried cp -a and cp -R but did... (4 Replies)
Discussion started by: santosh2626
4 Replies

3. Red Hat

Unable to copy files due to many files in directory

I have directory that has some billion file inside , i tried copy some files for specific date but it's always did not respond for long time and did not give any result.. i tried everything with find command and also with xargs.. even this command find . -mtime -2 -print | xargs ls -d did not... (2 Replies)
Discussion started by: before4
2 Replies

4. UNIX for Dummies Questions & Answers

Script to search and copy files

HI everyone, I been to this site before for help and found my answers on other threads now I am posting my own :). I have a list of file names with out extensions on an txt file. I need a way for the script to search on the server for each file name and copy the files over to a new directory.... (12 Replies)
Discussion started by: sergiol
12 Replies

5. Shell Programming and Scripting

Recursive search for files and copy to new directories

So I have extremely limited experience with shell scripting and I was hoping someone could point out a few commands I need to use in order to pull this off with a shell script like BASH or whatnot (this is on OS X). I need to search out for filenames with account numbers in the name itself... (3 Replies)
Discussion started by: flyawaymike
3 Replies

6. UNIX for Dummies Questions & Answers

Copy files into another directory

I have a folder will a lot of documents (pdf, xls, doc etc.) which users have uploaded but only 20% of them are currently linking from my html files. So my goal is to copy only the files which are linked in my html files from my Document directory into another directory. Eg: My documents exist... (5 Replies)
Discussion started by: ankitha
5 Replies

7. UNIX for Dummies Questions & Answers

Comparing two files with datestamp to current date

Hi, I am new to unix and I am stuck on how to compare two .zip file with date stamp in my directory. I need to compare out of the two file which is oldest to current date and unzip it after that done continue to unzip the second zip file. Thanks for your help. (5 Replies)
Discussion started by: lilvi3tboix1
5 Replies

8. Shell Programming and Scripting

shell script to search and copy files

Hello Im new to this forums, I would like some help regarding a script that I need in order to copy some files. Heres the scenario: I need to search several files which have a particular code inside, lets say "test" all of them on different directories. I need to copy all of them on a new... (4 Replies)
Discussion started by: c.watson
4 Replies

9. Shell Programming and Scripting

search files and copy them to a directory with datestamp attacched to it

Hi I need to search the some ftp files created in last 24 hours and copy them to a directory with date stamp attached to it. Iam using following command to search the files find $CA_OUT_PATH/*/ftp_out -type f -mtime -1 but now how to copy these files to some other directory one by one ... (1 Reply)
Discussion started by: sreenusola
1 Replies

10. UNIX for Dummies Questions & Answers

cp files that have a particular datestamp

Hello all I'm trying to copy all files in the current directory with yesterday's date to another directory using a single command . I searched the faqs but all the examples listed out involve only the find command.I tried to do something like but it does'nt seem to work. cp < ls -l |grep... (2 Replies)
Discussion started by: luft
2 Replies
Login or Register to Ask a Question