
That's why the 4.0KB is more or less the same for every folder, but it doesn't say anything about the contents. Not all folders are the same size, so why is that? The reason is that the 4.0KB represents the size it takes on the disk to store the meta-information about the folder itself, like the name of the folder and the position.

However, for folders it will always show 4.0KB. The -h flag is additional for the human readable sizesĪs you might notice, this command works great for simple files.The -a flag tells the command to also list hidden files that start with a.The -s flag tells the command to show the file sizes in human readable formats like KB, MB and GB.The -l flag says to list the files in a neat ordered vertical list, so that more information can be shown.This will search for files greater than 2GB, while showing us the size of the files. Using the following command, we can execute the ls command whenever find comes across a file matching our criteria. The -lsah consists of 4 separate flags: size +2G -size -5G One problem with the find command in this case is that it doesn’t reveal the file sizes of the files it finds.The ls command lists all files and folders in the current directory.I truncated the results a bit, but this is obviously a directory with a Laravel app in it. You can cd into these directories, run the same command again to find big folders and so forth. These directories we will need to investigate. Next, there are several bigger directories, that each take up a few hundred MB, like the and the -deploy directory.įinally, there are two big directories, the and directories. If omitted, it will list recursively check every directory and list every file it finds, which obviously isn't useful for us now.įirst, the total folder size is 8.9GB. The -max-depth=1 tells the command that it should only list files and folders in the current directory.tells the command that we want to start from the current directory The -h flag tells the command to show file sizes in human readable formats (like KB, MB and GB).Those are some of the ways you find directories larger than 1GB, or any other size you desire for that matter. You can also sort the first command like this too, in which case you’re combining the three commands into one: # du -h -max-depth=1 / | grep 'G\>' | sort -hr If you want it to display all directories, not just first level, just leave out the -d 1 option.įinally, as a bonus, you can sort the results from largest to smallest by piping in the sort command: # du -h -d 1 -t 1G / | sort -hr It will display first level directories larger than 1GB within the root / path, just like the first command. You can use the built in -t or –threshold option of the du command like this: # du -h -d 1 -t 1G / This single command is all you need for this task, but there’s an even shorter one that works well too. To specify a certain directory, add the relative path after the find command. It’s possible to also add a filter with the minimum size of 100MB. Here’s another example of this command, but with –max-depth=1 being shortened to -d 1, which works the same, and checking the /var directory instead of the root / directory. To find the largest files inside your current working directory, type the following: find. If you put (asterisk) with the command then.

So the grep ‘G>’ searches through the du output and displays only the files that are larger than 1GB. The command used to view the size of files and directories is du -sh to check the size of current directory. The | sign is the pipe sign that allows combining the first command with the next command, in this case grep, which is used for searching through text output for the specified strings, which can be specified through regular expressions. If we were to specify 2 it would go a level further and also look into directories like /home/user, /usr/bin, /var/log, etc. The –max-depth=1 option makes it display the sizes of only the directories immediately within the specified path, in this case the root path /, which in Linux includes directories like /home, /usr, /bin, /var, and so on. The -h option displays the sizes in a more human readable format, in gigabytes rather than kilobytes. So to find directories that are larger than 1GB you can run this command: du -h -max-depth=1 / | grep 'G\>'

The du command can be used with options that allow you to customize the results you get.Ĭommands can also be combined with each other so the second command filters the results output by the first command. Finding out sizes of files and directories in Linux is done using the du command, which estimates their disk space usage.
