Linux / Ubuntu, finding large size files / directories.

By | December 19, 2016

When you use your computer, you may need to delete some files because of insufficient storage space. If you do not want to delete large files, I want to find out how to find those large files.

There are many ways to know the file size in Linux. You can use the commonly used ls, or you can use du. Here we try to use du.

# du -s

# du -sh

“du -s” shows the total size of the current directory, including all sub-directories, in kilobytes (KB).

If you attach the h option like “du -sh”, it will show human-readable in a more user-friendly unit. In the example below, it is 8719788 KB, so it shows 8.4G.

# du -sh *

“du -sh *” shows information about [current directory files + sub-directories] one by one. Just the hidden files are not shown. That is, only the capacity of the file / directory shown when ls is displayed is shown.

# du -h –max-depth=1

If you want to see the size of the files / directories that appear when you include ls -a with hidden files, you can do “du -h –max-depth = 1”.

# du -sh * | sort -hr

#┬ádu -h –max-depth=1 | sort -hr

If you do not have a few files / directories, you can quickly see what’s biggest and what’s the smallest. However, if the number of objects increases, it is better to use sort. In the command that executed above | If sort -hr is given, sorting is possible in order of size.

Sort is basically a command to sort the text. When the result is expressed as human-readable as above, it may be difficult to sort by simple text alignment. Thus, the -h option is given to sort by human-readable criteria, and the -r option is added to show the order in large order.

In this way, you can follow the largest files / directories and delete them whenever unnecessary files / directories appear.

One thought on “Linux / Ubuntu, finding large size files / directories.

Leave a Reply

Your email address will not be published. Required fields are marked *