A very common problem, especially in development environments where a lot of people and even different teams share the same servers, is running out of space in them. In general, due to a lack of maintenence tasks for these servers. Old logs never deleted, temporal files that have been there forever, this kind of things. All this things makes sometimes impossible to deploy our applications because we are running out of space. In these cases, we need to find what is exactly consuming this space.
To do that, we have in *nix systems some useful console commands or combination of commands.
The first one, it is useful to now the status of the space in our servers.
df -h
The result should be something similar to this. Probably with more lines because I have only pasted a couple of them.
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk0s2 111Gi 51Gi 60Gi 47% 13428490 15666812 46% /
/dev/disk1s2 149Gi 63Gi 86Gi 43% 16540268 22448478 42% /Volumes/HD
The first combination of command that we are going to see is useful to find the biggest X files or directories in a specific location and its subfolders. In this case, I am going to find the biggest ten files or directories in the location /Volumes/HD:
du -a /Volumes/HD | sort -n -r | head -n 10
The result should be something like:
87657984 /Volumes/HD/folder001
44418920 /Volumes/HD/folder002
29209808 /Volumes/HD/folder003
13658736 /Volumes/HD/folder004
10394096 /Volumes/HD/folder005
10394096 /Volumes/HD/folder001/file001
10361792 /Volumes/HD/folder002/file002
10360368 /Volumes/HD/folder001/folder003/file003
10100704 /Volumes/HD/folder001/folder003/folder004/file004
10100704 /Volumes/HD/file005
Another very useful command that we already know from previous post is find. It works slightly different, this command can help us to find files bigger than a given size. For example, let’s try to find files with more than two gigabytes in our system
find /Volumes/HD -size +2G -exec ls -sd {} +
The result should be something like:
10394096 /Volumes/HD/folder001/file001
10361792 /Volumes/HD/folder002/file002
10360368 /Volumes/HD/folder001/folder003/file003
10100704 /Volumes/HD/folder001/folder003/folder004/file004
10100704 /Volumes/HD/file005
10100217 /Volumes/HD/file006
With these two combinations of commands probably your life will be easier next time you run out of space in your development server.
In any case, a good advice should be take care of your development servers, do not leave them to arrive to this situation because this kind of things always happens in the worst moments.
See you.