CAll Us: +1 888-999-8231 Submit Ticket

How to Investigate Disk Space Usage From the Command Line

How to Investigate Disk Space Usage From the Command LineEach of our plans establishes a disk-usage limit. If you receive an email with an alert that says you’re nearing this limit, ignoring it can hamper the operability of your website and other associated services, such as email.

Before you call our Sales team to ask about an upgrade, it’s almost always worthwhile to investigate the cause of this usage. Common unknown sources of data are large log files, old backups, full size media, or email. The most efficient way to determine the exact cause involves the command line.

If you have little-to-none experience with the command line, start with the ncdu command. If you’re no stranger to the command line, find and du may be of more interest to you. In addition to finding problem files, they can give you a better understanding of your site’s file structure and operation.


The ncdu command can quickly locate the source of high disk usage with minimal command line experience. This command provides a numerical output, as well as a visual indicator of the most space-hungry files.

Run the command ncdu, then use the arrow keys on your keyboard to navigate. The up and down keys go through the list vertically. The right arrow goes deeper into directories, and the left key withdraws from directories.

The following shows some example output:

 ncdu 1.12 ~ Use the arrow keys to navigate, press ? for help
--- /chroot/home/examplec/ ---------------------
501.6 MiB [##########] /vendor
228.0 MiB [#### ] /var
76.6 MiB [# ] /dev
27.3 MiB [ ] /lib
21.2 MiB [ ] /update
12.9 MiB [ ] /setup
5.6 MiB [ ] /generated
660.0 KiB [ ] composer.lock
428.0 KiB [ ]
316.0 KiB [ ] /pub
196.0 KiB [ ] /app
40.0 KiB [ ] /.github
16.0 KiB [ ] /phpserver
12.0 KiB [ ] .htaccess.sample
12.0 KiB [ ] .htaccess
12.0 KiB [ ] LICENSE_AFL.txt
12.0 KiB [ ] LICENSE.txt
12.0 KiB [ ] /bin
8.0 KiB [ ] index.html
8.0 KiB [ ] nginx.conf.sample
e 4.0 KiB [ ] /cgi-bin
4.0 KiB [ ] Gruntfile.js.sample
4.0 KiB [ ] composer.json
4.0 KiB [ ] .travis.yml
4.0 KiB [ ] .php_cs.dist
4.0 KiB [ ] .gitignore
4.0 KiB [ ] package.json.sample
4.0 KiB [ ] index.php
4.0 KiB [ ] robots.txt
4.0 KiB [ ] php.ini.sample
4.0 KiB [ ] COPYING.txt
4.0 KiB [ ] auth.json.sample
4.0 KiB [ ] .user.ini
4.0 KiB [ ] grunt-config.json.sample
4.0 KiB [ ] magento_umask
Total disk usage: 875.0 MiB Apparent size: 710.2 MiB Items: 92561

find and du

The find command can help locate files using a large amount of disk space, and you can even designate the size of files to locate.

The below command searches for any file that is larger than 10 megabytes (MB) in your working directory or lower.

find -type f -size +10M

The type -f  command looks only for files, and the -size +10M command looks for anything larger than 10 MB.

When executed, the output looks something like:

$ find -type f -size +10M

You can refine the find command further by combining it with the du command, which will show the size of the files.

$ find -type f -size +50M -exec du -h {} ;
107M ./html/var/log/system.log
111M ./html/var/backups/1546966441_filesystem_code.tgz
118M ./iworx-backup/

In the above example, the -exec command executes a command on the files found by find command. In this case, it’s the du command with the -h flag, which provides output in a human-readable format. The {} orders the command to run on the found files, and the ; indicates there are no further arguments.

The du command can also be used independently to list the size of files and folders, providing output like:

du -sch *
196K app
4.0K auth.json.sample
12K bin
4.0K cgi-bin
4.0K composer.json
660K composer.lock
4.0K COPYING.txt
77M dev
5.7M generated
4.0K grunt-config.json.sample
4.0K Gruntfile.js.sample
8.0K index.html
4.0K index.php
28M lib
4.0K magento_umask
8.0K nginx.conf.sample
4.0K package.json.sample
4.0K php.ini.sample
16K phpserver
316K pub
4.0K robots.txt
13M setup
22M update
228M var
502M vendor
875M total

You have several good options for arguments. The -s argument gives the total usage of a directory and its contents, the -c argument provides a grand total of all of the contents on the last line, and the -h argument outputs the contents in a human-readable form.

For more examples of du output, see our blog article, Sorting the Output of du.

About the Author

Christopher Jarvis

Christopher Jarvis has been assisting our clients for nearly 7 years as a member of our support staff.





Posted in:

Source link

About the Author

Leave a Reply