Solved

Compress files between dates in unix

Posted on 2014-07-23
4
673 Views
Last Modified: 2014-07-24
How do i compress certain files in my unix folder, between two given dates with certain name?

example.

i need to compress all the files with the name file1_*.txt and date between JUN_11 and JUL_20
 all compressed into one single file, is this possible? thanks.
0
Comment
Question by:celtician
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40215956
What dates? modification time? access time? inode change time?
And what kind of compression?
0
 

Author Comment

by:celtician
ID: 40215981
gzip type of compression

dates: from july-8, to july 20
access time, any time, that parameter doesn't matter, its only creation time. same applies for modification or inode change time.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 40216021
Are the dates fixed?

If so, then

gzip file1_JUN1[1-9].txt
gzip file1_JUN20.txt
0
 
LVL 27

Accepted Solution

by:
serialband earned 500 total points
ID: 40217698
@Tintin,

Won't that just create multiple files that are gzipped?  If you want a single file, you'll need to do some more.

You need to create 2 files with the date and time of the period you're looking for.
From your original question.
touch -t 201406110000 start_date
touch -t 201407210000 stop_date


In your follow up comment, you set your date to July-8 - July 20
touch -t 201407080000 start_date
touch -t 201407200000 stop_date


Then you can find the files between those dates and then create a tar gzip of the files
find PATH_TO_FILES -newer start_date ! -newer stop_date -exec tar -czf archive_files.tgz {} \;
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now