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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...