compress a folder
Pack a folder into one compressed file, look inside it, and unpack it again.
Steps
-
tar -czf folder.tar.gz folder/pack and compress with gzip, fast
-
tar -cJf folder.tar.xz folder/with xz: smaller, slower
-
zip -r folder.zip folder/a zip, for people on Windows
-
tar -tzf folder.tar.gzlist what is inside, without unpacking
-
tar -xzf folder.tar.gzunpack it here
-
unzip folder.zipunpack a zip
Notes
lore explain "tar -czf folder.tar.gz folder/"says what each letter does.- GNU tar also does zstd, fast and small:
tar --zstd -cf folder.tar.zst folder/.
Commands used
tarzipunzipgzipxz
Each has a page in lore: lore tar opens it.
Related recipes
- pack a folder without some filesMake a tar archive of a folder, leaving out folders like node_modules and files like logs.
- unpack an archiveOpen any common archive: tar, zip, gz, xz, 7z, rar.
- add to the end of a fileAdd lines to a file without replacing it, also to a file only root can write.
- argument list too long"Argument list too long" from rm, cp or mv: too many files for one command line. Hand them over in batches.