title: How to check if a file's size is greater than a certain value in Bash
body: <p>How do I achieve the following goal:</p>
  <ul>
  <li>I need to check the size of a file</li>
  <li>Then compare this file size to a fixed number using an <em>if</em> condition and corresponding conditional statement</li>
  </ul>
  <p>So far, I have the following:</p>
  <pre><code>#!/bin/bash
  
  # File to consider
  FILENAME=./testfile.txt
  
  # MAXSIZE is 5 MB
  MAXSIZE = 500000
  
  # Get file size
  FILESIZE=$(stat -c%s &quot;$FILENAME&quot;)
  # Checkpoint
  echo &quot;Size of $FILENAME = $FILESIZE bytes.&quot;
  
  # The following doesn't work
  if [ (( $FILESIZE &gt; MAXSIZE)) ]; then
      echo &quot;nope&quot;
  else
      echo &quot;fine&quot;
  fi
  </code></pre>
  <hr/>
  <p>With this code, I can get the file name in the variable $FILESIZE, but I am unable to compare it with a fixed integer value.</p>
  <pre><code>#!/bin/bash
  filename=./testfile.txt
  maxsize=5
  filesize=$(stat -c%s &quot;$filename&quot;)
  echo &quot;Size of $filename = $filesize bytes.&quot;
  
  if (( filesize &gt; maxsize )); then
      echo &quot;nope&quot;
  else
      echo &quot;fine&quot;
  fi
  </code></pre>