3

I'm on an ubuntu server and want to check a summary of disk usage of directories inside /var/lib/docker I'm confused why I'm not able to check the disk usage of all the directories inside /var/lib/docker using a glob *.

The directory /var/lib/docker clearly exists and has directories inside it:

$ sudo du -s /var/lib/* | grep docker
865644  /var/lib/docker
8   /var/lib/docker-engine
$ sudo du -s /var/lib/docker/*
du: cannot access '/var/lib/docker/*': No such file or directory
$ sudo file /var/lib/docker
/var/lib/docker: directory
$ sudo ls /var/lib/docker | head -n 1
builder
$ sudo du -s /var/lib/docker/builder
20  /var/lib/docker/builder

Why am I getting an error from du?

du: cannot access '/var/lib/docker/*': No such file or directory

My error seems related to being a non-root user because if I switch to the root user then I'm able to issue the du command:

# du -s /var/lib/docker/* | sort -n
4   /var/lib/docker/runtimes
4   /var/lib/docker/swarm
4   /var/lib/docker/tmp
4   /var/lib/docker/trust
20  /var/lib/docker/builder
20  /var/lib/docker/plugins
36  /var/lib/docker/volumes
60  /var/lib/docker/network
72  /var/lib/docker/buildkit
208 /var/lib/docker/containers
1880    /var/lib/docker/image
863328  /var/lib/docker/overlay2
  • You don't need a glob at all. du /var/lib/docker does the same. – OrangeDog Aug 9 at 20:52
4

You get the error because your (non-root) shell tried to expand the glob /var/lib/docker/* and was unable (because /var/lib/docker isn't readable by your user). Your shell then left the glob intact, leaving a literal asterisk for sudo, which is what du is complaining about:

du: cannot access '/var/lib/docker/*': No such file or directory

... because there is no file or directory named * under /var/lib/docker/.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.