
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
Tracking Down Where Disk Space Has Gone on Linux
As a Linux user, you might have come across a situation where you ran out of disk space, but you are not sure where all space has gone. It can be frustrating, but fortunately, there are several tools and techniques you can use to track down where disk space has gone on Linux.
In this article, we will cover following sub-headings to help you identify where your disk space has gone −
Check Disk Usage
The first thing to do is to check disk usage of your system. Linux has several command-line tools that can help you do that. most common tool is "du" command, which shows disk usage of a directory.
For example, if you want to see disk usage of current directory, you can run following command −
$ du -sh
The "-s" option shows total size of directory, while "-h" option makes output human-readable.
If you want to see disk usage of a specific directory, you can replace "." in command with path of directory.
$ du -sh /path/to/directory
If you want to see disk usage of all directories in current directory, you can run following command −
$ du -h --max-depth=1
The "--max-depth=1" option tells "du" command to only show disk usage of directories in current directory, and not their subdirectories.
Identify Large Files
Once you have identified directories that are taking up most of disk space, next step is to identify large files in those directories. You can use "find" command to do that.
For example, if you want to find all files larger than 100MB in current directory and its subdirectories, you can run following command −
$ find . -type f -size +100M -exec ls -lh {} \;
The "." in command tells "find" command to search in current directory and its subdirectories. "-type f" option tells command to only search for files. "-size +100M" option tells command to only show files that are larger than 100MB. "-exec ls -lh {} ;" option tells command to execute "ls -lh" command on each file that matches search criteria.
Check Log Files
Log files can also take up a lot of disk space, especially if you have not configured them properly. Linux has several log files that you can check to see if they are taking up too much disk space.
The most common log files are "syslog" and "auth.log" files. You can check size of these files using "ls" command.
$ ls -lh /var/log/syslog $ ls -lh /var/log/auth.log
If these files are taking up too much disk space, you can either delete them or configure your system to rotate them.
Check Trash
If you have deleted files from your system, they might still be taking up disk space in trash. Linux has a trash directory where deleted files are stored until you empty trash.
You can check size of trash directory using "du" command.
$ du -sh ~/.local/share/Trash/
If trash is taking up too much disk space, you can empty it using following command −
$ rm -rf ~/.local/share/Trash/*
Check Package Cache
Linux uses package managers to install and manage software. These package managers download packages from internet and store them in a cache directory. If you have installed a lot of software on your system, package cache can take up a lot of disk space.
You can check size of package cache using following command −
$ du -sh /var/cache/apt/archives/
This command is specific to "apt" package manager used in Debian-based distributions. If you are using a different package manager, you will need to replace "/var/cache/apt/archives/" with path of package cache directory for your package manager.
If package cache is taking up too much disk space, you can clear it using following command −
$ sudo apt-get clean
This command will remove all packages from package cache that are no longer needed.
Check Temporary Files
Linux uses temporary files for various purposes, such as storing data during software installation, downloading files from internet, and storing user session data. If these temporary files are not cleaned up regularly, they can take up a lot of disk space.
You can check size of temporary files using following command −
$ du -sh /tmp/
If temporary files are taking up too much disk space, you can clear them using following command −
$ sudo rm -rf /tmp/*
This command will remove all files and directories in temporary directory.
Use Disk Usage Analyzers
If you find it difficult to identify where your disk space has gone using command-line tools, you can use disk usage analyzers. These are graphical tools that provide a visual representation of disk usage of your system.
There are several disk usage analyzers available for Linux, such as Baobab, Disk Usage Analyzer, and K4DirStat. These tools can scan your system and display disk usage of each directory and file in a graphical format.
Use a Disk Space Usage Tool
Another way to track down where disk space has gone on Linux is by using a disk space usage tool like ncdu. Ncdu is a command-line utility that shows you size of directories and files in your system, and you can interact with tool using keyboard. Here is how to use ncdu −
Install ncdu on your Linux system. On Ubuntu, you can use following command −
sudo apt-get install ncdu
Once you have installed ncdu, you can run following command to scan your system −
ncdu /
This will scan your entire system and show you size of directories and files. You can use arrow keys to navigate through directories and press Enter key to open a directory.
If you want to scan a specific directory, you can run following command −
ncdu /path/to/directory
Replace "/path/to/directory" with path to directory you want to scan.
Check Size of Home Directories
In Linux, each user has a home directory where their files and data are stored. Sometimes, size of home directories can grow very large, especially if user is storing a lot of files or data. To check size of home directories, you can use following command −
du -sh /home/*
This will show you size of each home directory. If you find that a particular user's home directory is taking up too much disk space, you can talk to user and ask them to clean up their files.
Check Size of System Logs
System logs are files that record information about system and its operations. These logs can grow very large over time, and if you don't clean them up regularly, they can take up a lot of disk space. To check size of system logs, you can use following command −
sudo du -sh /var/log/*
This will show you size of each log file in "/var/log" directory. If you find that a particular log file is taking up too much disk space, you can either delete file or compress it using a tool like gzip.
Conclusion
In conclusion, tracking down where disk space has gone on Linux can be a daunting task, but with right tools and techniques, it can be a simple process. By checking disk usage, identifying large files, checking log files, trash, package cache, temporary files, and using disk usage analyzers, you can quickly identify where your disk space has gone and take appropriate action to free up space.
- Related Articles
- Guide to Monitoring Disk Usage on Linux
- How to Format a Hard Disk on Linux OS
- Find free disk space using Java
- Find free disk space using C#
- BleachBit – A Free Disk Space Cleaner
- How to Increase Swap Space on Linux Ubuntu?
- How to find out bad sectors on your linux hard disk
- How to Add Disk Storage to Oracle Virtual Box on Linux
- Where should the Google Analytics Tracking Code be placed?
- Great tools to check linux disk partitions and usage in linux
- How to Increase Disk Inode Number in Linux
- How to list down all the available commands and aliases on Linux?
- 3 Useful GUI and Terminal Based Linux Disk Scanning Tools
- 5 Best Open Source Disk CloningBackup Tools for Linux Servers
- How to check total space and available space in Linux using the terminal?
