How can multiple file sizes be calculated in Linux?

There are several commonly used methods for using the du command to calculate the total size of multiple files or directories.

  1. Calculate the total size of all files and subdirectories in the current directory.
du -sh *
  1. Calculate the total size of all files and subdirectories in the specified directory.
du -sh /path/to/directory/*
  1. Calculate the total size of multiple files.
du -ch file1 file2 file3
  1. Calculate the total size of all files and subdirectories in the current directory and sort them by size.
du -sh * | sort -h

Please note that the option “-h” in the above commands indicates displaying file sizes in a human-readable format, “-s” indicates displaying only the total size, and “-c” indicates displaying the total size along with the size of each file separately.

bannerAds