[英]How to check if all the files in a folder are of the same format
I have a folder which contains a list of files. 我有一个包含文件列表的文件夹。 The problem is they dont have extensions.
问题是他们没有扩展名。 I want to check if they are JPEG or JPG format.
我想检查它们是否为JPEG或JPG格式。 I tried this
我试过了
find folder -type f -not -name "*.*"
The output is 输出是
folder/t351
folder/t352
folder/t353
folder/t354
folder/t355
I tried using Regex but since the name of the files have no extensions It din't work out. 我尝试使用Regex,但是由于文件名没有扩展名,因此无法正常工作。 Can someone tell me how I can validate the files and check if they have a certain format.
有人可以告诉我如何验证文件并检查它们是否具有特定格式。
How about this? 这个怎么样?
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
You should use the file command. 您应该使用file命令。 I propose you a quick code that you can refine:
我为您提供了一个可以完善的快速代码:
for f in directory
do
isJPEG=$(file $f | grep JPEG)
if [ -n "$isJPEG" ]; then
echo $f
fi
done
Try ls | grep -v '\\.' |file -f -
试试
ls | grep -v '\\.' |file -f -
ls | grep -v '\\.' |file -f -
ls | grep -v '\\.' |file -f -
. ls | grep -v '\\.' |file -f -
。 For example, in a directory where ls
shows 例如,在
ls
显示的目录中
2 ga\(\)\ ab cd date.txt ga() mo times x?gh
and file *
shows 和
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
the command pipe 命令管道
ls | grep -v '\\.' |file -f -
shows 表演
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
(Apparently file -
is outputting extra tabs or spaces within lines in this example. Note, the first file name has two spaces at its end, as seen by spaces before the colon.) Also note, the command (显然
file -
在本例中,输出线内多余的制表符或空格注意,第一个文件名在其端部的两个空间,由冒号之前的空间所看到。)还要注意,该命令
ls | grep -v '\\.' |file -f - |grep -i jpeg
produced: 生产:
x?gh: JPEG image data, JFIF standard 1.01
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.