When you start getting disk full messages on Linux, there's a few different reasons why that might happen:
-
The expected. Too many large files. You can track down large directories using WinDirStat or
du -hx --max-depth=1 | sort -h
where the-x
option tellsdu
to not cross filesystem boundaries and the-h
option to both useshuman-readable
sizes like11M
or1G
. -
Deleted files aren't actually deleted if they are still open. You can use
lsof
to find open files. Give it the filesystem as an argument likelsof /home
. -
By default 5% of each filesystem is reserved for writes by
root
. Depending on what the filesystem is being used for, this may be too much or simply unnecessary. See this Server Fault answer for how to deal with this. -
The files could be shadowed by a mount. If a filesystem is mounted over a non-empty directory, the files in that directory aren't visible.
-
Last, the disk might not actually be out of space at all. It might actually be out of inodes. Some filesystems, notably the ext2/3/4 filesystems used by default on most Linux distributions have a fixed number of inodes allocated at filesystem creation time. The default is high enough that it is unlikely to be an issue unless there are a very large number of empty files.
df -i
will show the number of inodes free on each filesystem to verify if a filesystem is indeed out of inodes.But how do you find those empty files? As described above,
du
will help find large files, but now we want to find large numbers of files. The following command acts likedu -hx --max-depth=$depth | sort -h
for inodes instead of file sizes:find -xdev | sed "s@\(\([^/]*/\)\{$depth\}[^/]*\).*@\1@" | uniq -c | sort -n
find -xdev
lists all of the files under the current directory on the same filesystem. Thesed
command finds the first$depth
directories (ending in/
) and discards the rest of the filename (the.*
at the end), so each directory appears once for every file or directory anywhere under it. Then the end of the command counts the repeated lines and sorts by those counts, highlighting the directories with the most files.
Comments
Have something to add? Post a comment by sending an email to comments@aweirdimagination.net. You may use Markdown for formatting.
There are no comments yet.