
du command (short for disk usage) is widely used to determine file sizes.
:::note Viewing File Sizes
To display a file size in kilobytes, use the following command:
:::
ls -lh command to view file sizes in a human-readable format:
Using tar for Archival
Thetar command is one of the most common utilities used to group multiple files or directories into a single archive file (tarball). This is particularly useful for data backup, transfer, and archiving.
To create a tar archive, use the -c option to create the archive and the -f option to specify the file name:
-x option:
-z option:
Compression Commands in Linux
Linux offers several commands for compressing files. The choice of command depends on the type of data and required compression level. Below are examples usingbzip2, gzip, and xz:
| Compression Utility | Command Example | Compressed File Extension |
|---|---|---|
| bzip2 | [~] du -sh test.img.bz2 | .bz2 |
| gzip | [~] du -sh test1.img.gz | .gz |
| xz | [~] du -sh test2.img.xz | .xz |
.bz2 for bzip2, .gz for gzip, and .xz for xz.
:::note Decompressing Files
To uncompress these files, use the following commands:
- For bzip2:
bunzip2 - For gzip:
gunzip - For xz:
unxz:::
zcat, bzcat, and xzcat allow you to read compressed files without manual decompression.