1

First of all, I'm completely ignorant regarding shell commands. So, please, be patient. Also, I'm using OS X, but I'm happy with an answer in the generality of Unix if such thing is possible.

I'm trying to execute the command stat -f [some parameters here] [volume name].

According to references elsewhere, the most simple command of this form stat -f /dev/disk0s2 is syntactically correct. However I've got the following:

 stat -f /dev/disk0s2
 /dev/disk0s2

According to here (https://www.computerhope.com/unix/stat.htm), for instance, I should get a paragraph full of information. In my case, I'm mostly interested in the block size obtained through the stat command.

Also, here (https://apple.stackexchange.com/questions/42509/how-to-get-hfs-filesystem-blocksize), it's mentioned the parameters "%k, %z, %b". However in the manual of stat (i.e., by using man stat) I can't find such parameters. Furthermore I have no idea why the quotation marks are being used there (I've seen both stat -f %k and stat -f "%k", for instance).

So, in summary, I have three questions:

1) Why stat -f /dev/disk0s2 is not giving me the expected output?

2) What are these %k, %z and %b parameters and are they being mentioned in the manual?

3) What's the meaning of the quotation marks around the above mentioned parameters (for instance, stat -f %k and stat -f "%k")? Is this a general stuff in the syntax of Unix commands?

Thanks in advance.

2

The command line tools that come pre-installed on OS X come from FreeBSD, but many guides online will probably assume a Linux environment and GNU tools. They're not always the same.

Compare the two man pages for FreeBSD stat and GNU stat. In FreeBSD, -f sets the output format and takes a corresponding argument. In GNU stat -f asks for the output about the filesystem (not the named file), and takes no argument.

So, 1) the result is different because you're using a different tool, 2) the format options are mentioned under "Formats" in the FreeBSD man page. 3) The quotes aren't really related to stat itself, but the shell. Command line arguments that contain characters special to the shell (like whitespace, or glob characters ?*[] etc) need to be quoted to prevent the shell from processing them. But % isn't special (at least not in that context), so it doesn't matter if it's quoted or not.

  • Thanks for the fast reply. About 3, is there an example where the shell would read it differently with and without the quotation marks? – user40276 Mar 20 '18 at 12:32
  • Ah, ok. I haven't refreshed the page to see your edited answer. Still I can't understand the quotation marks well. It looks like it only makes sense when I'm adding special characters to names of things, but this %k, for instance, plays apparently the role of a sub option so even if % was special, wouldn't I want it to be processed? – user40276 Mar 20 '18 at 12:40
  • Try ls "*" v.s. ls * – xenoid Mar 20 '18 at 12:41
  • @xenoid Yes, I've got it in this case. But in the above example the % in %k seems to be something like an option (or an option inside an option) and not a name pointing to something, so it looks like I actually would want the shell to process it as %k and not "%k" even if % was a special character. – user40276 Mar 20 '18 at 12:46
  • Out of habit perhaps? Very often you use the format to print several things with spaces in between: stat -c "%8s %n" * and the quotes are necessary then. Note in passing that you can have length specifiers in the format, or that you can make arbitrary strings: stat -c "File %n is %s bytes" *. – xenoid Mar 20 '18 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.