+4 votes
37 views
View Linux Folder and File Size

in Linux/Unix by (551k points)
reopened | 37 views

1 Answer

+5 votes
Best answer

How to see folder size in Linux

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 
image

 

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.

 

image

 

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 
image

 

Step 4

We go to the end to see the total results. We can now see in the size column the value much clearer.

 

image

 

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 
image

 

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 
image

 

step 7

As a result we will see the following:

 

image

 

step 8

Now you can add the above command to the -h option for a more readable format:
 du -ah /home/name 
image

 

step 9

Pressing Enter we will see this:

 

image

 

step 10

We can see the size on disk in kilobytes by using the -k option:
 du -k /home/name 
image

 

step 11

As a result we will see the following:

 

image

 

step 12

You can also see the size in megabytes using the -m parameter:
 du -mh /home/name 
image

 

step 13

When pressing Enter we will see the following result:

 

image

 

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 
image

 

step 15

The result obtained will be the following:

 

image

 

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 
image

 

step 17

As a result these types of files will not be in the result:

 

image

 

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 
image

 

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:

 

image

 

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.

 


by (3.5m points)
edited

Related questions

+4 votes
1 answer
asked Nov 1, 2019 in Mac by backtothefuture (551k points) | 222 views
+4 votes
1 answer
asked Oct 20, 2019 in Windows 10 by backtothefuture (551k points) | 223 views
+5 votes
1 answer
asked May 22, 2019 in Linux / Unix by backtothefuture (551k points) | 208 views
+5 votes
1 answer
asked Sep 7, 2023 in Linux/Unix by backtothefuture (551k points) | 29 views
+5 votes
1 answer
asked Jun 20, 2023 in Linux/Unix by backtothefuture (551k points) | 39 views
Sponsored articles cost $40 per post. You can contact us via Feedback
10,634 questions
10,766 answers
510 comments
3 users