11

I'm trying to get the size of a folder an application is currently writing to. If I run the du command it sometimes fails with the error:

du: cannot access `/a/b/a.txt': No such file or directory

because the application deleted the file while du was processing. How can I tell it to ignore such errors?

Anthon
  • 79,293
Vivek Goel
  • 1,293

2 Answers2

8

You can filter standard error using grep, without losing (possibly important) other error messages. In bash:

du 2> >(grep -v '^du: cannot \(access\|read\)' >&2)
Chris Down
  • 125,559
  • 25
  • 270
  • 266
2

try like this

     du -sh /home/dir 2> /dev/null | cut -f1
no1
  • 121