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 6828711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:24:54+00:00 2026-05-26T22:24:54+00:00

I want to zip a sub directory and send it elsewhere, the problem I

  • 0

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.

  • 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-26T22:24:55+00:00Added an answer on May 26, 2026 at 10:24 pm

    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:

    (cd Unwanted1/Unwanted2; zip -r ~/new.zip ./wanted/file.txt)
    

    Or since you’re using -r you presumably want more than just file.txt, so:

    (cd Unwanted1/Unwanted2; zip -r ~/new.zip wanted)
    

    Or use pushd/popd to jump in/out:

    pushd Unwanted1/Unwanted2
    zip -r ~/new.zip wanted
    popd
    

    This works in sh/bash/csh/tcsh.

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

Sidebar

Related Questions

All I have used osmdroid and i want to download map zip files from
I have a bunch of files in a directory. I want to zip some
I want to pack the project into a zip-file and have the build date
When creating a zip from ant, how can I exclude all sub directories and
I have the path /home/mine/new that contains files and sub directories. I want to
Say I have a list and a vector, and I want to zip them
I have the following code to zip all the files and then save it
I have a scenario where by I want to zip an email attachment using
the problem is: I have a local directory '/local' and a remote FTP directory
I have a ubuntu server. How can I zip files through executing a command

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.