help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wait until the file is done


From: Dennis Williamson
Subject: Re: wait until the file is done
Date: Fri, 30 Oct 2020 12:32:09 -0500

On Fri, Oct 30, 2020, 12:29 PM Greg Wooledge <wooledg@eeg.ccf.org> wrote:

> On Fri, Oct 30, 2020 at 06:20:16PM +0100, Mike Jonkmans wrote:
> > On Fri, Oct 30, 2020 at 12:52:11PM -0400, Greg Wooledge wrote:
> > >
> > > size=$(wc -c < "$file")
> >
> > It may be better to use: wc -c "%file"
> > As 'wc' can use the file size (via fstat).
> >
> > The '<' forces wc to read the file content.
> > Which can be significantly slower for large (video) files.
>
> That's not true.
>
> unicorn:~$ strace wc -c < .bashrc
> [...]
> fstat(0, {st_mode=S_IFREG|0755, st_size=2738, ...}) = 0
> lseek(0, 0, SEEK_CUR)                   = 0
> fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x3), ...}) = 0
> write(1, "2738\n", 52738
> )                   = 5
> close(0)                                = 0
> close(1)                                = 0
> close(2)                                = 0
> exit_group(0)                           = ?
> +++ exited with 0 +++
>

Plus using the redirection has the added benefit of not having to strip the
filename from the output of wc.

>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]