How to check if a file’s size is greater than a certain value in Bash

A couple of syntactic issues.

  1. The variable definitions in Bash do not take spaces. It should have been MAXSIZE=500000, without spaces.
  2. The way comparison operation is done is incorrect. Instead of if [ (( $FILESIZE > MAXSIZE)) ];, you could very well use Bash’s own arithmetic operator alone and skip the [ operator to just if (( FILESIZE > MAXSIZE)); then

If you are worried about syntax issues in your script, use ShellCheck to syntax check your scripts and fix the errors as seen from it.


As a general coding practice, use lowercase user-defined variables in Bash to avoid confusing them with the special environment variables which are interpreted for different purposes by the shell (e.g., $HOME and $SHELL).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)