[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Check if file size greater than a small number?
From: |
Greg Wooledge |
Subject: |
Re: Check if file size greater than a small number? |
Date: |
Wed, 9 Mar 2022 13:11:23 -0500 |
On Wed, Mar 09, 2022 at 11:42:11AM -0600, Dennis Williamson wrote:
> On Wed, Mar 9, 2022 at 11:10 AM Peng Yu <pengyu.ut@gmail.com> wrote:
> > But if my goal is just to know whether the file size is greater than a
> > smaller (say 40). What is the most efficient way to do so in bash?
> size=41
> filename=testfile
> read -n "$size" < "$filename"
> if ((${#REPLY} >= size)) ...
That doesn't look like it will do what the OP desires. For at least
two reasons:
1) It won't handle NUL bytes at all.
2) It will try to read 41 *characters*, but the OP might (probably does)
want the file's size in *bytes*. Of course, this part can be fixed
by setting locale variables to C, but see part 1.
unicorn:~$ printf 'abcde\0ghijk' > foo
unicorn:~$ ls -l foo
-rwxr-xr-x 1 greg greg 11 Mar 9 13:09 foo*
unicorn:~$ read -n 11 < foo
unicorn:~$ echo "${#REPLY}"
10
- Check if file size greater than a small number?, Peng Yu, 2022/03/09
- Re: Check if file size greater than a small number?, Dennis Williamson, 2022/03/09
- Re: Check if file size greater than a small number?, Jesse Hathaway, 2022/03/09
- Re: Check if file size greater than a small number?, Kerin Millar, 2022/03/09
- Re: Check if file size greater than a small number?, Peng Yu, 2022/03/09
- Re: Check if file size greater than a small number?, Alex fxmbsw7 Ratchev, 2022/03/10
- Re: Check if file size greater than a small number?, Chet Ramey, 2022/03/10
- Re: Check if file size greater than a small number?, Jesse Hathaway, 2022/03/10
- Re: Check if file size greater than a small number?, Greg Wooledge, 2022/03/10
- Re: Check if file size greater than a small number?, Lawrence Velázquez, 2022/03/10
Re: Check if file size greater than a small number?, Alex fxmbsw7 Ratchev, 2022/03/09