How to Zip USB Files Without Absolute Paths: Get Relative Paths in Zip Archives (macOS Terminal)

Zipping files from a USB drive is a common task, whether for backups, sharing, or archiving. However, macOS users often encounter an annoying issue: when creating a zip archive via the GUI (right-click > Compress), the resulting zip file may include absolute paths (e.g., /Volumes/MyUSB/Documents/Report.pdf). This is problematic because when someone unzips the file, it recreates the entire absolute path structure (like /Volumes/MyUSB/...), which is unnecessary, confusing, and not portable.

The solution? Use the macOS Terminal to create zip archives with relative paths instead. Relative paths (e.g., Documents/Report.pdf) ensure the zip file contains only the folder structure relative to your USB drive’s root, making it clean and usable for anyone.

In this guide, we’ll walk through every step to achieve this, from understanding paths to verifying your zip archive.

Table of Contents#

  1. Understanding Absolute vs. Relative Paths
  2. Why Absolute Paths in Zip Archives Are a Problem
  3. Preparing Your USB Drive
  4. Accessing the macOS Terminal
  5. Navigating to Your USB Drive in Terminal
  6. Zipping Files with Relative Paths: Step-by-Step
  7. Verifying the Zip Archive (Check for Relative Paths)
  8. Troubleshooting Common Issues
  9. Conclusion
  10. References

1. Understanding Absolute vs. Relative Paths#

Before diving into Terminal commands, let’s clarify the difference between absolute and relative paths:

  • Absolute Path: A full path starting from the root directory (/). For example:
    /Volumes/MyUSB/Photos/Summer2023.jpg
    This path uniquely identifies a file on your system but is tied to your specific setup (e.g., your USB drive’s name and mount point).

  • Relative Path: A path relative to your current working directory. For example, if your current directory is /Volumes/MyUSB, the relative path to Summer2023.jpg would be:
    Photos/Summer2023.jpg
    Relative paths are portable because they don’t depend on the system’s root structure.

2. Why Absolute Paths in Zip Archives Are a Problem#

When you zip files with absolute paths:

  • Cluttered Extraction: Unzipping the file recreates the entire absolute path (e.g., /Volumes/MyUSB/...), which is irrelevant on another user’s system.
  • Portability Issues: If the recipient’s USB drive has a different name (e.g., USB Stick instead of MyUSB), the path breaks.
  • Confusion: Users may struggle to find files buried in unnecessary nested folders.

Relative paths solve this by storing only the structure relative to your USB drive’s root, ensuring clean, portable extraction.

3. Preparing Your USB Drive#

Before using Terminal:

  1. Mount the USB Drive: Plug it into your Mac. It should appear on the Desktop or in Finder under "Locations."
  2. Note the USB Name: The drive’s name (e.g., MyUSB, BackupDrive) is critical for navigation in Terminal. Avoid names with special characters (e.g., !, @) if possible—spaces are okay but require extra care (see Troubleshooting).
  3. Organize Files (Optional): If needed, arrange files/folders on the USB into the structure you want in the zip (e.g., Docs/, Photos/). The zip will mirror this structure.

4. Accessing the macOS Terminal#

Terminal is macOS’s command-line interface. To open it:

  • Press Cmd + Space to open Spotlight Search.
  • Type Terminal and hit Enter.

A Terminal window will appear, ready for commands.

5. Navigating to Your USB Drive in Terminal#

To zip with relative paths, you must first navigate to your USB drive’s root directory in Terminal. Here’s how:

Step 1: List All Mounted Volumes#

First, confirm your USB drive’s name and mount point. Run:

ls /Volumes

This lists all mounted drives (e.g., Macintosh HD, MyUSB, Time Machine Backups). Locate your USB drive’s name (e.g., MyUSB).

Step 2: Navigate to the USB Drive#

Use the cd (change directory) command to move into your USB drive’s root. Replace MyUSB with your drive’s name:

cd /Volumes/MyUSB

Verify your location: Run pwd (print working directory) to confirm you’re in the USB root. The output should be:

/Volumes/MyUSB

6. Zipping Files with Relative Paths: Step-by-Step#

Now that you’re in the USB root directory, use the zip command to create an archive with relative paths. The zip tool is preinstalled on macOS, so no extra software is needed.

Basic: Zip Entire USB Contents#

To zip all files and folders on the USB (preserving their structure as relative paths):

Run this command (replace my_archive.zip with your desired archive name):

zip -r my_archive.zip .

Breakdown of the command:#

  • zip: The terminal tool for creating zip archives.
  • -r: "Recursive" flag—includes subfolders and their contents.
  • my_archive.zip: The name of your output zip file (saved in the USB root by default).
  • .: Represents the current directory (your USB root). This ensures paths are relative to the USB root.

Advanced: Zip Specific Files/Folders#

To zip only specific files or folders (instead of the entire USB), replace . with the relative paths of the items you want.

Examples:

  • Zip a single file:

    zip my_archive.zip important_document.pdf
  • Zip a specific folder (e.g., Photos):

    zip -r my_archive.zip Photos/
  • Zip multiple files/folders (e.g., Docs/ and Notes.txt):

    zip -r my_archive.zip Docs/ Notes.txt

Save the Zip File Outside the USB (Optional)#

By default, my_archive.zip is saved in the USB root. To save it to your Desktop (or another location), use an absolute or relative path for the output file:

zip -r ~/Desktop/my_archive.zip .
  • ~/Desktop/: Absolute path to your Desktop (the ~ symbol represents your user folder, e.g., /Users/YourName).

7. Verifying the Zip Archive (Check for Relative Paths)#

Always verify the zip file contains relative paths before sharing. Use the unzip -l command to list the archive’s contents without extracting:

unzip -l my_archive.zip

Good output (relative paths):

Archive:  my_archive.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
    12345  09-20-2023 14:30   important_document.pdf
    67890  09-20-2023 14:31   Photos/summer_vacation.jpg
---------                     -------
    80235                     2 files

Bad output (absolute paths—if you forgot to navigate to the USB root first):

Archive:  my_archive.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
    12345  09-20-2023 14:30   /Volumes/MyUSB/important_document.pdf  <-- Avoid this!
---------                     -------
    12345                     1 file

8. Troubleshooting Common Issues#

Issue 1: USB Name Has Spaces#

If your USB drive name has spaces (e.g., My USB), wrap the path in quotes when navigating:

cd "/Volumes/My USB"

Or use backslashes to escape spaces:

cd /Volumes/My\ USB

Issue 2: "Permission Denied" Errors#

If you see Permission denied, the files may be read-only or you lack access.

  • Check permissions: Run ls -l to view file permissions. Look for r (read), w (write), x (execute) for your user.
  • Fix read-only files: Use chmod to grant write access (replace file.txt with your file):
    chmod u+w file.txt
  • Use sudo (last resort): For system-protected files, prefix the command with sudo (e.g., sudo zip -r my_archive.zip .). Enter your Mac password when prompted.

Issue 3: "zip: command not found"#

The zip tool is preinstalled on macOS, but if missing (rare), install it via Homebrew:

brew install zip

Issue 4: Flattened Folders (No Structure)#

If your zip file lacks folder structure (all files in the root), you may have used the -j flag (which "junks" paths). Avoid -j if you want to preserve relative folder structure.

9. Conclusion#

Using Terminal to zip USB files ensures you avoid messy absolute paths and create clean, portable archives with relative paths. The key steps are:

  1. Navigate to your USB root with cd /Volumes/YourUSBName.
  2. Use zip -r archive.zip . (or specific files/folders) to create the archive.
  3. Verify with unzip -l archive.zip to confirm relative paths.

This method works for any external drive (USB, SD card, external SSD) and ensures your zipped files are easy to share and extract anywhere.

10. References#