u (Update) command
Update older files in the archive and add files that are not already in the archive.
Note: the updating of solid .7z archives can be slow, since it
can require some recompression.
Example
7z u archive.zip *.doc
updates *.doc files to archive
archive.zip .
Notes
7-Zip doesn't use the system wildcard parser. 7-Zip doesn't
follow the archaic rule by which *.* means any file. 7-Zip treats
*.* as matching the name of any file that has an extension. To process
all files, you must use a * wildcard.
Switches that can be used with this command
-bb (Set output log level)
-i (Include)
-m (Method)
-p (Set Password)
-r (Recurse)
-sfx (create SFX)
-si (use StdIn)
-so (use StdOut)
-sni (Store NT security information)
-sns (Store NTFS alternate Streams)
-ssw (Compress shared files)
-spf (Use fully qualified file paths)
-spm (Require path separator mark for directory path)
-stl (Set archive timestamp from the most recently modified file)
-stx (Exclude archive type)
-t (Type of archive)
-u (Update)
-w (Working Dir)
-x (Exclude)
See also
Commands:
a (Add) ,
d (Delete) ,
Switches:
-u (Update)
Notes from this site
Not part of the 7-Zip manual. Written by this site; examples checked with 7-Zip 26.04.
What is the difference between 7z u and 7z a?
Both add new files. a recompresses every file you name; u skips unchanged files, so it is faster. "Newer" means a later modification time: a changed file with an older time is skipped. u never deletes anything: a file removed from disk stays in the archive. When nothing changed, u reports 0 files added and the archive content stays identical.
Quick examples
The official Linux and macOS console binary is 7zz; the commands differ from Windows only by that name.
7zz u backup.7z /data/project # Windows: 7z u backup.7z C:\data\project
7zz u backup.7z -bb1 /data/project # also print U (updated) and + (added) per file
7zz u backup.7z /data/project -xr'!*.tmp' # leave out *.tmp files
7zz u backup.7z -uq0 /data/project # sync: also drop entries whose file is gone (see warning)
7zz u -pSECRET backup.7z /data/project # archive with a password
7zz u archive.zip '*.doc' -r # quote patterns so the shell does not expand them
# cron: sync only if /data exists and is not empty, then test
[ -n "$(ls -A /data 2>/dev/null)" ] && 7zz u backup.7z -uq0 /data && 7zz t backup.7z
Warning: -uq0 deletes entries, and there is no dry run, so copy the archive first (cp backup.7z backup.bak). A folder is added with its subfolders without -r . -uq0 changes only state q ("in archive, not on disk"); see the -u switch page. All other cases keep the u default.
Common mistakes
-uq0 with a missing source: when /data was not mounted or did not exist, every entry was removed from the archive (exit code 1 with a warning), leaving it empty. Use the guard above.
A touched file was re-added (U with -bb1) although its content was the same; copies or restores that do not keep modification times do the same.
Updating a .tar.gz or .tgz fails with E_INVALIDARG (exit code 2). Workaround: 7zz x x.tgz gives x.tar; run 7zz u x.tar newfile, then 7zz a new.tgz x.tar.
RAR cannot be updated (7-Zip cannot create it). With encrypted file names, give -p; the header encryption was kept. Check the result with t .
Related pages