Compressing old files as zip file through script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compressing old files as zip file through script
# 1  
Old 07-23-2013
Compressing old files as zip file through script

I have below files in foler one/archive>

Code:
one. txt     6/21/2013
two txt      7/23/2013
three.txt    6/20/2013

I wanted to move all the old files (>30 days) compressing single .zip file into one/archive/ as below

Code:
two txt         7/23/2013
oldfiles.zip     6/21/2013

Please provide the script for the same

Thanks in advance.

Last edited by Don Cragun; 07-23-2013 at 07:55 AM.. Reason: Please use CODE tags
# 2  
Old 07-23-2013
you can find the files older than 30 days and archive them with the below commandline.

Code:
find . -mtime +30 | xargs tar cvzf archive.tar

remove files older than 30 days with the below commandline.

Code:
find . -mtime +30 | xargs rm

This User Gave Thanks to codemaniac For This Post:
# 3  
Old 07-23-2013
Thanks for your reply

Problem facing here is that it is pulling the list of files from sub folder as well.
# 4  
Old 07-23-2013
the gnu find has a maxdepth option that lets you restrict the search to the current directory.

can you try something like below.

Code:
find . -maxdepth 1 -mtime +30


Last edited by codemaniac; 07-23-2013 at 10:20 AM..
This User Gave Thanks to codemaniac For This Post:
# 5  
Old 07-24-2013
Got a error saying -maxdepth is invalid option, thanks

---------- Post updated 07-24-13 at 01:36 AM ---------- Previous update was 07-23-13 at 09:36 AM ----------

The above provided solution is not working for me
# 6  
Old 07-25-2013
Code:
find . -mtime +30 | zip name -@ -

Here Files get zipped from sub folders as well. I wanted to zip only from current dir files. - maxdepth +1 option not working for me.

can someone help me on this issue.

Last edited by Scott; 07-25-2013 at 11:07 AM.. Reason: Code tags
# 7  
Old 07-25-2013
okay if you are not using GNU find then i guess maxdepth will not be available.

You can do something like below using prune to not descending to and directory other than "dir".
Code:
find /full/path/dir \( ! -name dir -o -type f \) -prune -type f

This User Gave Thanks to codemaniac For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

3. Homework & Coursework Questions

Trouble with Shell Script Compressing file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: You will create a shell script that performs the following action: Use a parameter to pass a file that... (5 Replies)
Discussion started by: Luvs2drnk
5 Replies

4. Shell Programming and Scripting

Using Shell Script in place of Perl script to Unzip the zip files.

Hi Expert, We have some shell scripts which Internally uses Perl Script to Unzip the source zip files which comes to inbound directory. So now our requirement is to avoid the dependency on Perl Script and us Shell Script to unzip the files. I have the Perl script with me attached can some one... (3 Replies)
Discussion started by: naveen.dasu
3 Replies

5. Shell Programming and Scripting

Script to zip the files of yesterday

Hi I've the following requirement, where i need to zip the yesterday files every day . Yesterday's Files touch AB_XYZA_20130930183017.log touch AB_DY_XYZA_20130930183017.log touch AB_GZU_20130930183017.log touch AB_XYZA_20130930180023.log touch AB_DY_XYZA_20130930180023.log touch... (1 Reply)
Discussion started by: smile689
1 Replies

6. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

7. Shell Programming and Scripting

Script to rename zip-files with name of file

Hi, I'm desperately in search for a solution of the following problem: I have a directory full of zip-files. All these zip-files contain a single file with a name that should be used for the name of the zip-container. Anybody a good idea. I'm an absolute beginner in shell scripting - so please... (7 Replies)
Discussion started by: mark_a17
7 Replies

8. AIX

ZIP multiple files and also specify size of zip file

I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a... (1 Reply)
Discussion started by: tom007
1 Replies

9. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies

10. UNIX for Dummies Questions & Answers

compressing two files in a script

Hi, i have written a script in unix which produces two files(.csv file) at the end. Now i want to add these to files in a zip file and send the zip file across the network by FTP. Problem is that i dunno how to make a single zip file containing the two files that have been created by the script.... (1 Reply)
Discussion started by: nimish
1 Replies
Login or Register to Ask a Question