I want to zip a sub directory and send it elsewhere, the problem I have is when I use the zip command it also includes all the unwanted layers of directories I do not want.
e.g.
zip -r /new.zip /Unwanted1/Unwanted2/wanted1/wanted2/file.txt
###unzipped produces the following
/Unwanted1/Unwanted2/wanted1/wanted2/file.txt
###I want
/wanted1/wanted2/file.txt
update: The directory I want to zip has lots of nested directories, hence the -r. Also it would be great to deal with absolute paths, the old solution used to cd about the place but I just didn’t really like it. Perhaps that is the best (only) way.
You have to change directories to wherever you want to start, or maybe there’s an option to ‘zip’ to do that for you. If you’re too lazy to read through the gazillion options in the man page, like I am, just ‘cd’ first, even in a script. Or you can enclose the whole thing in parenthesis without affecting your shell or script’s working directory:
Or since you’re using -r you presumably want more than just file.txt, so:
Or use pushd/popd to jump in/out:
This works in sh/bash/csh/tcsh.