On linux, I have a file called dirs.txt. This file has directory names in it, some of which contain embedded blanks. I want to run the du -sh command on each directory name (to get a total usage for each directory and its children). I've tried:
cat dirs.txt | xargs du -sh
but that seems to split the directory names on their spaces which means lots of errors. How can I tackle this?
cat dirs.txt | tr '\12' '\0' | xargs -0 du -sh
So long as the dirs.txt
file has one directory name per line, this works.
xargs
with the -0
option to take care to not mishandle special characters like spaces.