u (update) command updates files in archives with fine-grained control over which files are updated, added, or refreshed based on timestamps and existence.
Syntax
Description
The update command provides sophisticated archive maintenance by:- Updating existing files with newer versions
- Adding new files not in the archive
- Skipping files that haven’t changed
- Supporting complex update modes
- Preserving archive structure and metadata
The main difference between
a (add) and u (update): the a command always adds/updates files, while u compares timestamps and only updates newer files by default.Common Options
Name of the archive to update. Must already exist.
Files or directories to update. Supports wildcards.
Set update action mode. Controls behavior for different file states.Format:
-u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]See Update Modes below.Set archive type.Example:
-t7zSet compression level (0-9).
Set password for encrypted archives.
Recurse subdirectories.
Exclude files by pattern.
Include files by pattern.
Set working directory.
Update Modes
The-u switch controls update behavior with a complex but powerful syntax:
State Codes
Each letter represents a file state:| Code | State | Description |
|---|---|---|
p | File exists in archive and on disk | Both versions exist |
q | File exists in archive only | Deleted from disk |
r | File exists on disk only | New file not in archive |
x | File in archive is newer | Archive version is newer |
y | File on disk is newer | Disk version is newer |
z | Files are same age | Timestamps match |
Action Numbers
Each state can have an action:| Number | Action |
|---|---|
| 0 | Ignore this file |
| 1 | Copy from archive to temp archive |
| 2 | Copy from disk to temp archive |
| 3 | Copy from both (archive and disk) |
Default Update Mode
Without-u, the update command uses:
p0- If in both: ignore (no update)q0- If in archive only: ignore (keep in archive)r2- If on disk only: add from diskx1- If archive is newer: keep archive versiony2- If disk is newer: update from diskz1- If same age: keep archive version
Examples
Basic update (newer files only)
Update with maximum compression
Update specific files
Update all text files
Synchronize archive with directory
sync.7z that exactly matches the files/ directory.
Update and delete removed files
Advanced Update Modes
Synchronization Mode
Create an archive that exactly mirrors a directory:q0- Remove files deleted from diskr2- Add new files from diskx2- Use newer file (from disk if disk is newer)y2- Use newer file (from disk if disk is newer)z0- When same, ignore (keeps archive version)
Incremental Backup
Update only changed files:Freshen Existing Files
Update only files that already exist in archive:r0- Don’t add new filesy2- Update with newer files from disk
Add New Files Only
Add files not in archive, don’t update existing:p0- Ignore files in bothr2- Add files only on disk
Complex Examples
Update with password
Update excluding patterns
Update with new compression method
Update and show differences
Conditional update based on size
Update multiple archives
Update vs Add Command
| Feature | Update (u) | Add (a) |
|---|---|---|
| Check timestamps | Yes, by default | No |
| Skip unchanged files | Yes | No |
| Update modes | Configurable | Simple |
| Performance | Faster (skips unchanged) | Slower (processes all) |
| Use case | Incremental updates | Create/full refresh |
When to Use Update
- Incremental backups - Only backup changed files
- Syncing archives - Keep archive matching directory
- Efficiency - Skip unchanged files to save time
- Selective updates - Complex update logic needed
When to Use Add
- Creating archives - New archive from scratch
- Full refresh - Rebuild entire archive
- Simplicity - Don’t need timestamp checking
- Force update - Update all files regardless of timestamp
Scripting Examples
Daily Incremental Backup
Smart Update Script
Synchronize Directory to Archive
Performance Tips
- Use update instead of recreating - Much faster for large archives
- Enable multi-threading - Add
-mmt=onfor faster compression - Adjust compression level - Use
-mx=1for faster updates - Use solid archives carefully - Solid mode requires recompression
- Skip unchanged files - Default behavior saves significant time
For solid archives (
-ms=on), updating files requires recompressing the entire solid block, which can be slow. Non-solid archives allow updating individual files independently.Related Commands
- Add Command (a) - Create or add to archives
- Delete Command (d) - Remove files from archives
- List Command (l) - View archive contents