Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'more/less doesn't uncompress first' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
more/less doesn't uncompress first
Authored by: macgician on Sep 17, '09 04:48:47PM

> (in fact, contrary to what some posts on this site have suggested, command line utilities like strings will see the same file regardless if it is compressed or not)


Not entirely true. While "cat" will uncompress the file first, "more" and "less" will show a raw binary dump of the compressed file. That's a quick and dirty way to tell if a file is compressed, at least until Apple fixes it. Your utility is far more useful obviously.



[ Reply to This | # ]
more/less doesn't uncompress first
Authored by: brkirch on Sep 17, '09 07:04:54PM
Yes I could have worded that better. After I submitted this hint I found that there are some obscure ways to tell if a file is compressed. For example, if stat -f %f [file] returns a number that has the 32 flag set (the UF_COMPRESSED flag) then the file is HFS+ compressed. I can't say I can see how more or less can be used to identify compressed files though, as the data being printed to the screen is the uncompressed data, not the compressed (just tried it, you may have somehow gotten a different result but I tried it on some compressed files and it is definitely showing the uncompressed data).

[ Reply to This | # ]
more/less doesn't uncompress first
Authored by: scooby509 on Sep 17, '09 08:52:32PM
Less certainly works differently than cat, but Apple would have to specifically modify it to not use standard POSIX calls. Here's the source to cat; search for 'fdopen' to see where it's opening its input file.

Less is a surprisingly complex utility but it still uses a standard POSIX function to open a regular file in this source file, search for open(qopen_filename, OPEN_READ) within the file to find it.

man 3 fdopen 2 open will confirm that both of these system calls are standard POSIX calls, so they don't really know anything about HFS vs. any other file system.

(Also, 'more' is simply the compatibility mode of 'less.' They're the same file, hard linked.)

[ Reply to This | # ]

more/less doesn't uncompress first
Authored by: michelcolman on Sep 18, '09 06:57:44AM

Nope, I just compressed an rtf file, then used "more" and "less", the file appeared normally, as if nothing was special about it, no raw compressed data but the original, readable text.



[ Reply to This | # ]