Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Find and copy .zip file based on today's date Post 303036555 by bakunin on Tuesday 2nd of July 2019 05:41:55 AM
Old 07-02-2019
Quote:
Originally Posted by midhun3108
Code:
#! /usr/bin/sh
find /var/tmp/NewFile/TestM/ -name '*.txt' -mtime 0 | while read FILE
do
        echo "Found file $FILE"
done

OK, this is a good start. The find utility provides a list of filenames fitting the clauses you specifiy. Here is the principle of how it works. I suggest you try the following commands on the commandline to get acquainted:

Code:
find /var/tmp/NewFile/TestM/

will list everything in the directory: files, directories, whatever. As you are interested only in files you can specify:

Code:
find /var/tmp/NewFile/TestM/ -type f

The -type f limits the output to only files, skipping directories and other things. But you are not interested in all files, only the ones with a certain extension: "zip", if i got you right. Therefore:

Code:
find /var/tmp/NewFile/TestM/ -type f -name "*zip"

This will reduce the outcome further to only files (-type f) named "zip" (-name "*zip") at the end. You can use other clauses (as you have done) to further limit the result set.

Right now you pipe this list into a while-loop and process it there. In the version you showed us only an echo-statement is inside the loop and therefore the filename is simply displayed, nothing else. You could now put other commands into the loop to process the files in the way you want, i.e.:

Code:
#! /usr/bin/sh
find /var/tmp/NewFile/TestM/ -name '*zip' -mtime 0 | while read FILE
do
        echo "Found file $FILE"
        cp "$FILE" /some/where/else
done

but there is a much better and more elegant approach: find can itself process the files found using the -exec clause: the filename found is represented by "{}" and you need to terminate the "commandline" by "\;". Therefore:

Code:
find /var/tmp/NewFile/TestM/ -name '*zip' -mtime 0 -exec cp {} /some/where/else \;

I suggest you consult the man pages about find about the exact terms and limitations of this procedure.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to copy log files with today's date

I am a newbie to scripting. I need a korn shell script to copy log files of current day to archive folder and rename with current days date stamp. I would really appreciate your help. File structure is as follows. Everyday files get overwritten, so I need copy to a archive directory and... (3 Replies)
Discussion started by: mdncan
3 Replies

2. Shell Programming and Scripting

Identify log files based on time stamp,zip and then copy..HELP

Hi All, PFB is a requirement. I am new to shell scripting. So plz help. It would be highly appreciated. 1. choose all the log files based on a particular date (files location is '/test/domain')--i.e,we should choose all the files that are modified on 29th November, neither 28th nor 30th 2.... (3 Replies)
Discussion started by: skdas_niladri
3 Replies

3. Shell Programming and Scripting

Find and copy files based on todays date and search for a particular string

Hi All, I am new to shell srcipting. Problem : I need to write a script which copy the log files from /prod/logs directory based on todays date like (Jul 17) and place it to /home/hzjnr0 directory and then search the copied logfiles for the string "@ending successfully on Thu Jul 17". If... (2 Replies)
Discussion started by: mail.chiranjit
2 Replies

4. Shell Programming and Scripting

Find file that matches today's date in filename and move to /tmp in bash

I'm having problems with my bash script. I would like to find a file matching today's date in the filename, i.e. my_file_20120902.txt and then move it to a different directory, i.e. /tmp. Thanks. (1 Reply)
Discussion started by: jamesi
1 Replies

5. Shell Programming and Scripting

Shell Scripting: Copy Files with Today's date

I was wondering the best way about finding files that were created today and copy them to a directory (grep ?). There can be multiple files for todays date or none. I am looking to copy all of the .lis files for todays date. I may need to modify the filename to include todays date but for the... (4 Replies)
Discussion started by: smkremer
4 Replies

6. Shell Programming and Scripting

Find the latest file based on the date in the filename

Hi, We've a list of files that gets created on a weekly basis and it has got a date and time embedded to it. Below are the examples. I want to find out how to get the latest files get the date and time stamp out of it. Files are PQR123.PLL.M989898.201308012254.gpg... (1 Reply)
Discussion started by: rudoraj
1 Replies

7. Shell Programming and Scripting

File Copy based on file receive date

I have bunch of files in my source folder like below and every day based on date I am receiving file ex: Nov 28,Nov 29,Nov 30 ... -rw-rw-r--+ 1 root root 20 Nov 27 06:00 aaaa27.txt -rw-rw-r--+ 1 root root 20 Nov 28 06:00 aaaa28.txt -rw-rw-r--+ 1 root root 20 Nov 29 06:00 aaaa29.txt I... (4 Replies)
Discussion started by: krish2014
4 Replies

8. Shell Programming and Scripting

Find and awk with today's date

Hi All, Solaris 10 o/s With your help I developed the following script. find /oracle/diag/rdbms/*/*/trace -type f -name '*d00*.trc' -mtime 0 -exec egrep –c 'NS Primary Error' '{}' '+' which returns the counts I needed nelow: /oracle/diag/rdbms/musidp/musidp/trace/abcdef_d001_21751.trc:15... (9 Replies)
Discussion started by: bdby
9 Replies

9. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

10. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies
All times are GMT -4. The time now is 06:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy