We’re rewarding the question askers & reputations are being recalculated! Read more.
19 added 61 characters in body
source | link

will give you the number of bytes that can be read from the file. IOW, it's the size of the content of the file. It will however read the contentcontents of the file (except if the file is a regular file or symlink to regular file in most wc implementations as an optimisation). That may have side effects. For instance, for a named pipe, what has been read can no longer be read again and for things like /dev/zero or /dev/random which are of infinite size, it's going to take a while. That also means you need read permission to the file, and the last access timestamp of the file may be updated.

will give you the number of bytes that can be read from the file. IOW, it's the size of the content of the file. It will however read the content of the file (except if the file is a regular file or symlink to regular file in most wc implementations as an optimisation). That may have side effects. For instance, for a named pipe, what has been read can no longer be read again and for things like /dev/zero or /dev/random which are of infinite size, it's going to take a while. That also means you need read permission to the file.

will give you the number of bytes that can be read from the file. IOW, it's the size of the content of the file. It will however read the contents of the file (except if the file is a regular file or symlink to regular file in most wc implementations as an optimisation). That may have side effects. For instance, for a named pipe, what has been read can no longer be read again and for things like /dev/zero or /dev/random which are of infinite size, it's going to take a while. That also means you need read permission to the file, and the last access timestamp of the file may be updated.

18 added 49 characters in body
source | link
  • With zsh (after loading the zsh/system module):

    {sysseek -w end 0 && size=$((systell(0)))} < $file
    
  • With ksh93:

    : < "$file" <#((size=EOF))
    

    or

    { size=$(<#((EOF))); } < "$file"
    
  • with perl:

    perl -le 'seek STDIN, 0, 2 or die "seek: $!"; print tell STDIN' < "$file"
    
  • With zsh (after loading the zsh/system module):

    {sysseek -w end 0 && size=$((systell(0)))} < $file
    
  • With ksh93:

    : < "$file" <#((size=EOF))
    
  • with perl:

    perl -le 'seek STDIN, 0, 2 or die "seek: $!"; print tell STDIN' < "$file"
    
  • With zsh (after loading the zsh/system module):

    {sysseek -w end 0 && size=$((systell(0)))} < $file
    
  • With ksh93:

    < "$file" <#((size=EOF))
    

    or

    { size=$(<#((EOF))); } < "$file"
    
  • with perl:

    perl -le 'seek STDIN, 0, 2 or die "seek: $!"; print tell STDIN' < "$file"
    
17 added 188 characters in body
source | link

or to avoid an error about an empty arithmetic expression in dash or yash when wc produces no output (like when the file can't be opened):

size=$(($(wc -c < "$file") +0))

or to avoid an error about an empty arithmetic expression in dash or yash when wc produces no output (like when the file can't be opened):

size=$(($(wc -c < "$file") +0))
16 added 60 characters in body
source | link
15 added 213 characters in body
source | link
14 added 76 characters in body
source | link
13 note about permission for wc vs stat
source | link
12 added 1 character in body
source | link
11 added 2 characters in body
source | link
10 added 1257 characters in body
source | link
9 deleted 11 characters in body
source | link
8 added 143 characters in body
source | link
7 added 119 characters in body
source | link
6 added 115 characters in body
source | link
5 added 125 characters in body
source | link
4 added 18 characters in body
source | link
3 added details for AIX output; mote/note typo
source | link
2 added 453 characters in body
source | link
1
source | link