shell文件存在的判断
来源:互联网 发布:树莓派kali linux中文 编辑:程序博客网 时间:2024/05/16 11:32
判断文件:
WORKDIR=/home/tmp
LOCAL_LIST_FILE=$WORKDIR/local.list
#if no local.txt file, generate a new one
if [ ! -f "$LOCAL_LIST_FILE" ]; then
touch $LOCAL_LIST_FILE
fi
注意:一定要有空格,判断文件是否存在,如果不存在,就生成一个新的
if [ ! -d /mnt ] # be sure the directory /mnt exists
then
mkdir /mnt
fi
目录。/mnt是否存在,不存在就生成目录/mnt
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.
* 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.
WORKDIR=/home/tmp
LOCAL_LIST_FILE=$WORKDIR/local.list
#if no local.txt file, generate a new one
if [ ! -f "$LOCAL_LIST_FILE" ]; then
touch $LOCAL_LIST_FILE
fi
注意:一定要有空格,判断文件是否存在,如果不存在,就生成一个新的
if [ ! -d /mnt ] # be sure the directory /mnt exists
then
mkdir /mnt
fi
目录。/mnt是否存在,不存在就生成目录/mnt
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.
判断文件大小还可以用:
set filesize = `ls -| $filename | awk '{print $5}'`
if($filesize == 0) then 文件为空! endif
* 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文件存在的判断
- shell文件存在的判断 shell数组
- Shell 判断文件是否存在的方法
- shell判断文件是否存在
- Shell--判断文件是否存在
- shell判断文件是否存在
- shell判断文件是否存在
- shell判断文件是否存在
- shell 判断文件是否存在
- shell 判断文件是否存在
- shell 判断文件是否存在
- shell判断文件是否存在
- Shell判断文件是否存在
- shell判断文件是否存在
- shell判断文件是否存在
- shell 判断文件是否存在
- shell判断文件是否存在
- shell判断文件是否存在
- zjut 1046 绩点计算
- 项目-团队-技术-个人(提拔篇)
- 自动切换ip地址批处理
- 大型互联网站解决海量数据的常见策略
- 封装
- shell文件存在的判断
- C++杂记/读书 2011/12/19
- Altium.Designer铺铜技巧
- LAYOUT焊盘过孔大小设计标准
- css滚动
- 总结一下本项目的一点感触
- 跆拳道
- 常见编译调试错误
- 原来数学还是很重要!