0
0
Linux CLIscripting~10 mins

Why compression saves storage and bandwidth in Linux CLI - Visual Breakdown

Choose your learning style9 modes available
Concept Flow - Why compression saves storage and bandwidth
Original Data
Apply Compression Algorithm
Compressed Data Created
Store Compressed Data
Send Compressed Data Over Network
Decompress Data When Needed
Data is compressed to reduce size, then stored or sent, saving space and bandwidth before decompression.
Execution Sample
Linux CLI
echo "Hello Hello Hello Hello" > file.txt
ls -l file.txt
gzip file.txt
ls -l file.txt.gz
Create a text file with repeated words, check size, compress it, then check compressed size.
Execution Table
StepCommandActionOutput/Result
1echo "Hello Hello Hello Hello" > file.txtCreate file.txt with repeated textNo output
2ls -l file.txtCheck file size-rw-r--r-- 1 user user 24 file.txt
3gzip file.txtCompress file.txt to file.txt.gzNo output
4ls -l file.txt.gzCheck compressed file size-rw-r--r-- 1 user user 16 file.txt.gz
5gzip -d file.txt.gzDecompress back to file.txtNo output
6ls -l file.txtCheck decompressed file size-rw-r--r-- 1 user user 24 file.txt
💡 Compression reduces file size from 24 to 16 bytes, saving storage and bandwidth.
Variable Tracker
VariableInitialAfter Step 1After Step 3After Step 5
file.txt size (bytes)024deleted24
file.txt.gz size (bytes)N/AN/A16deleted
Key Moments - 3 Insights
Why is the compressed file smaller than the original?
Because compression finds repeated patterns (like repeated words) and stores them efficiently, as shown in step 4 of the execution_table.
Does compression lose any data?
No, gzip compression is lossless, meaning the original data is fully restored after decompression, as seen in steps 5 and 6.
Why does sending compressed data save bandwidth?
Because the compressed file is smaller, less data is sent over the network, reducing bandwidth usage, illustrated by the smaller size in step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the size of file.txt after compression?
A24 bytes
B0 bytes
CFile deleted
D16 bytes
💡 Hint
Check step 3 and 4: after compression, file.txt is replaced by file.txt.gz.
At which step is the compressed file size checked?
AStep 2
BStep 4
CStep 5
DStep 6
💡 Hint
Look at the execution_table row where ls -l file.txt.gz is run.
If the original file had no repeated words, how would compression affect size?
ACompressed file would be about the same size
BCompressed file would be much smaller
CCompressed file would be larger
DCompression would fail
💡 Hint
Compression works best with repeated patterns; without them, size reduction is minimal.
Concept Snapshot
Compression reduces file size by encoding repeated data efficiently.
This saves storage space and bandwidth when sending files.
Use tools like gzip to compress and decompress files.
Compression is lossless: original data is fully restored.
Smaller files mean faster transfers and less storage used.
Full Transcript
This lesson shows why compression saves storage and bandwidth. We start with a file containing repeated words. Checking its size shows 24 bytes. After compressing with gzip, the file size reduces to 16 bytes. This smaller size means it uses less storage space and less bandwidth when sent over a network. Decompressing restores the original file fully, proving compression is lossless. Compression works by finding repeated patterns and storing them efficiently, which is why repeated words compress well. If data has no repetition, compression saves less space. Overall, compression helps save resources by reducing file sizes.