What is du –exclude Command in Linux?


In Linux, the “du” command is used to estimate file space usage. It is a very useful tool for finding out which directories or files are taking up the most disk space on a system. However, sometimes we may want to exclude certain directories or files from the output of the “du” command. In such cases, the “du –exclude” command can come in handy. This article we will discuss what the “du –exclude” command is in Linux and provide two examples to help illustrate its usage, further I will be using Linux Mint 21 distro for that.

What is du –exclude command in Linux?

The “du –exclude” command is a Linux command that allows you to exclude specific directories or files from the output of the “du” command. This can be useful when you want to focus only on certain directories or files and exclude the rest. The “–exclude” option can be used with the “du” command to specify directories or files that should be excluded from the output.

How to use du –exclude command in Linux?

To use the “du –exclude” command in Linux, you need to follow the below given syntax:

du --exclude=[directory or file name] [directory path]

Example 1: Exclude a Directory from the Output of the “du” Command

Let’s say you want to exclude a directory called “temp” from the output of the “du” command. To do this, you can use the following command:

 

du --exclude=Documents /home/linux/

In this example, the “du” command will display the disk usage of the “/home/user/” directory but exclude the “Documents” directory from the output:

Example 2: Exclude a File from the Output of the “du” Command

Suppose you want to exclude a file called “myfile.txt” from the output of the “du” command. To do this, you can use the following command:

du --exclude=myfile.txt /home/user/

In this example, the “du” command will display the disk usage of the “/home/user/” directory but exclude the “myfile.txt” file from the output:

Conclusion

The “du –exclude” command is a useful Linux command that allows you to exclude specific directories or files from the output of the “du” command. It is a handy tool when you want to focus only on certain directories or files and exclude the rest. In this article, we discussed what the “du –exclude” command is in Linux and how to use it. We also provided two examples to help illustrate its usage. By using the “du –exclude” command, you can efficiently estimate file space usage and get more accurate results.

Print Friendly, PDF & Email