Applying Exclusion Techniques
Now that you understand the basics of excluding files and directories from the du
command output, let's explore some practical examples of how to apply these techniques.
Excluding Temporary Files and Directories
Temporary files and directories are often created by various applications and can significantly contribute to the disk usage report. To exclude these, you can use the --exclude
option with common temporary file extensions or directory names:
$ du --exclude='*.tmp' --exclude-directory='/tmp' .
12K ./file1.txt
8.0K ./file2.txt
20K .
In this example, the du
command excludes all files with the .tmp
extension and the /tmp
directory from the disk usage report.
Excluding Version Control Directories
If your project uses a version control system like Git, the associated directories (e.g., .git/
) can be excluded from the du
command output:
$ du --exclude-directory='.git' .
12K ./file1.txt
8.0K ./file2.txt
20K .
This ensures that the disk usage report focuses on the actual project files and directories, rather than the version control-related data.
Excluding Specific File Patterns
You can also exclude files based on specific patterns, such as file extensions or partial file names. This can be useful when you want to focus on a particular type of file or exclude certain types of backup or log files. For example:
$ du --exclude='*.log' --exclude='*backup*' .
12K ./file1.txt
8.0K ./file2.txt
20K .
In this case, the du
command excludes all files with the .log
extension and any files or directories containing the word "backup".
By applying these exclusion techniques, you can tailor the du
command output to suit your specific needs and gain a better understanding of the disk space usage in your Linux system.