LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-08-2004, 02:17 PM   #1
antonioxcom
LQ Newbie
 
Registered: Jul 2004
Posts: 6

Rep: Reputation: 0
linux gzip file by date


hi,

there are alot of log file in the directory:

20040421.txt
20040422.txt
..
..
20040707.txt
20040708.txt


I wanna to gzip:
20040421.txt -> 20040421.txt.gz
20040422.txt -> 20040422.txt.gz
...
...
...
until
20040708.txt - > 20040708.txt.gz

Exclude the latest log, which is today's log.txt
 
Old 07-08-2004, 02:32 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Something like

Code:
 ls -1t *txt | tail -n $((`ls -1 *txt | wc -l` -1 )) | xargs gzip
should do the trick ...


Cheers,
Tink
 
Old 07-11-2004, 03:35 AM   #3
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("jessie", "squeeze"), Linux Mint (Serena), XUbuntu
Posts: 221

Rep: Reputation: 24
I'm more of a newbie than the last guy, so I can make it simpler. I'm sure he's right, but it's too
much of a scripting tour de force to read it!

I'm not sure you really want gzip, because it seems to individually compress the files without
putting them all together into a single file (unlike Windows zip or PKZIP which you are probably
used to already).

So gzip * compresses everything, but as separate files. (Well I guess you asked that).
In Linux, the packaging is more typically
done with "tar". "Tar" like everything Linux tends to like to output to stdio if you don't give it
a -f option. So what you want is:

tar -cf yourarchive *
After you have this, you can gzip youracrchive to also compress it.

You wanted not to include one file. You can tar as above, then use
tar --delete 20040708.txt to remove that one file before gzipping.
 
Old 07-11-2004, 04:15 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally posted by pcardout
[B]I'm more of a newbie than the last guy, so I can
make it simpler. I'm sure he's right, but it's too
much of a scripting tour de force to read it!
Heh - it's not that hard ... the only half-way
complex thing is this bit:

Code:
tail -n $((`ls -1 *txt | wc -l` -1 ))
determine the number of files, and subtract one,
which I do to only get the "oldest" entries in tail...
the
Code:
ls -1t *txt
gives you all entries sorted by date, newest first
(thus in the first line). With the tail-bit I cut-off the
newest one. And with the xargs gzip the older
ones get zipped individually, which is exactly what
the fellow had asked for.


Cheers,
Tink
 
Old 07-12-2004, 12:07 AM   #5
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("jessie", "squeeze"), Linux Mint (Serena), XUbuntu
Posts: 221

Rep: Reputation: 24
Tink - Thanks for the lesson!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Solaris 8 gzip issues- cannot gzip -d lynx sixosix Solaris / OpenSolaris 4 03-13-2005 03:17 PM
gzip a directory into a file tcma Linux - Software 4 10-07-2004 02:51 AM
untar gzip file problem jmr0311 Linux - General 8 09-12-2004 04:32 PM
How to gzip a file SnowSurfAir Linux - Software 5 07-31-2003 01:09 PM
gzip and leave the original file intact WindozBytes Programming 4 09-04-2002 09:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration