0

ファイルのリストを含むフォルダーがあります。問題は、拡張機能がないことです。JPEG形式かJPG形式か確認したい。私はこれを試しました

find folder -type f -not -name "*.*"

出力は

folder/t351
folder/t352
folder/t353
folder/t354
folder/t355

正規表現を使ってみましたが、ファイル名に拡張子がないのでうまくいきません。誰かがファイルを検証して特定の形式であるかどうかを確認する方法を教えてもらえますか?

4

3 に答える 3

1

これはどう?

PROMPT> ls * | sed 's/^.*$/"&"/g' | xargs file
IREffectFilter.m:                                        ASCII C++ program text, with CRLF line terminators
MacBook Air.spx:                                         XML  document text
PGFilteredImageView.m:                                   ASCII C++ program text
Screen Shot 2012-09-27 at 1.33.50 PM.png:                PNG image data, 559 x 152, 8-bit/color RGB, non-interlaced
Screen Shot 2012-10-02 at 10.04.37 AM.png:               PNG image data, 880 x 1136, 8-bit/color RGBA, non-interlaced
Screen Shot 2012-10-02 at 2.08.53 PM.png:                PNG image data, 937 x 1158, 8-bit/color RGB, non-interlaced
Screen Shot 2012-10-03 at 9.50.16 AM.png:                PNG image data, 651 x 347, 8-bit/color RGB, non-interlaced
Screen Shot 2012-10-08 at 11.14.51 AM.png:               PNG image data, 1343 x 1528, 8-bit/color RGBA, non-interlaced
Screen Shot 2012-10-08 at 12.09.01 PM.png:               PNG image data, 880 x 1136, 8-bit/color RGBA, non-interlaced
Screen Shot 2012-10-08 at 12.29.16 PM.png:               PNG image data, 880 x 1136, 8-bit/color RGBA, non-interlaced
Screen Shot 2012-10-09 at 8.44.05 AM.png:                PNG image data, 880 x 1136, 8-bit/color RGBA, non-interlaced
Screen Shot 2012-10-11 at 4.17.14 PM.png:                PNG image data, 880 x 1136, 8-bit/color RGBA, non-interlaced
breakpoint1.sh:                                          Bourne-Again shell script text executable
breakpoint2.sh:                                          Bourne-Again shell script text executable
bugtracker.txt:                                          UTF-8 Unicode text
error_svn_rename.txt:                                    UTF-8 Unicode English text
long_text.txt:                                           data
于 2012-10-11T16:55:55.560 に答える
1

試してみてくださいls | grep -v '\.' |file -f -。たとえば、次のディレクトリls

  2 ga\(\)\    ab cd  date.txt  ga() mo  times  x?gh

file *ショー

  2 ga\(\)\  : ASCII text, with very long lines
  ab cd:       empty
  date.txt:    ASCII text
  ga() mo:     PDF document, version 1.5
  times:       HTML document, ASCII text
  x?gh:        JPEG image data, JFIF standard 1.01

コマンドパイプ
ls | grep -v '\.' |file -f -
が示しています

  2 ga\(\)\  :           ASCII text, with very long lines
  ab cd:     empty
  ga() mo:       PDF document, version 1.5
  times:     HTML document, ASCII text
  x?gh:    JPEG image data, JFIF standard 1.01

(file -この例では、行内に余分なタブまたはスペースが出力されているようです。最初のファイル名には、コロンの前のスペースで示されているように、末尾に 2 つのスペースがあることに注意してください。) また、コマンド
ls | grep -v '\.' |file -f - |grep -i jpeg
が生成し たことにも注意してください。

  x?gh:    JPEG image data, JFIF standard 1.01
于 2012-10-11T19:34:30.383 に答える
1

file コマンドを使用する必要があります。改良できる簡単なコードを提案します。

for f in directory
do
    isJPEG=$(file $f | grep JPEG)
    if [ -n "$isJPEG" ]; then
       echo $f
    fi
done
于 2012-10-11T17:00:55.420 に答える