-1

Using du -h: how to sum up the file size of file1, file 2, file 3...located in various directories.

I believe it can be done via script, but I have no idea how to perform arithmetic out of different outputs in the terminal.

2
  • I would like to know the total size of different files from different directories. I tried du -h file 1 file 2 file 3, and du -h file 1 + file 2...Are you suggesting I should read the manual for du?
    – Joey
    Jul 3, 2020 at 23:30
  • Yep. Im suggesting. If I execute du -ach ./.cache/pip/selfcheck.json Downloads/PDFMaker1.0.1.tar I get a total in the last line. (36K total)
    – kanehekili
    Jul 3, 2020 at 23:46

1 Answer 1

1

Use the -c / --total option to get the total size.

To get the last line containing the "total" value:

du -hc /path/to/file1 /path/to/file2 /path/to/filex | tail -n1

Or the last line without the "total" string:

du -hc /path/to/file1 /path/to/file2 /path/to/filex | tail -n1 | cut -f1
1
  • They have a point: I should have read the manual for du.
    – Joey
    Jul 3, 2020 at 23:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .