~ Dedicated to Linux beginners ~ Primitive but reliable disc cleaning tech

One day, a young development person I met at work seems to have some trouble on his server.

"Something ... something ... the application has stopped working ..."

What did you do?

"Something ... something ... this kind of English comes out ..."

Pilon (Slack notification sound) No space left on device

You can say that much English with a mouse. Well, young people, don't be afraid. Do you know the df and du commands?

I thought that it was something I didn't know, and I taught him the solution.

Let's grasp the current situation in both rabbits and horns

I'm using Ubuntu, a Linux-based distribution, so I'll explain it using that as an example.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.9G     0  2.9G   0% /dev
tmpfs           597M  1.4M  595M   1% /run
/dev/sda2        80G   79G    1G 100% /← here
tmpfs           3.0G     0  3.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.0G     0  3.0G   0% /sys/fs/cgroup
/dev/loop0       94M   94M     0 100% /snap/core/9066
/dev/loop1       98M   98M     0 100% /snap/core/9289
tmpfs           597M     0  597M   0% /run/user/1000

There are several partitions, but in my case it is / one, so I think the above is the minimum configuration of Ubuntu. You can see that / is using 79G in 80G and there is only 1G left.

It smells muddy, but the surest way is to just repeat the du command.

du is a command that aggregates and displays the disk usage for each directory. [Du] command-display disk usage

If you have no idea where the files are bloated, start with the top level /. If there is a hit, start under that directory. If you use it obediently, it will be around / home`` / usr / `` / var.

Options for the du command

---h The default is Byte notation, so Mega, Giga notation for easy viewing If you have a large number of directories, it may be easier to tell at a glance if you do not add them. ---d How many times do you go under the layer? This time, for the sake of clarity, repeat for each 1 hierarchy.

$ sudo du -hd 1 /
15M     /bin
142M    /boot
0       /dev
5.4M    /etc
4.4G    /home
838M    /lib
0       /lib64
0       /media
0       /mnt
0       /opt
...abridgement...

I've omitted a part, but it seems that 4.4G is taken by / home, so let's explore here next.

$ sudo du -hd 1 /home
4.4G    /home/nyamane
32K     /home/kamaitachi
4.4G    /home/

You can see that my home directory is almost full. Next, let's explore my home directory. If there are many directories, it may be difficult to distinguish if M or G is lined up, so try taking the -h option.

$ sudo du -d 1 /home/nyamane/
40420   /home/nyamane/.cache
0       /home/nyamane/.gnupg
16      /home/nyamane/.ssh
3444    /home/nyamane/.config
2251960 /home/nyamane/repos
0       /home/nyamane/snap
87396   /home/nyamane/pkgs
11436   /home/nyamane/.kube
4       /home/nyamane/.k9s
4       /home/nyamane/.docker
1316    /home/nyamane/.kubectx
41556   /home/nyamane/google-cloud-sdk.staging
159004  /home/nyamane/google-cloud-sdk
1103432 /home/nyamane/.vscode-server
357428  /home/nyamane/.npm
366672  /home/nyamane/.rbenv
4892    /home/nyamane/.gem
27016   /home/nyamane/.solargraph
59920   /home/nyamane/.local
80      /home/nyamane/.pylint.d
4516088 /home/nyamane/

/ home / nyamane / repos about 2.2GB /home/nyamane/.vscode-server about 1.1GB

Well, you're finally getting closer to the core. This is the directory that puts together my development repositories. All you have to do now is repeat the work as it is and proceed step by step. Assuming that you finally searched to the bottom layer, let's finally find out to the file unit with ls.

$ ls -laF /home/nyamane/repos/some_repos/logs

As a result of checking with ls, I found that the file development.log is large, so let's delete it.

$ rm -f /home/nyamane/repos/some_repos/logs/development.log

Congratulations. Now you have + a few GB of disk space.

in conclusion

This time it was a development log file output by my application, so I just rm, but it is also necessary to judge whether it is a file that can be deleted in the first place, so it is necessary to investigate and deal with it as appropriate. there is. Please note that if you erase it without thinking about it, you may get hurt.

If the disk capacity often hits the ceiling, the capacity setting is strict in the first place, so consider expanding the disk size or replacing the HDD. If the server is used for development, it is possible that the application logs too much.

Recommended Posts

~ Dedicated to Linux beginners ~ Primitive but reliable disc cleaning tech