Learn to pack and unpack files with tar on the command line and move archives around efficiently. 15.11.2025 | reading time: 2 min Tar is the classic Unix tool to gather files into a single archive for storage or transport; this short guide shows how to create, inspect and extract tar archives from the shell with practical commands. A hands-on example Create a small example, pack it, inspect it and extract it again with the following commands and outputs: ```$ ls -R project project: README.md src project/src: main.c $ tar -cvf project.tar project project/ project/README.md project/src/ project/src/main.c $ tar -tf project.tar project/ project/README.md project/src/ project/src/main.c $ mkdir -p /tmp/extracted && tar -xvf project.tar -C /tmp/extracted project/ project/README.md project/src/ project/src/main.c ``` Compression options To save space, combine tar with compressors: use `tar -czvf archive.tar.gz` for gzip, `tar -cjvf` for bzip2, or `tar -cJvf` for xz; extract the matching compressed archive with `-x` plus the same compression flag or let modern tar auto-detect compression. Tips and edge cases Use `-C` to change directory while archiving or extracting, `--strip-components=N` to drop leading path elements on extract, `--exclude` to skip files, and `-p` when you need to preserve permissions; avoid storing absolute paths unless you use `-P` and understand the risks. Complementary utilities For different workflows consider `rsync` for incremental transfers, `zip`/`unzip` when cross-platform ZIP is required, and `cpio` or `star` for specialized archive formats and tape support; combine `ssh` and tar to stream archives across machines securely. Final thoughts Tar remains a powerful, scriptable tool for packaging and moving files; try composing small scripts that create compressed archives and verify their contents to automate backups and deployments, and continue learning Linux fundamentals toward certifications like CompTIA Linux+ or LPIC-1 with focused exam preparation such as bitsandbytes.academy. Join Bits & Bytes Academy First class LINUX exam preparation. filesystem utilities backup storage scripting