Essential Linux File Management Commands: tar, zip, unzip, ln, scp, and rsync
This guide introduces essential Linux file management commands—including tar, zip, unzip, ln, scp, and rsync—detailing their most useful options, typical usage patterns, and examples for creating, extracting, linking, and synchronizing files both locally and remotely.
tar: compress and decompress
Commonly used to create a .tar.gz archive with gzip compression:
# Most common: create .tar.gz archive (gzip compression), resulting in backup.tar.gz
tar -zcvf backup.tar.gz /home/user/docs # z=gz compression, c=create, v=verbose, f=specify filename
# Create .tar.bz2 archive (bzip2 compression, higher compression ratio)
tar -jcvf backup.tar.bz2 /home/user/docs
# Extract .tar.gz to current directory
tar -zxvf backup.tar.gz # x=extract, other parameters same as above
# Extract to specified directory (essential! avoid clutter in current directory)
tar -zxvf backup.tar.gz -C /tmp/backup # -C specifies target directory (must exist)
# List archive contents without extracting
tar -ztvf backup.tar.gz # t=list, v=verbose details
# Extract .tar.xz format (high compression ratio)
tar -Jxvf backup.tar.xzzip: compress
Key options:
-r: recursive compression, required for directories
-q: silent mode, no progress output
-m: delete original files after compression
-u: update archive with new content
-d: delete specified content from the archive
# Compress a single file
zip test.zip test.txt
# Compress a directory (must include -r, otherwise ineffective)
zip -r docs.zip /home/user/docs # recursively compress all contents of docs directory
# Silent compression (no progress output)
zip -qr docs.zip /home/user/docs
# Add new file to archive (update)
zip -u docs.zip /home/user/new_file.txt
# Delete original file after compression (save space)
zip -rm docs.zip /home/user/docs
# Delete specified file inside archive
zip -d docs.zip "docs/unused.txt" # remove unused.txt from docs.zipunzip: decompress
Key options:
-d: specify target directory for extracted contents
-l: list archive contents without extracting
-q: silent mode
-o: force overwrite without prompting
# Extract to current directory
unzip docs.zip
# Extract to specified directory (most common, avoid file clutter)
unzip docs.zip -d /tmp/docs # extracts to /tmp/docs (directory created if needed)
# List archive contents without extracting
unzip -l docs.zip
# Silent extraction (no progress output)
unzip -q docs.zip
# Force overwrite during extraction (no confirmation needed)
unzip -o docs.zip
# Extract only specified file from archive
unzip docs.zip "docs/important.txt" -d /tmp # extracts important.txt to /tmpln: link files
# Soft link (symbolic), supports cross-partition, not for directories
ln -s /etc/nginx/nginx.conf /tmp/nginx.conf
# Hard link shares inode with source; deleting source does not affect hard link; after source deletion, soft link fails; supports files and directories
ln /etc/nginx/nginx.conf /tmp/nginx.confscp: remote file transfer
# Transfer a tarball to a remote machine
scp apr-1.6.3.tar.gz root@remote-ip-address:/root
# Transfer a file using a non‑default port (11333)
scp -P 11333 111.txt [email protected]:/etcrsync: incremental synchronization
Local sync
rsync [options] source_path destination_path
rsync -av /data/aaa.txt /backup/Remote sync: local → remote
# Archive mode, verbose, compress; sync contents of backup to remote backup
rsync -avz /data/backup/ [email protected]:/tmp/backup/
# Remote non‑22 port
rsync -avz -e "ssh -p 11222" /data/backup/ [email protected]:/tmp/backup/
# Exclude specified files from sync
rsync -avz --exclude="log/" --exclude="*.tmp" /data/project/ [email protected]:/tmp/project/
# Large file transfer with -P for resume
rsync -avzP /data/lar.tar.gz [email protected]:/tmp/Remote sync: remote → local
# Pull from remote to local
rsync -avz [email protected]:/var/log/nginx/ /tmp/nginx_logs/Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Linux Cloud-Native Ops Stack
Focused on practical internet operations, sharing server monitoring, troubleshooting, automated deployment, and cloud-native tech insights. From Linux basics to advanced K8s, from ops tools to architecture optimization, helping engineers avoid pitfalls, grow quickly, and become your tech companion.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
