Add up a column of numbers at the Unix shell

后端 未结 20 2731
Happy的楠姐
Happy的楠姐 2021-01-29 18:10

Given a list of files in files.txt, I can get a list of their sizes like this:

cat files.txt | xargs ls -l | cut -c 23-30

which pr

20条回答
  •  忘掉有多难
    2021-01-29 18:24

    cat will not work if there are spaces in filenames. here is a perl one-liner instead.

    perl -nle 'chomp; $x+=(stat($_))[7]; END{print $x}' files.txt
    

提交回复
热议问题