Zipping a directory and extracting to another server.

Hello everyone,

I am trying to make a script in KSH that will zip an entire directory but leave out one file in that directory. I then need to send that zipped directory to another UNIX box. I am new to UNIX and would appreciate a good template to study from.

Why zip? why not tar?

---------- Post updated at 12:07 PM ---------- Previous update was at 12:01 PM ----------

# cd into the source directory you want
cd /path/to/source
# List all files, excluding one name, then feed those names into tar
find . -type f '!' -name 'whatever.ext' |
# Feed those names into xargs, which turns piped parameters into
# commandline arguments. 'echo asdf | xargs cat' is equivalent to
# 'cat asdf' for instance.
# it then runs tar, which creates /tmp/whatever.tar
xargs -I {} tar -rcf /tmp/whatever.tar
# extract it on the remote server
ssh username@host tar -C /path/to/dest -vxf - < /tmp/whatever.tar
rm /tmp/whatever.tar[/code]

Less convoluted ways are possible depending what your system is but since you never said, I suspect they won't work.

1 Like

Thank you Corona! Your reply was very comprehensible and fast!

It's a common question so I had an answer handy.