Where did all my space go on Ubuntu/Linux?
Occasionally we’ll get calls from clients that don’t have service agreements with us and say something like, “our site keeps going down or is unresponsive.” Once they confirm that no one has made any changes, we’ll start checking logs and debugging the situation. We always host WordPress sites on secured virtual private cloud servers so we can lock them down and really decrease the chances of the site being hacked from the server side or through another site on a shared server.
On some of these small sites, we use little droplets that have maybe 15 to 30GB of space. More times than not, this error they are experiencing happens because the server has run out of space from logs or from them uploading a bunch of files.
There’s a couple quick server commands that can be ran to check where all the space has gone or if this is even an issue. We use Ubuntu, so check your specific flavor of linux.
First, let’s check and see if it’s an issue.
SSH into your server and run:
You’ll see the output and be able to determine if space is an issue for you
Filesystem Size Used Avail Use% Mounted on udev 992M 0 992M 0% /dev tmpfs 201M 21M 180M 11% /run /dev/vda1 49G 12G 37G 25% / tmpfs 1001M 0 1001M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 1001M 0 1001M 0% /sys/fs/cgroup tmpfs 201M 0 201M 0% /run/user/1000
Here, space is not an issue, but if it was, the next thing you would want to do is figure out what is taking up all that space.
There is a super handy tool called
ncdu that you can use to do this. If you don’t have it already, you’ll need to install it on your server. You can do that by running:
sudo apt-get install ncdu
You can use it by either browsing to the directory that you want to inspect and typing
ncdu or by typing the path you want to inspect. Since we don’t know where the space is being used we will use the root directory:
It will start a scan
Once it has finished, You’ll see a list of directories and the size that each directory/file is taking up.
You can use the arrows to navigate.
- UP ARROW – Move cursor up
- DOWN ARROW – Move cursor down
- RIGHT ARROW – Open the currently selected directory
- LEFT ARROW – Go back a directory (open parent directory)
Here’s a list of all the commands (you can type
q to open the help):
k– Move cursor up
j– Move cursor down
enter– Open selected directory
h– Open parent directory
n– Sort by name (ascending/descending)
s– Sort by size (ascending/descending)
C– Sort by items (ascending/descending)
d– Delete selected file or directory
t– Toggle dirs before files when sorting
g– Show percentage and/or graph
a– Toggle between apparent size and disk usage
c– Toggle display of child item counts
e– Show/hide hidden or excluded files
i– Show information about selected item
r– Recalculate the current directory
b– Spawn shell in current directory
q– Quit ncdu
Looking for someone to manage your site? Call us and get a service agreement