To stay up to date, remember to subscribe to our YouTube channel!
SUBSCRIBE ON YOUTUBE
When working with folders and files in Linux, it is ideal to know certain administration options about them and one of the most important is to know their size or weight, it is ideal because a large folder and little use can affect disk space hard or you can see a slowdown of the normal processes of the system, although it is true that we can graphically see the size of a folder, there are some hidden ones or we will not always have the time to access each path and that is why in Linux we have a command that will be our ally in this task and we are talking about the du command..
Du is an ideal Linux command to display the use of hard disk space for both files and directories, its operation works recursively for directories.
parameters
When using du we have some usage parameters such as:
- -0, --null: end each line with NUL,L but not with a new line
- -a, --all: display results for all files and not just directories
- --apparent-size: output the apparent sizes but not the actual disk usage
- -B, --block-size=SIZE : adjust sizes by size before generating the result
- -b, --bytes: output the result in bytes
- -c, --total: output the total size at the end of the results
- -d, --max-depth=N: create the total size for a directory
- -h, --human-readable: show us the sizes in a readable way
- -k: show the size in kilobytes
- L, --dereference: keep track of all symbolic links
- -m : show the size in megabytes
- -S, --separate-dirs: applies to directories and does not include the size of subdirectories
- -s, --summarize: output only the total for each argument
- --time: display the date and time of the last modification
- --time-style=STYLE: display dates and times using the STYLE style in which we can use full-iso, long-iso, iso
- -X, --exclude-from=FILE: excludes the files that we indicate
- -x, --one-file-system: jump over other filesystem directories if they exist
TechnoWikis will explain in a simple way how to access these folder size details in Linux with du..
How to see folder size in Linux
Step 1
To start we open the terminal and if we want to see a summary of the use of the hard disk we will execute the following command on the screen with the path to analyze:
du /home/name
Step 2
We go to the end of the terminal to see all the results. There we find details of the size and path of the folder or file.
Step 3
If we want to see the results in a readable format, we must execute adding the -h parameter as follows:
du -h /home/name
Step 4
We go to the end to see the total results. We can now see in the size column the value much clearer.
step 5
If the goal is to see the total disk usage, we are going to add the -s option as follows:
du -sh /home/name
step 6
There we see only the total size of the specified path. It is possible to see all files and directories using the -a parameter as follows:
du -a /home/name
step 7
As a result we will see the following:
step 8
Now you can add the above command to the -h option for a more readable format:
du -ah /home/name
step 9
Pressing Enter we will see this:
step 10
We can see the size on disk in kilobytes by using the -k option:
du -k /home/name
step 11
As a result we will see the following:
step 12
You can also see the size in megabytes using the -m parameter:
du -mh /home/name
step 13
When pressing Enter we will see the following result:
step 14
Now we can see the total used disk space at the bottom of the results with the -c option:
du -ch /home/name
step 15
The result obtained will be the following:
step 16
In order not to use all files in the search, it is possible to exclude some file types using the following command:
du -ah --exclude="*.extension" /home/name
step 17
As a result these types of files will not be in the result:
step 18
Finally, it is possible to see the results with the modification date for a more precise control of these with the following syntax:
du -ha --time /home/name
step 19
There we can see a new column with the details of the date and time in which that folder or file suffered any modification:
Thanks to each of these du command options, it will be possible to have full control over the size of the folders in Linux and thus carry out specific administration tasks if necessary.