xargsrhel7du

How can I run du command from a file on RHEL when file has directories with spaces in the names?


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?


Solution

  • 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.