f



Is 'du -b file' equivalent to 'wc -c file'?

Hi all,

It seems that both 'du -b file' and 'wc -c file' can give the correct 
bytes count on the file. Are they equivalent for all case on this type of 
job?

Regards
-- 
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
0
Hongyi
5/22/2015 4:18:53 AM
comp.unix.shell 15484 articles. 3 followers. Post Follow

4 Replies
822 Views

Similar Articles

[PageSpeed] 13

On 2015-05-22, Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> Hi all,
>
> It seems that both 'du -b file' and 'wc -c file' can give the correct 
> bytes count on the file. Are they equivalent for all case on this type of 
> job?
>
> Regards

There's no -b switch for du on my system (Mac OS X 10.10.3), and it's
not in POSIX.  The -c switch for wc is however standard, so use that
instead.

Note that you will have to use -m with wc to always get the correct
number of *characters* in a file.

-- 
:: Andreas Kusalananda Kahari, Uppsala University,  Sweden ::
:: a n d r e a s  .  k a h a r i  @  i c m  .  u u  .  s e ::
0
Kusalananda
5/22/2015 6:52:32 AM
On Fri, 22 May 2015 06:52:32 +0000, Kusalananda wrote:

> There's no -b switch for du on my system (Mac OS X 10.10.3),

I can find the following for my case manpage of du:

 -b, --bytes
  equivalent to '--apparent-size --block-size=1'

 --apparent-size
  print  apparent  sizes, rather than disk usage; although the apparent  
size is usually smaller, it may be larger due to holes in ('sparse') 
files, internal fragmentation, indirect blocks, and the like

-B, --block-size=SIZE
scale sizes by SIZE before printing them; e.g., '-BM' prints sizes in 
units of 1,048,576 bytes;


> and it's
> not in POSIX.  The -c switch for wc is however standard, so use that
> instead.
> 
> Note that you will have to use -m with wc to always get the correct
> number of *characters* in a file.

Regards
-- 
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
0
Hongyi
5/22/2015 8:54:32 AM
2015-05-22 04:18:53 +0000, Hongyi Zhao:
> Hi all,
> 
> It seems that both 'du -b file' and 'wc -c file' can give the correct 
> bytes count on the file. Are they equivalent for all case on this type of 
> job?
[...]

On a *GNU* system, with *one* *regular* file whose name doesn't
start with "-", it will be equivalent, not necessarily if not
all those conditions are met.

-b is a GNU extension. It gives the size in bytes and instead
of giving disk usage, it gives the size as reported by the
lstat() system call.

wc -c is portable and counts the number of files that can be
read from a file. For a regular file (or symlink to regular
file), most wc implementations, as an optimisation, will not
read the file but call stat() to get the size.

Now, if not a regular file, the behaviour will typically vary.

For symlinks, du will give you the size of the link as reported
by lstat(), wc the size of the content of file it points to.

For directories, you'll get an error with wc and du will give
you the sum of the apparent size of the directory and all the
unique files (counting hardlinks once) it contains.

For a device, du -b will give you the size reported by lstat(),
most probably 0, while wc will give you the number of bytes it
manages to read from it (will run forever for /dev/zero for
instance).

For a pipe, same thing. Some systems report 0 on lstat(), some
the amount currently in the pipe. wc will block until there's no
more writter to the pipe.

etc.

If there are more than one file, wc will also give you a total
line. For GNU du, if some of the files are referenced several
times (including as different hard links), only one will be
reported.

If the file name starts with -, obviously it will be treated as
an option. There's still a difference though when using wc -c --
file and du -b -- file for the file called "-". wc will treat it
as meaning stdin instead of counting bytes in the file called
"-" (you'll need to call wc as "wc -c ./-" or "wc -c < -").

-- 
Stephane
0
Stephane
5/22/2015 10:51:46 AM
On Fri, 22 May 2015 11:51:46 +0100, Stephane Chazelas wrote:

> On a *GNU* system, with *one* *regular* file whose name doesn't start
> with "-", it will be equivalent, not necessarily if not all those
> conditions are met.
> 
> -b is a GNU extension. It gives the size in bytes and instead of giving
> disk usage, it gives the size as reported by the lstat() system call.
> 
> wc -c is portable and counts the number of files that can be read from a
> file. For a regular file (or symlink to regular file), most wc
> implementations, as an optimisation, will not read the file but call
> stat() to get the size.
> 
> Now, if not a regular file, the behaviour will typically vary.
[...]

Deeply and exhausting detailed analysis, thanks a lot. 

Regards
-- 
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
0
Hongyi
5/22/2015 1:24:33 PM
Reply:

Similar Artilces:

'cat file' but only if 'file' exist
I'm trying to run 'cat *.x' only if *.x files exist. What is the cleanest way of doing this? I'm doing it by shopt -s nullglob for i in *.x; do cat $i; done but this is aweful typing. -- William Park, Open Geometry Consulting, <opengeometry@yahoo.ca> No, I will not fix your computer! I'll reformat your harddisk, though. On 2004-06-09, William Park wrote: > I'm trying to run 'cat *.x' only if *.x files exist. What is the > cleanest way of doing this? I'm doing it by > shopt -s nullglob > for i in *.x; do cat $i; done ...

'^=' and '~='?
Hello, What is the difference between '^=' and '~='? Thanks, Duckhye ...

'is not' or '!='
A newbie question to you; what is the difference between statements like: if x is not None: and if x != None: Without any context, which one should be preferred? IMHO, the latter is more readable. On 2014-08-18 21:35, ElChino wrote: > A newbie question to you; what is the difference between statements > like: > if x is not None: > and > if x != None: > > Without any context, which one should be preferred? > IMHO, the latter is more readable. > "x == y" tells you whether x and y refer to objects that are equal. "x is y&qu...

``awk '!a[$0]++' file'' and ``awk '{if(!($0 in rec)) {rec[$0]=1; print $0;}}' file ''
Hi all, Currently, I'm reading the book on awk programming language, but meet the following two examples which I cann't understand so well: awk '!a[$0]++' file and awk '{if(!($0 in rec)) {rec[$0]=1; print $0;}}' file Could someone here please give me some hints or explanations on the logic of above codes? Regards -- ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. In article <meuejm$gsf$1@aspen.stu.neva.ru>, Hongyi Zhao <hongyi.zhao@gmail.com> wrote: > Hi all, > > Currently, I'm reading the bo...

web('file', 'filename' '-browser') not working
Hello, I'm working on a project involving Matlab and a nice flashy GUI. To call help files, I do: web('file', 'help.html' '-browser'); On my computer, this works. After compiling it, it works. If I manage to get the current directory wrong, somehow, the browser attempts to go to www.help.com, rather than put up an error. So far so good, except when the file isn't there, which I'm ignoring for the moment. However, when I run the program on other computers (I compile the program first), it always goes to www.help.com, no matter what the pwd says, or where ...

'''''''''''''The Running Update/Append Queries Using VBA code Ordeal''''''''''''''
Hello fellow programmers, I am trying to run an append/update query from code, a command button on a form initiates the queries. the format i am using is; _____________________________________________________ SELECT "criteria" FROM "criteria" WHERE "criteria" UPDATE/APPEND "field selections" RecordSource "qryExample" = above text strings" _______________________________________________________________________ When i am running a SELECT query in this manner it works fine with no problems, and accepts the values of specified linked for...

'to file' and 'to workspace' help
I have a model that runs a 4 degrees of freedom robot here, right now I am only working with rotating the robot though. I have the model using a repeating sequence stair block as an input, this waits 10 seconds spins 5 degrees waits 10 secs spins 5 more degrees all the way up to 360 then i have a stop simulation block that stops the simulation once it has reached 360. The model works perfectly for my purpose, but in my feedback loop that reads my encoder position i am trying to insert a to file or to workspace block so that i can keep track of the encoder readings while the robot is stopped ...

Difference between a 'file' and a 'table'
With OS400, all files are objects that can be accessed relationally. When I view the file system from Navigator (windows client), I see there is the Database and SQL tables, then there is the filesystem. I can manipulate both these objects (tables, files) with SQL. So, what is the difference between a table and a file? -- Texeme http://texeme.com Without being strict in its definition a file and a table in OS/400 are the same. If you go into object types you will find that there is a Type *FILE and a Type *TBL, maybe I will ask the next question, what is the difference ...

exist('fname','file')
Hello I have a file 'fname' in one of the directories under the matlabpath. the file was saved by the SAVE function. when I exist('fname','file') ans = 0 why it is not showing 2 since it exists? I also tried the full path name of the file, thanks Is the filename actually 'fname'? Or is the filename stored in the fname variable? Or is there an extension? (i.e. fname.mat) Is it in a different directory? If fname is a variable, you need to leave off the quotes: exist(fname,'file') If it has an extension, you need to put that on: e...

'''''''''''''The Running Update/Append Queries Using VBA code Ordeal'''''''''''''' #2
Hi, Thanks for ur help there HJ. I know how to do the tasks you specified there. I would like for the update query to use field values from some of the fields on the form (frmInvoices) such as InvoiceNumber, DateFrom, DateTo. My problem is that an append/update query can't find the values in the open Form (frmInvoices) when I specify them as; [Forms]![frmInvoices]![InvoiceNumber] a select query has no problem finding the field values on a form. please help. Aaron Hi Aaron, Could you post the entire code that you are having trouble with? Now it is not possible to see what goes wron...

if str_mo not in ('','.') and str_da not in ('','.') and str_yy not in ('','.') Any shorter ?
Hi, there. =20 I'm just curious if it ever dawned on anybody how to abbreviate this line : if str_mo not in ('','.') and str_da not in ('','.') and str_yy not in ('','.')=20 =20 Igor Kurbeko Clinical Programmer Analyst 678 336 4328 ikurbeko@atherogenics.com =20 no brain no pain =20 how about: if not (str_mo in ('','.') or str_da in ('','.') or str_yy in ('','.')) OR if not (missing(str_mo) or missing(str_da) or missing(str_yy)) Eric On 22 Oct 03 21:13:37 GMT, ikurbeko@ATHER...

Gui having an 'open file window' and a 'save file window'
Is it possible to click on a button in the gui and have a Windows-like window where I can select the file to open and another like when you click on 'save as'? Thank you very much nathaniel zoso wrote: > Is it possible to click on a button in the gui and have a > Windows-like window where I can select the file to open and another > like when you click on 'save as'? > > Thank you very much Check out the UIGETFILE and UIPUTFILE functions, respectively. -SteveSimon ...

change 'file name' in 'From Multimedia File' simulink block
I need to load a avi video into workspace and do some processing work. I use the 'From Multimedia File' block in simulink to extract the audio of the avi file. The question is that if for different avi files, i have to manually set the 'file name' of the 'From Multimedia File' everytime before start the simulation. I can read the avi file in a .m file and get the path name and filename first. Is that possible to send these path name and filename automatically to the 'file name' in 'From Multimedia File' block when the avi file is loaded? thx a lo...

A function with 'and' , 'not' , 'null' , 'car' and 'cdr'
What's this ? (defun enigma (x) (and (not (null x)) (or (null (car x)) (enigma (cdr x))))) "I suppose I should learn Lisp, but it seems so foreign." - Paul Graham, Nov 1983 On Wed, Oct 07 2015, CAI GENGYANG wrote: > What's this ? > > > (defun enigma (x) > (and (not (null x)) > (or (null (car x)) > (enigma (cdr x))))) Bad taste? It returns T if the list X contains nil as an element. It would be clearer to write (some #'null x). Helmut CAI GENGYANG ...

Issue with the 'script' command in users '.kshrc' and '.bashrc' files
I am attempting to monitor users actions by using the following 'script' command: # exec script -a /tmp/${LOG} In order to capture all types of login whether 'telnet', su, su - etc etc I have put it into the .profile, .dtprofile and the *rc shell files. This works fine for CSH and SH, however if I launch another session (dtterm &) or switch shell to either KSH or BASH, then it seems to spin round and attempt to infinately create fresh 'script' sessions until I quit out. Example below: Script started, file is /tmp/x Script started, file is /tmp/x Script started,...

Web resources about - Is 'du -b file' equivalent to 'wc -c file'? - comp.unix.shell

Wired Equivalent Privacy - Wikipedia, the free encyclopedia
Although its name implies that it is as secure as a wired connection, WEP has been demonstrated to have numerous flaws and has been deprecated ...

Equivalent Fractions on the App Store on iTunes
Get Equivalent Fractions on the App Store. See screenshots and ratings, and read customer reviews.

Rate of Indigenous children in child protection 'almost equivalent to another Stolen Generation'
The rate of Indigenous Australians in the child protection system has reached &quot;epidemic levels&quot;.

Uber X 'surge' charge turns Northbridge cup day ride into equivalent of airfare
A Sorrento businessman has come away from the&nbsp;Melbourne Cup with a big tip for punters after an&nbsp;Uber X cup day ride.

Intel: For Mainstream Gamers, Our IGPs Are Equivalent to Discrete GPUs
... where it was five years ago. We believe that the performance of Intel’s integrated graphics today, what we offer in the products […], is equivalent ...

OnePlus X may cost the equivalent of $270 in China
Despite the 'clandestine' nature of OnePlus' second offering this year, the company has been surprisingly straightforward with it. Months ago, ...

Franklin Gutierrez: Rich Hill's hitting equivalent
Franklin Gutierrez had a 167 wRC+ and produced 2.3 fWAR in 189 PA, and he did it while staying under the radar. Franklin Gutierrez's 2015 comeback ...

America has built the equivalent of 10 Keystone pipelines since 2010, by @Gaius_Publius
America has built the equivalent of 10 Keystone pipelines since 2010 by Gaius Publius The blue lines show expansion since 2005. Note the expansions ...

America Has Built the Equivalent of 10 Keystone Pipelines Since 2010
... obscures a sobering fact. A virtual Keystone pipeline is being built anyway. Yadullah Hussain at Financial Post : America has built the equivalent ...

The top-end Surface Book costs £250 more than the equivalent MacBook Pro
Microsoft has revealed the price of the most expensive Surface Book — and it costs $400 (£258) more than the equivalent MacBook Pro at $3,199 ...

Resources last updated: 1/25/2016 3:37:58 PM