$ ls -l | > while read perms links owner group size month day time file > do > printf "%10d %s\n" "$size" "$file" > totalsize=$(( ${totalsize:=0} + ${size:-0} )) > done $ echo ${totalsize-unset} ## print "unset" if variable is not set unset 通过使用进程替换,变量t...
-c Checks for the character special file. -p Checks for a named pipe (FIFO). -s Used to find whether the file size is greater than zero or not. -t Check whether the file descriptor is associated with the terminal or not. -r Used to find whether the file is readable or not. -w...
3. 两个档案之间的比较,如: test file1 -nt file2 -nt (newer than)判断 file1 是否比 file2 新 -ot (older than)判断 file1 是否比 file2 旧 -ef 判断 file2 与 file2 是否为同一档案,可用在判断 hard link 的判定上。 主要意义在判定,两个档案是否均指向同一个 inode 哩! 4. 关于两个整数之...
# Usage: lines "file" mapfile -tn 0 lines < "$1" printf '%s\n' "${#lines[@]}" } 1. 2. 3. 4. 5. 示例函数(bash 3): 此方法使用的内存少于mapfile方法,并在bash3中工作,但对于较大的文件,它的速度较慢。 lines_loop() { # Usage: lines_loop "file" count=0 while IFS= read ...
服务器的开发和管理离不开 Bash 脚本,掌握它需要学习大量的细节。 set命令是 Bash 脚本的重要环节,却...
1 bash script to check if a file exists over a certain size 0 Bash if file sizes are greater than 1kb 0 find the difference between two file sizes and compare in an if statement - Bash 1 How to check if the size of a file or a directory is larger than a value...
-u file 若文件存在且设置了SUID位,则为真 -w file 若文件存在且可写,则为真 -x file 若文件存在且可执行,则为真 -o file 若文件存在且被有效用户ID所拥有,则为真 -z string 若string长度为0,则为真 -n string 若string长度不为0,则为真 ...
(( a % 2 == 0 )) [ -n string ] string 的长度大于0 [ -z string ] string 的长度为0 string1=string2 字符串相等 string1!=string2 字符串不相等 [ int1 -gt int2 ] int1>int2 greater than [ int1 -ge int2 ] int1>=int2 greater equal ...
find . -size 10k -print Find all files greater than 10k in the current directory. egrep “(foo|bar)” file.txt Find the words foo and bar in file.txt. sed s/foo/bar/g file.txt Find the word foo and replace it with a bar in file.txt. locate file.txt Find the location of the...
/bin/bash # This script gives information about a file. FILENAME="$1" echo "Properties for $FILENAME:" if [ −f $FILENAME ]; then echo "Size is $(ls −lh $FILENAME | awk '{ print $5 }')" echo "Type is $(file $FILENAME | cut −d":" −f2 −)" echo "Inode ...