Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6814211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:39:44+00:00 2026-05-26T20:39:44+00:00

I have a directory structure that looks like this: basedir/dir1/dir2/dir3/dir4/myzip/subdirs I would like to

  • 0

I have a directory structure that looks like this:

basedir/dir1/dir2/dir3/dir4/myzip/subdirs

I would like to create an archive of the myzip dir with all its subdirectories, but without including dir1 to dir4 in the zip archive, and save the resulting archive myzip.zip in basedir.

This doesn’t work as dir1 to 4 get included in the archive

cd basedir
zip -r myzip.zip dir1/dir2/dir3/dir4/myzip

I know I can do it this way

cd basedir/dir1/dir2/dir3/dir4
zip -r ../../../../myzip.zip myzip
cd ../../../..
# Need to go back to basedir for next commands

This also works

cd basedir
cp -r dir1/dir2/dir3/dir4/myzip myzip
zip -r myzip.zip myzip
rm -rf myzip
# Kind of annoying to have to copy then remove

Is there a more elegant way to do that? I was hoping I could add some arguments to the first command I typed to make it work the way I wanted in one line.

Isn’t what I want to do what most people want to do too? IMO they should only include subdirs by default in the zip command.

I don’t understand the point of the current implementation of zip, because all those do just the same thing:

zip -r myzip.zip dir1/dir2/dir3/dir4/myzip
zip -r myzip.zip dir1/dir2/dir3/dir4
zip -r myzip.zip dir1/dir2/dir3/
zip -r myzip.zip dir1/dir2/
zip -r myzip.zip dir1/

Wouldn’t it have been smarter to write the zip command so it includes only the subdirectories by default?

Then if you wanted dir1 to dir4 included you could just do:

myVersionOfZip -r myzip.zip dir1

If you wanted only the subdirs of myzip you would do:

myVersionOfZip -r myzip.zip dir1/dir2/dir3/dir4/myzip
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:39:45+00:00Added an answer on May 26, 2026 at 8:39 pm

    You can avoid the cd ../../../.. if you use pushd.

    pushd basedir/dir1/dir2/dir3/dir4
    zip -r myzip.zip myzip
    popd
    

    Archival tools are designed to preserve path information, so I doubt that there’s a way around what you’re trying to.

    That will make your script a little bit more elegant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a directory structure that looks like this: /a/f.xml /b/f.xml /c/f.xml /d/f.xml What
I have a directory structure that looks like this: project/ __init__.py foo/ __init.py__ first.py
So, I have an app/assets/stylesheets/ directory structure that looks something like this: |-dialogs |-mixins
I have a project with a directory structure that looks like: /foo/baz/__init__.py /bar/foo.py /bar/splat.py
I have an installation of CodeIgniter. Basically, my directory structure looks like this: |
I have a data model for a directory type structure that looks something like
When creating gems, I often have a directory structure like this: |--lib |-- helpers.rb
I am a beginner in SVN.I have the SVN directory structure like this: |-trunk
I have a directory structure something like this: base subdir1 subdir2 subdir3 subsubdir1 subsubdir2
I have a project structure that looks like the following: [Solution Name] doc (documentation)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.