Add up a column of numbers at the Unix shell

后端 未结 20 2290
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:46

    if you don't have bc installed, try

    echo $(( $(... | paste -sd+ -) ))
    

    instead of

    ... | paste -sd+ - | bc
    

    $( ) <-- return the value of executing the command

    $(( 1+2 )) <-- return the evaluated results

    echo <-- echo it to the screen

提交回复
热议问题