怎么在shell脚本里判断文件名的后缀

怎么在shell脚本里判断文件名的后缀,第1张

因为linux并不针对文件后缀进行分类

所以如果你想判断文件后缀,通过shell的话,只能自己写脚本

你可以通过awk或者sed把文件名点后面的文字提取出来

然后用if进行判断是否和你设定的一致,来判断后缀

可以用“test 条件表达式”进行测试,如:test -f /etc/fstab 测试文件/etc/fstab文件是否存在

-e File如果文件File存在(Exist),则为True-s File如果文件File存在且文件大小(Size)大于零,则为True-f File如果文件File存在且是普通文件(File),则为True-d File如果文件File存在且是目录(Directory),则为True-b File如果文件File存在且是块(Block)特殊文件,则为True-c File如果文件File存在且是字符(Character)特殊文件,则为True-L File如果文件File存在且是符号链接(Link)文件,则为True-r File如果文件File存在且是可读的(Readable),则为True-w File如果文件File存在且是可写的(Writable),则为True-x File如果文件File存在且是可执行的(Executable),则为True-O File如果文件File存在且属于当前用户(Owner),则为True-G File如果文件File存在且属于当前用户组(Group),则为TrueFile1 -nt File2如果文件File1新于(Newer Then) File2,则为TrueFile2 -ot File2如果文件File1旧于(Older Then) File2,则为True


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/11851407.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存