It is unusual on Code Review, to recommend a different approach, but this process can be simplified a whole bunch..... and avoid perl entirely.....
du -s -B 1 | grep -P -q '^\d{10,}+\s.*'
It breaks down as follows:
du -s -B 1
print a summary (no details for each file), with a byte-per-block size ... i.e. print the number of bytes in the current directory.
Then, using grep (and perl-compatible regex).... use quiet output, which returns 0 on a successful match, and 1 on no-match.
In other words, make sure the line starts with at least 10 digits.... i.e. >= 1,000,000,000
bytes.
Putting it together, the grep will be successful if the current directory is at least 1GB.
I tested this with:
du -s -B 1 | grep -P -q '^\d{10,}+\s.*' && echo "Bigger than 1G" || echo "less than 1G"
Edit:
This is compatible with your original code, which uses --si
on du, which uses 1,000,000,000 bytes to represent GB. If you want to use GiB ( \$2^{31}\$ ) then it is actually substantially harder ....
tail -1
? Doesn't that just choose one of the subdirectories arbitrarily? \$\endgroup\$.
, which is the current directory). The other lines are sizes of subdirectories. \$\endgroup\$