Shell programming notes

  
 

[ -a FILE ] True if FILE exists. [ -b FILE ] True if FILE exists and is a block special file. [ -c FILE ] True if FILE exists and is a word special file. [ -d FILE ] True if FILE exists and is a directory. [ -e FILE ] True if FILE exists. [ -f FILE ] True if FILE exists and is a normal file. [ -g FILE ] True if FILE exists and SGID is already set. [ -h FILE ] True if FILE exists and is a symbolic link. [ -k FILE ] True if FILE exists and a sticky bit has been set. [ -p FILE ] True if FILE exists and is a name pipe (F if O). [ -r FILE ] True if FILE exists and is readable. [ -s FILE ] True if FILE exists and the size is not 0. [ -t FD ] True if the file descriptor FD is open and points to a terminal. [ -u FILE ] True if FILE exists and SUID (set user ID) is set. [ -w FILE ] True if FILE exists if FILE exists and is writable. [ -x FILE ] True if FILE exists and is executable. [ -O FILE ] True if FILE exists and is a valid user ID. [ -G FILE ] True if FILE exists and is a valid user group. [ -L FILE ] True if FILE exists and is a symbolic link. [ -N FILE ] True if FILE exists and has been mod if ied since it was last read. [ -S FILE ] True if FILE exists and is a socket. [ FILE1 -nt FILE2 ] If FILE1 has been changed more recently than FILE2, or if FILE1 exists and FILE2 does not true. [ FILE1 -ot FILE2 ] True if FILE1 is older than FILE2, or if FILE2 exists and FILE1 does not exist. [ FILE1 -ef FILE2 ] True if FILE1 and FILE2 point to the same device and node number. [ -o OPTIONNAME ] True if the shell option “OPTIONNAME” is on. [ -z STRING ] “STRING” is zero if the length is zero. [ -n STRING ] or [ STRING ] “STRING” is non-zero and non-zero is true. [ STRING1 == STRING2 ] If 2 strings are the same. “=” may be used instead of “==” for strict POSIX compliance is true. [ STRING1 != STRING2 ] True if the strings are not equal. [ STRING1 < STRING2 ] True if “STRING1” sorts before “STRING2& quoquo; lexicographically in the current locale. [ STRING1 > STRING2 ] True if “STRING1” sorts after “STRING2& quoquo; lexicographically in the current locale. [ ARG1 OP ARG2 ] “OP” is one of -eq, -ne, -lt, -le, -gt or -ge. These arithmetic binary operators return true if “ARG1” is equal to, not equal to, less Than, less than or equal to, greater than, or greater than or equal to “ARG2”, respectively. “ARG1” and “ARG2” are integers.

for in format

for no $variable in string do$ variable done a simple string enumeration traversal method, using the for in format to string the space by string serviceSERVICES="80 22 25 110 8000 23 20 21 3306 " For x in $SERVICES do iptables -A INPUT -p tcp --dport $x -m state --state NEW -j ACCEPT done


Let sed handle only one line at a time Syntax:

sed '/abc/s/$//nnew line/;ta;b;:a;n;ba' enters the infinite loop after the first match, so the second and third Sub-matching will not happen. :a Mark ta matches and jumps to the label ab goto End: a mark n read the next line ba goto label a

sed "/abc/s/$//nnew line/;ta;b;:a ;n;ba" alert >alert1



Copyright © Windows knowledge All Rights Reserved