I have a directory called 'directory1' with files: file1, file2, file3, that have been passed by in a variable 'files'. Echo $files has the following output: file1 file2 file3. I want to have the sum of the sizes but the code below only works for only one file. How can I make it work for all the files?
ls -l ./$dir/$files | awk '{t+=$5}END{print t}'
ls -l ./$dir/$files
itself is only going to give the file size of directory1/file1. Try it.files
variable? You also mention adir
variable that is not described before. Does it mean that files are not on the same folder? Also is it required to useawk
to sum the sizes or can other tools be used too?files
variable, not the files themselves, like if they are full paths, separated by lines or just filenames separated by spaces, as examples. Usually we provide an example input as well as a desired output on such questions, so that the answer can be clear and straightforward. Could you add that to the question?