This module describes how to manage disk space. First you will learn about the
du
command, which has several options for displaying the size of files and directories. This module also
explains how to save disk space by using file compression. You will learn the
compress
,
uncompress
, and
zcat
commands. Finally, you will learn to work with archives in various ways by using the
tar
command.
By the end of this module, you will be able to:
- Use
du
to display your disk usage
- Use
compress
and uncompress
to manage file sizes
- Use
zcat
to view compressed files
- Describe an archive
- Use
tar
cvf
to create an archive
- Use
tar
tf
to list the file names in an archive
- Use
tar
xvf
to extract files from an archive
Managing space on a Unix system effectively involves a combination of proactive monitoring, efficient usage, and regular housekeeping. Here are some best practices:
-
Monitor Disk Usage
- `df` Command: Use
df -h
to check disk usage by file systems in a human-readable format.
- `du` Command: Use
du -sh /path/to/directory
to analyze the disk usage of specific directories.
- Disk Usage Analyzers: Tools like
ncdu
or baobab
provide a visual or interactive way to analyze disk usage.
-
Identify and Remove Unused Files
-
Manage Installed Packages
- Remove Unused Packages: Use package managers (
apt
, yum
, dnf
, etc.) to uninstall unnecessary software.
sudo apt autoremove
- Clean Cache:
- For APT:
sudo apt clean
- For YUM/DNF:
sudo yum clean all
-
Automate Maintenance
- Schedule regular checks with
cron
jobs.
- Use scripts to monitor and clean up disk space, sending email notifications for low disk warnings.
-
Compress Files and Directories
-
Optimize File Systems
- Enable quotas to limit user or group disk usage.
- Use filesystem-specific tools (e.g.,
xfs_growfs
, e2fsck
) to manage and optimize the filesystem.
-
Separate Critical Partitions
- Use separate partitions for
/var
, /home
, /tmp
, and logs to isolate potential space hogs.
-
Archive and Backup
- Move rarely used data to external storage or archive.
- Use tools like
rsync
or cloud solutions to maintain off-site backups.
-
Regular Monitoring
- Use system monitoring tools like
nagios
, zabbix
, or prometheus
for real-time space tracking and alerts.
-
Advanced Techniques
- LVM (Logical Volume Management): Allows dynamic resizing of disk space.
- ZFS/Btrfs: Use advanced file systems that offer built-in compression, deduplication, and snapshot features.
By adopting these strategies, you can maintain a well-organized and efficient Unix system, minimizing space-related issues.
In the next lesson, you will learn to display your disk usage with the
du
command.