du command gives error and result at the same time
I would like to know the disk space of my VPS, and although for folders du
works fine as
$ du -sh /home/
325M /var/
But trying to get the entire vps is giving me this result.
[root@user/]# du -sh
du: cannot access `./proc/18097/task/18097/fd/4': No such file or directory
du: cannot access `./proc/18097/task/18097/fdinfo/4': No such file or directory
du: cannot access `./proc/18097/fd/4': No such file or directory
du: cannot access `./proc/18097/fdinfo/4': No such file or directory
1.3G .
I am assuming 1.3G is the space, but why does the error happen? How do I fix it?
You don’t need to fix that – it’s not broken. Those are references to kernel file objects that are not available to du
– it’s a common race condition involving file descriptors. Those consume no space anyway (and neither does /proc
, for that matter) as they are not on disk – they are only temporary references to in-kernel file-descriptors. They are either referencing anonymous pipes/sockets – and so are not stat
able as they have no filename – or between the time that du
notices them and the time it tries to stat
them they have either ceased to exist or du
never had permissions to do so in the first place. They are very likely du
‘s own file descriptors.
However, your command might have issues in that it addresses multiple file-system mounts. This is probably not your intent, and so you could use:
du -shx
…to address only files that exist on the current working directory’s root mount. Because /proc
is a file-system all its own and is mounted separately to /
running that from /
would exclude /proc
and all others which do not belong.
Else, if you do want listings for multiple file-system mounts, you can just do:
du -sh 2>/dev/null