Help - compress file one day ago


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help - compress file one day ago
# 1  
Old 03-23-2012
Help - compress file one day ago

Hi All,
I'm a new member of this Forum. I have need your help to handle this request.

"Compress a file name not of today but of yesterday only".

For example
Code:
0 mar 08:00 TEST_RPT_STATUS_M1I_CMI20120320.xls
20 mar 08:00 TEST_RPT_STATUS_M1I_CMI20120320.rep
21 mar 08:00 TEST_RPT_STATUS_M1I_CMI20120321.xls
21 mar 08:00 TEST_RPT_STATUS_M1I_CMI20120321.rep
22 mar 08:00 TEST_RPT_STATUS_M1I_CMI20120322.xls
22 mar 08:00 TEST_RPT_STATUS_M1I_CMI20120322.rep
23 mar 11:39 TEST_RPT_STATUS_AAAAAAAAAAAAAA.log
23 mar 11:39 TEST_RPT_STATUS_BBBBBBBBBBB.log

If I use this Unix/Linux command
Code:
find /home/user1/LOGS -mtime -1 -type f -iname "TEST_RPT*" -exec gzip -f '{}' ';'

only the files of today will be compressed. If I set -2 as mtime I find the files of today and of yesterday compressed.

I need to use compress ONLY the files of yesterday (Here 22 mar).

Any suggestion will be well appreciated.

Thanks in advance for your kind support.

Regards,

Giovanni

Moderator's Comments:
Mod Comment How to use code tags when posting data and code samples.

Last edited by Franklin52; 03-24-2012 at 09:18 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 03-23-2012
find

Hi,

Greetings!!! Welcome to the unix and linux forum!!!!

Code:
find /home/user1/LOGS -mtime +1 -type f -iname "TEST_RPT*" -exec gzip -f '{}' ';'

-1 in mtime says to the find command that, get the files are created with in one day.
+1 in mtime says to the find command that, get the files are created more than one day.

Please use code tags for data samples and codes.

Cheers,
RangaSmilie

Last edited by rangarasan; 03-23-2012 at 10:47 AM..
# 3  
Old 03-23-2012
Welcome.

The find command is a weird one since the switches like -mtime etc. usually will list a range of files (i.e. +1 files older than a day, etc.). One way to get only the files created the previous day, is to use a combination of boolean operators and the -daystart switch (see find man page):

Code:
find . \( -mtime -1 -and -not -daystart -mtime 0 \)

Hope this helps.
# 4  
Old 03-23-2012
Hi Thanks for your quick reply.

The Unix command is the following
Code:
find /home/user1/LOGS  \( -mtime -1 -and -not -daystart -mtime 0 \) -type f -iname "TEST_RPT*" -exec gzip -f '{}' ';'

No error is returned by the script but no file is compressed.

Any suggestion will be well appreciated.

Thanks,

Regards,

Giovanni

Last edited by Franklin52; 03-24-2012 at 09:18 AM.. Reason: Please use code tags for data and code samples, thank you
# 5  
Old 03-23-2012
if you use GNU find then try this Smilie
Code:
# find . -daystart -type f -mtime 1

so
Code:
# find /home/user1/LOGS -daystart -mtime 1 -type f -iname "TEST_RPT*" -exec gzip -f '{}' ';'


Last edited by ygemici; 03-24-2012 at 08:20 AM..
# 6  
Old 03-23-2012
Hi,
Sorry again for the trouble but the message returned is the following
Code:
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

Any idea?

Thanks in advance.

Regards,

Giovanni

---------- Post updated at 12:23 PM ---------- Previous update was at 10:51 AM ----------

Hi All!
Problem solved!
Code:
find /home/user1/LOGS -daystart -mtime 1 -type f -iname "TEST_RPT*" -exec gzip -f '{}' ';'

Thank You very much indeed.

Regards,

Giovanni

Last edited by Franklin52; 03-24-2012 at 09:19 AM.. Reason: Code tags
# 7  
Old 03-24-2012
Quote:
Originally Posted by gio123bgg
Hi,
Sorry again for the trouble but the message returned is the following

Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

Any idea?

Thanks in advance.

Regards,

Giovanni

---------- Post updated at 12:23 PM ---------- Previous update was at 10:51 AM ----------

Hi All!
Problem solved!

find /home/user1/LOGS -daystart -mtime 1 -type f -iname "TEST_RPT*" -exec gzip -f '{}' ';'

Thank You very much indeed.

Regards,

Giovanni
i forgot the "1" after daystart while write the your commd, because of i work on jobs more than one at the same time and sometimes I'm doing typo Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find a file that's modified more than 2 days ago but less than 5 days ago?

How to find a file that's modified more than 2 days ago but was modified less than 5 days ago by use of any Linux utility ? (4 Replies)
Discussion started by: abdulbadii
4 Replies

2. Shell Programming and Scripting

Help - To copy and compress files one day ago

Hi dears, Hi All, I'm a new member of this Forum. I have need your help to handle this request. "I want to copy and Compress files not of today but of yesterday only using some script". For example I have the following files under a particular directory in a Solaris machine. ... (7 Replies)
Discussion started by: JackyJohn
7 Replies

3. Shell Programming and Scripting

script to compress files in directory that changes its name every day

Hi all I have the following script that should compress a file in a directory: # compress log files older than 2 days find /u01/easydone/DBDUMPS/*.dmp -mtime +2 -exec gzip {} \; BUT the problem is that these files that I want to compress are inside a directory with following format: ... (5 Replies)
Discussion started by: fretagi
5 Replies

4. UNIX for Dummies Questions & Answers

Issue: Compress in unix server and FTP to windows and open the compress file using Winzip

Hi All ! We have to compress a big data file in unix server and transfer it to windows and uncompress it using winzip in windows. I have used the utility ZIP like the below. zip -e <newfilename> df2_test_extract.dat but when I compress files greater than 4 gb using zip utility, it... (4 Replies)
Discussion started by: sakthifire
4 Replies

5. Shell Programming and Scripting

How to touch a file 30min ago

I know how to touch like this touch -t 199908031046 /tmp/file1 But I want to create a cron job for touch a file which 30 min ago in Solaris which haven't -mmin Can I use like this ? touch -t `date +%s` - 30 /tmp/file1 Because I want to file the file which older than 30min. Thanks, (6 Replies)
Discussion started by: kennylcn
6 Replies

6. Shell Programming and Scripting

Cron to run first day of month to calculate date 3 months ago

Hi, I would like to find out how can i calculate a date which is 3 months ago. I intend to run a cron job on the 1st of every month, and calculate the month 4 months earlier from the date. For example, if today's date is 1st May 2007, i would like to return 012007( January 2007). i can get... (1 Reply)
Discussion started by: new2ss
1 Replies

7. Shell Programming and Scripting

Find the file from 15 days ago

How can I get difference date between today and 15 days ago and all filename is was created before 15 days ago? It has to be korn shell script. Thanks. (2 Replies)
Discussion started by: YoungBlood
2 Replies

8. UNIX for Dummies Questions & Answers

file was created before 15 days ago.

How can I get difference date between today and 15 days ago and all filename is was created before 15 days ago? It has to be korn shell script. Thanks. (1 Reply)
Discussion started by: YoungBlood
1 Replies

9. Shell Programming and Scripting

How to compare prev day file to current day file

Hi all: I am new to this board and UNIX programming so please forgive if I don't explain something correctly. I am trying to write a script to keep track of our links, we link one program written for Client A to Client B's directory. What we want to do is to keep track of our linked programs... (1 Reply)
Discussion started by: Smurtzy
1 Replies
Login or Register to Ask a Question