Jump to content

Compress/archive


Recommended Posts

Ok, I know how to compress a file.

 

zip -r archive.zip file

 

But, how can I split it in several archives of given size ?

 

For example, I have a 5 MB file. I compress it and it's size is reduced to 1.5 MB. I would like the compression utility to break the archive in 2 750KB archives.

 

How do I do this ?

 

[moved from Software by spinynorman]

Link to comment
Share on other sites

Check the command split, if you just want to split that thing up into 2 files half the size.

man split

Remember, it is already compressed.

 

I hope this is what you need, in which case it's really funny, since you said it already:

But, how can I split it in...

 

Makes me thing back of that time I wanted to rename who ranges of files and finally found that I was looking for the 'rename' command...

Edited by aRTee
Link to comment
Share on other sites

I was hoping to do it all from one command.

 

Anyway, I played a little with split and it does what I want. How do I merge all those files to one (the 'merge' command ?) ?

 

I've read the bzip2 man page but it doesn't mention any splitting.

Link to comment
Share on other sites

Guest duncangareth

How about a shell script:

 

Something like:

 

# gzsplit - gzip a file, then split it

# Change default size if you like - this is 10K

DEFAULTSIZE=10240

NARGS=$#

case $NARGS in

2) SIZE=$1; FILE=$2 ;;

1) SIZE=$DEFAULTSIZE; FILE=$1;;

*) echo "Usage: tgzsplit <filename>";

exit 1;;

esac

if [ -r $FILE ]

then

gzip -9 $FILE ; split -b $SIZE $FILE.gz $FILE

else

echo "gzsplit: file $FILE not found."

exit 1

fi

 

To re-assemble the file, simply say:

 

cat filename?? > filename.gz

 

then gunzip it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...