用SHELL编程问题,如何判断文件类型

用SHELL编程问题,如何判断文件类型,第1张

应该是bash吧:脚本蔽森尺的写法是这样的:file_name=xxxxxxxif [ -d $file_name ]

then

echo "directory"

else

echo "not a directory"

fi 下春好面是全部参数,里面就有你需宏高要的:-a file exists.

-b file exists and is a block special file.

-c file exists and is a character special file.

-d file exists and is a directory.

-e file exists (just the same as -a).

-f file exists and is a regular file.

-g file exists and has its setgid(2) bit set.

-G file exists and has the same group ID as this process.

-k file exists and has its sticky bit set.

-L file exists and is a symbolic link.

-n string length is not zero.

-o Named option is set on.

-O file exists and is owned by the user ID of this process.

-p file exists and is a first in, first out (FIFO) special file or

named pipe.

-r file exists and is readable by the current process.

-s file exists and has a size greater than zero.

-S file exists and is a socket.

-t file descriptor number fildes is open and associated with a

terminal device.

-u file exists and has its setuid(2) bit set.

-w file exists and is writable by the current process.

-x file exists and is executable by the current process.

-z string length is zero.

dos格式和unix格式差别就在于换行符

只要把所有的换行符统一衫纤,就完成了转化,如

unix2dos 是转为dos格式

dos2unix 是转为unix格式

但是判断就不是绝对的了,因为有可能文件中漏陪既有dos换行符,也有unix换行符,因此是模糊的,并没有什么意义。

有使用返塌蠢用file 命令可以显示格式,但并不一定有效。


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存