Prev: Use shell command to judge whether a file is in pdf format or not.
Next: Use shell command to judge whether a file is in pdf format or not.
From: Janis Papanagnou on 15 Feb 2010 21:53 Hongyi Zhao wrote: > Hi all, > > I want to use shell command to judge whether a file is in pdf format > or not. Any hints? man file man grep On my system file(1) gives, for example, the following information... ASCII text ISO-8859 text Microsoft Office Document PDF document, version 1.3 PDF document, version 1.4 ... ....then apply grep(1) and check the return code in a shell if statement. Janis
From: mop2 on 16 Feb 2010 05:09
On Tue, 16 Feb 2010 00:47:34 -0200, Hongyi Zhao <hongyi.zhao(a)gmail.com> wrote: > Hi all, > > I want to use shell command to judge whether a file is in pdf > format > or not. Any hints? You can try an alternative to the command file. A function with bash, for example, can be: ispdf(){ read -n5 < $1 &&[ "$REPLY" = %PDF- ];} $ ispdf uhf.htm &&echo yes $ ispdf irfr3303pbf.pdf &&echo yes yes $ |