How to find the size of a file and assign it to a variable in UNIX

前端 未结 4 622
借酒劲吻你
借酒劲吻你 2021-01-23 09:36

I am writing a UNIX script that reads the size of a text file and if the file is of some size it should print the text file. If it is not an else loop executes and the process c

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-23 10:19

    Assign your file size in a variable and then check equality with -eq

    size=`ls -l ${filepath}/{filename}.lst| awk '{print $5}'`
    if [ $size  -eq 461 ]
    then
       echo "MATCHED"
    else
      echo "NOT MATCHED"
    fi
    

提交回复
热议问题