Reputation: 13206
I have the following step in my Bash code which checks to see if a file is bigger than 1.6GB:
#!/bin/sh
SIZE_THRESHOLD=1717986918
if [[ $(find /home/methuselah/file -type f -size +${SIZE_THRESHOLD}c 2>/dev/null) ]]; then
somecmdbecausefileisbigger
else
somecmdbecausefileissmaller
fi
The command somecmdbecausefileisbigger
is never triggered even when the file size is greater than 1.6GB. Why is this?
Upvotes: 0
Views: 871
Reputation: 531045
Just use stat
(note that your version of stat
may differ; check your man page for details):
if [ "$(stat -c '%s' /home/methuselah/file)" -gt "$SIZE_THRESHOLD" ]; then
Upvotes: 1
Reputation: 249133
I don't know why your find
command doesn't work, but I do know a simpler way to do this:
if [ $(stat -f %z /home/methuselah/file) -gt ${SIZE_THRESHOLD} ]; then
Though unfortunately you have to replace -f %z
with -c %s
on Linux (the former works on BSD and MacOS).
Upvotes: 1