Solved

Compress files between dates in unix

Posted on 2014-07-23
4
706 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 28

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

770 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