shell文件存在相关判断参数
The tests below are test conditions provided by the shell:
* -b file = True if the file exists and is block special file.
* -c file = True if the file exists and is character special file.
* -d file = True if the file exists and is a directory.
* -e file = True if the file exists.
* -f file = True if the file exists and is a regular file
* -g file = True if the file exists and the set-group-id bit is set.
* -k file = True if the files’ “sticky” bit is set.
* -L file = True if the file exists and is a symbolic link.
* -p file = True if the file exists and is a named pipe.
* -r file = True if the file exists and is readable.
* -s file = True if the file exists and its size is greater than zero.
* -s file = True if the file exists and is a socket.
* -t fd = True if the file descriptor is opened on a terminal.
* -u file = True if the file exists and its set-user-id bit is set.
* -w file = True if the file exists and is writable.
* -x file = True if the file exists and is executable.
* -O file = True if the file exists and is owned by the effective user id.
* -G file = True if the file exists and is owned by the effective group id.
* file1 -nt file2 = True if file1 is newer, by modification date, than file2.
* file1 ot file2 = True if file1 is older than file2.
* file1 ef file2 = True if file1 and file2 have the same device and inode numbers.
* -z string = True if the length of the string is 0.
* -n string = True if the length of the string is non-zero.
* string1 = string2 = True if the strings are equal.
* string1 != string2 = True if the strings are not equal.
* !expr = True if the expr evaluates to false.
* expr1 -a expr2 = True if both expr1 and expr2 are true.
* expr1 -o expr2 = True is either expr1 or expr2 is true.
Shell中的数据问题
ArrayName=(”element 1″ “element 2″ “element 3″) #数组定义
echo ${#ArrayName[@]}
echo “The number of elements in the array is ${#ArrayName[*]}”
例子
#!/bin/bash
# define array
# name server names FQDN
NAMESERVERS=(”ns1.nixcraft.net.” “ns2.nixcraft.net.” “ns3.nixcraft.net.”)
# get length of an array
tLen=${#NAMESERVERS[@]}
# use for loop read all nameservers
for (( i=0; i<${tLen}; i++ ));
do
echo ${NAMESERVERS[$i]}
done
Sample output:
ns1.nixcraft.net.
ns2.nixcraft.net.
ns3.nixcraft.net.
建议继续学习:
- 海量小文件存储 (阅读:7736)
- 其实,文件也可以truncate (阅读:7536)
- 你可能不知道的Shell (阅读:7079)
- 面向对象的Shell脚本 (阅读:5291)
- 关于Linux的文件系统cache (阅读:4922)
- 在 shell 脚本里打日志 (阅读:4921)
- Bash如何取得当前正在执行的脚本的绝对路径? (阅读:5003)
- 使用Shell快捷键助你一臂之力 (阅读:4561)
- Perl 倒行分析文件方法。perl读文本文件,从末尾往前读. (阅读:4571)
- 修改系统最大文件句柄数 (阅读:4407)
扫一扫订阅我的微信号:IT技术博客大学习
- 作者:zja601 来源: Zhang Jiuan' Notes
- 标签: shell 文件
- 发布时间:2010-01-26 16:52:50
-
[74] memory prefetch浅析
-
[53] find命令的一点注意事项
-
[36] 基本排序算法的PHP实现
-
[33] 卡诺模型―设计品质与设计价值的思考
-
[32] Oracle bbed工具的编译
-
[26] 程序员技术练级攻略
-
[26] 8大实用又重要Mac使用技巧
-
[26] 读书笔记-壹百度:百度十年千倍的29条法则
-
[24] 两行 JavaScript 代码
-
[22] 小屏幕移动设备网页设计注意事项