File size check, Linux


File size check

cd $file_path
# file_path directory
file=($(cat video.txt | xargs ls -lah | awk '{ print $9}'))
# get name in video.txt --- two files for example VID_141523.mp4 VID_2_141523.mp4
actualsize=$(wc -c <"$file")
if [ $actualsize -ge $minimumsize ]; then
    echo $file size $actualsize bytes
    echo error $file size 0 bytes

VID_141523.mp4 file corrupted during conversion. its size 0 bytes

Script output—- error VID_20220709_141523.mp4 size 0 bytes


  • VID_141523.mp4
  • VID_2_141523.mp4

How to add this construct to the loop ?
It should check all files in the list video.txt


You probably mean – "how to loop instead of this: file=($(cat video.txt | xargs ls -lah | awk '{ print $9}'))" (which is pretty horrible by itself (*)).

You should just use a while loop:

cat video.txt | while read file; do
   # something with $file

Also, please use stat -c%s FILE instead of wc (which, BTW, also takes a file – you can use wc -c FILE instead of using input redirection), as that looks just at the file system information to check the size, instead of loading and counting each byte.

(*) doing ls -lah and then awk '{print$9}' is the same as just doing ls, but there are other issues with this code that is very not bash idiomatic.

Answered By – Guss

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published