shell 去掉文件中的空行

去掉文件中的空行
cat filename | sed -e '/^$/d' > filename


保留最新的9个文件,其它的文件删除的命令语句
ls -t | awk '{if(NR>9){print $0}}' |xargs rm -f



$$ 
Shell本身的PID(ProcessID)
$!
Shell最后运行的后台Process的PID
$?
最后运行的命令的结束代码(返回值)
$-
使用Set命令设定的Flag一览
$*
所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。
$@
所有参数列表。如"$@"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。
$#
添加到Shell的参数个数
$0
Shell本身的文件名
$1~$n
添加到Shell的各参数值。$1是第1参数、$2是第2参数…

判断 test
test -f 是否参在并是文件
-d 是否参在并是目录
-e 文件是否存在
man test
判断7种文件类型
test -f $1 && cat $1普通文件
test -d $1 && ls -ld $1目录
test -L $1 && ls -ld $1连接文件
test -p $1 && ls -ld $1管道文件
test -S $1 && ls -ld $1套接字
test -b $1 && ls -ld $1块设备
test -c $1 && ls -ld $1字符设备
比较数字大小
#!/bin/bash
test $1 -gt $2 && echo $1
test $1 -lt $2 && echo $2
test $1 -eq $2 && echo $1=$2
判断字符串
#!/bin/bash
test $1 != $2 && echo 不相等
test $1 = $2 && echo $1=$2
组合判断
#!/bin/bash
test $1 -gt 5 -a $1 -lt 10 && echo $1
if
#!/bin/bash
if test $1 -gt 5(或if [ $1 -gt 5 ]注意空格)
then
echo $1
fi

#!/bin/bash
ping -c 1 -W 1 192.168.0.$1 &>/dev/null (-c 1表示ping一次,-W目标主机不可达超时为1秒)
if [ $? -eq 0 ]
then
echo link OK
esle
echo link no
fi

你可能感兴趣的:(shell 去掉文件中的空行)