zsh-users
 help / color / mirror / code / Atom feed
* I/O edirection and dd
@ 2016-04-24  9:53 Meino.Cramer
  2016-04-24 11:22 ` guyzmo
  2016-04-24 11:22 ` lilydjwg
  0 siblings, 2 replies; 4+ messages in thread
From: Meino.Cramer @ 2016-04-24  9:53 UTC (permalink / raw)
  To: zsh-users

Hi,

with the pipe

    cat verylongfile | dd count=512 | file -

I want to get the type of file without reading it completly.

Unfortunately dd and cat are very chatty and print something like:

512+0 records in
512+0 records out
262144 bytes (262 kB) copied, 0.00396828 s, 66.1 MB/s
"Here comes the wanted output of the file command'
[2]    32419 broken pipe  cat tmp.blend | 
       32420 done         dd count=512 | 
       32421 done         file -


I want to get rid of all that - except for the printout of the
'file' command.

I tried several permutations and combinations of '{}", "2>&1" and 
such but beside some additional syntax errors my success was very
....hrmmm....limited.

How can I acchieve what I want?

Thank you very much in advance for any help!

Best regards,
Meino





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: I/O edirection and dd
  2016-04-24  9:53 I/O edirection and dd Meino.Cramer
@ 2016-04-24 11:22 ` guyzmo
  2016-04-24 11:22 ` lilydjwg
  1 sibling, 0 replies; 4+ messages in thread
From: guyzmo @ 2016-04-24 11:22 UTC (permalink / raw)
  To: zsh-users

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@gmx.de 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: I/O edirection and dd
  2016-04-24  9:53 I/O edirection and dd Meino.Cramer
  2016-04-24 11:22 ` guyzmo
@ 2016-04-24 11:22 ` lilydjwg
  2016-04-24 17:10   ` Bart Schaefer
  1 sibling, 1 reply; 4+ messages in thread
From: lilydjwg @ 2016-04-24 11:22 UTC (permalink / raw)
  To: zsh-users

On Sun, Apr 24, 2016 at 11:53:42AM +0200, Meino.Cramer@gmx.de wrote:
> Hi,
> 
> with the pipe
> 
>     cat verylongfile | dd count=512 | file -
> 
> I want to get the type of file without reading it completly.
> 
> Unfortunately dd and cat are very chatty and print something like:
> 
> 512+0 records in
> 512+0 records out
> 262144 bytes (262 kB) copied, 0.00396828 s, 66.1 MB/s
> "Here comes the wanted output of the file command'
> [2]    32419 broken pipe  cat tmp.blend | 
>        32420 done         dd count=512 | 
>        32421 done         file -
> 
> 
> I want to get rid of all that - except for the printout of the
> 'file' command.
> 
> I tried several permutations and combinations of '{}", "2>&1" and 
> such but beside some additional syntax errors my success was very
> ....hrmmm....limited.
> 
> How can I acchieve what I want?
> 
> Thank you very much in advance for any help!

Why don't you let file read the file itself? file won't read the entire
file.

dd prints out information to stderr, so you can do

cat verylongfile | dd count=512 2>/dev/null | file -

cat isn't necessary in this case. You can just use redirection:

< verylongfile dd count=512 2>/dev/null | file -

And head -c256k will do the same as your dd command.

-- 
Best regards,
lilydjwg


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: I/O edirection and dd
  2016-04-24 11:22 ` lilydjwg
@ 2016-04-24 17:10   ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2016-04-24 17:10 UTC (permalink / raw)
  To: zsh-users

On Apr 24,  7:22pm, lilydjwg wrote:
} Subject: Re: I/O edirection and dd
}
} On Sun, Apr 24, 2016 at 11:53:42AM +0200, Meino.Cramer@gmx.de wrote:
} > 
} >     cat verylongfile | dd count=512 | file -
} 
} Why don't you let file read the file itself? file won't read the entire
} file.

Indeed, if you check /etc/magic or /usr/share/file/magic (location should
be explained in "man file") you'll find that the number of bytes needed
is listed for most file types.  (Encrypted ZIPs may need to read 75kb,
for one example from my system.)

-- 
Barton E. Schaefer


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-24 17:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-24  9:53 I/O edirection and dd Meino.Cramer
2016-04-24 11:22 ` guyzmo
2016-04-24 11:22 ` lilydjwg
2016-04-24 17:10   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).