Support the ongoing development of Laravel.io →
Article Hero Image

Managing Disk Space With "ncdu"

6 Jan, 2022 3 min read

Photo by benjamin lehman on Unsplash

Linux ships with a useful command named du (Disk Usage), which is used to determine the size of files and directories. When provisioning your server, Forge installs ncdu which is an advanced version of du that allows you to easily navigate your directories via an ncurses interface. This makes it much quicker to identify large files and directories.

Sometimes, you may find that Forge was unable to perform an operation on your server because there is no free disk spaces available. This is often caused by one or two large files that can be removed; however, locating these files is sometimes tricky.

To find large files on your server, you may use ncdu to navigate around common directories on our server. As the root user, you should cd / and run ncdu. The command will scan the directory and its children. Once it's done scanning you will see a list of directories and their sizes.

The ncdu interface

Notice at the bottom of the terminal window we’re also shown total disk usage, apparent size, and the number of items.

To navigate the interface we can use the up and down arrows to select a directory, then right (or return) to enter the directory, and left to move back up.

In the screenshot above we can see that the server’s /var directory is the largest directory at 2.0 GiB. Let’s move into that directory by hitting return.

Switching directory

We’re now shown all of the files and directories within /var ordered by size. Next, we’ll move into the log directory as it’s looking bigger than the rest.

The /var/log directory

The /var/log/journal directory is the biggest. It’s safe to delete files within this directory but do not delete the directory itself.

To delete a file, first select it using the arrow keys and then press d. You’ll be asked to confirm that you want to delete the file.

Deleting a file

If your log directory is small in size and you’re still seeing errors related to disk usage, you may also want to navigate to the /home/forge directory.

When Forge executes an action on your server it first uploads a script to your server. You can find these script files in directories such as /root/.forge and /home/forge/.forge. When the script is executed, Forge will pipe and store the output to a .output file.

Forge configures your server to periodically remove these files to save disk space automatically.

Sometimes it may be necessary to remove these .output files earlier than the scheduled clean up. Thankfully, ncdu makes this really easy to do.

Last updated 1 month ago.

joelbutcher, driesvints, phcostabh liked this article

3
Like this article? Let the author know and give them a clap!

Other articles you might like

Article Hero Image November 18th 2024

Laravel Custom Query Builders Over Scopes

Hello 👋 Alright, let's talk about Query Scopes. They're awesome, they make queries much easier to r...

Read article
Article Hero Image November 19th 2024

Access Laravel before and after running Pest tests

How to access the Laravel ecosystem by simulating the beforeAll and afterAll methods in a Pest test....

Read article
Article Hero Image November 11th 2024

🍣 Sushi — Your Eloquent model driver for other data sources

In Laravel projects, we usually store data in databases, create tables, and run migrations. But not...

Read article

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.