1.用16进制查看文件
hexdump -C [file]
?
2.文件linux<->windows格式转换
windows to linux: dos2unix [file] linux to windows: unix2dos [file]
?
3.查看系统codepage
locale charmap
?
4.Error output
echo >&2
?
5. awk '{if($4~/NRW1/ && $4!~/NRW0/)next}{print $0}' /home/zdlolnxa/PDSNZ.FFB.HBA.NZ.WTAX.BS.IN.FILE
?
awk ' $4 ~/[0]$/{print $0}' /home/zdlolnxa/PDSNZ.FFB.HBA.NZ.WTAX.BS.IN.FILE
?
6.替换文件中的字符串
find -name '目标文件' | xargs perl -pi -e 's|要被替换的字符串|替换的字符串|g'
?
7.script传入参数
全部参数: $* 或 $@
参数个数: $#
最后一个参数: ${!#}
?
8.在变量中使用传入参数,用 ! 代替 $,并{}起来
paramNum=$#
echo $paramNum
for((i=0;i do
?? echo parameter $i is ${!i}
done
?
9.shift , 用在当传入参数不确定的情况
?
count=1
while [ -n "$1" ]
do
??echo "Parameter #$count = $1"
??count=$[ $count + 1 ]
??shift
done
?
10.Show directory ls -d */
?
11.永久重定向
exec 2>testerr
?
12.创建临时文件
本地临时文件
mktemp XXXXXX.tmp
/tmp临时文件
mktemp -t XXXXXX.tmp
?
13.在sed中使用循环指定输出行
for((i=1;i<=$commFB;i++))
do
commMsg=grep 'Feedback' $tempLog | sed -n "$i"p | awk '{print $1}'
echo commMsg $commMsg
done
14.切割字符
echo $DCB | gawk -F, '{print $1}'
?
15.sftp between two server without password
genKey:
1. ssh-keygen -t rsa (press “ENTER” for each questions)
2. Then you can find the key under user/.ssh/id_rsa.pub (public key) and id_rsa
exchange key
copy id_rsa.pub content to another server's authorized_keys
3. chmod 600 .ssh
?
16.Find out files last modify day is over ? days ago
?? find . -mtime +n -type d