Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: I/O edirection and dd



Hello Meino,

this question is not diretcly zsh related so this list is not the place
to ask that. It would be a better fit for a stackexchange-like forum
(either stackoverflow, or superuser, or unix stackoverflow). But anyway,
I'm giving you an answer inline.

On Sun, Apr 24, 2016 at 11:53:42AM +0200, Meino.Cramer@xxxxxx wrote:
> with the pipe
> 
>     cat verylongfile | dd count=512 | file -
> 
> I want to get the type of file without reading it completly.
[...]
> How can I acchieve what I want?

First, you're doing a useless use of cat, as dd can have its input file
defined using the 'if=' argument. Then the byte count is way too high,
as file only needs the first few bytes to determine type of a file.
Finally, you can get rid of useless output by redirecting stderr from dd
into the null chadev, but if you don't it's not preventing file to do
its job. So here you go:

    % dd if=ascii_file.txt count=10 | file -
    10+0 records in
    10+0 records out
    5120 bytes (5.1 kB) copied, 6.7592e-05 s, 75.7 MB/s
    /dev/stdin: ASCII text

or for the less chatty version:

    % dd if=ascii_file.txt count=10 2> /dev/null | file -
    /dev/stdin: ASCII text

and there you go!

HTH,

-- 
Guyzmo



Messages sorted by: Reverse Date, Date, Thread, Author