用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.

unix中文件属性是不依赖于

扩展名

的,加上扩展名只是为了 *** 作者的方便。unix中一个文件是否能被执行,和

后缀名

没有太大的关系,主要看文件的属性有关。

例如:

-rwxr-xr-x

1

mythmy

mythmy

85

2009-03-09

11:45

A.txt

这个文件的文件名是A.txt

但是这是个可执行文件,因为其属性是:755。所以这个文件是所有人都可读,可执行的。

所以说不管扩展名是.sh还是.c只要其

文件属性

是可执行,就一样可以执行SHELL语句。


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

原文地址:https://54852.com/tougao/7923176.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存