#!/bin/sh
proc() {
c0=’-’
c1=’/’
c2=’|’
c3=’/’
begin=$1
end=$2
row=$3
pos1=`expr $begin + 1`
pos2=`expr $begin + 5`
printf "/033[2J"
while [ $begin -le $end ]; do
index=`expr $begin % 4`
pro=`echo "scale=0; ${begin}*100/$end" | bc`
eval printf /"’/033[${row};${bos1}H$c’$index ’$pro%% ’/"
begin=`expr $begin + 1`
done
echo "done"
}
# call subroutine
proc 0 102 20
1.1 shell写的进度指示条2(旋转型):
drawper ()
{
_per=`expr $1 /* 100 / $2`
case `expr $_per / 4 % 4` in
0) _char="|" ;;
1) _char="/" ;;
2) _char="-" ;;
3) _char="//" ;;
esac
printf "/r$_char $_per%%"
if [ $1 -eq $2 ];then
printf "/n"
fi
}
i=1
while [ $i -le 100 ]
do
drawper $i 100
i=`expr $i + 1`
done
1.2 shell写的进度指示条3(方块前进型):
#!/bin/sh
abort() {
printf "/033[m/n"
exit
}
# do nothing, just simulate time consume.
idle() {
i=1
sum=`date +%S`
sum=`expr $sum /* $sum | cut -b 1`
sum=`expr $sum /* 10`
while [ $i -le $sum ]; do
i=`expr $i + 2 `
trap abort 2
done
}
proc() {
begin=$1
end=$2
row=$3
pos1=`expr $begin + 1`
pos2=`expr $end - 1`
mid=`echo "($begin+$end)/2-2" |bc`
printf "/033[2J"
printf "/033[${row};${begin}H["
printf "/033[${row};${end}H]"
while [ $pos1 -le $pos2 ]; do
pro=`echo "scale=0; ($pos1 - $begin)*100/($pos2-$begin)" | bc`
if [ $pos1 -gt $mid ]; then
printf "/033[7m/033[${row};${mid}H$pro%%/033[${row};${pos1}H:"
else
printf "/033[m/033[${row};${mid}H$pro%%/033[7m/033[${row};${pos1}H:"
fi
pos1=`expr $pos1 + 1`
idle
trap abort 2
done
printf "/033[m/n"
echo "done"
}
# call subroutine
printf "### proc 1 80 10 ### hit ENTER to continue "
if read a; then
proc 1 80 10
fi
printf "### proc 25 55 10 ### hit ENTER to continue "
if read a; then
proc 25 55 20
fi
--------------------------
ping -c 5 -f hostname | tail -1 | awk '{ print $4 }' | awk -F "/" '{ print $2 }'
--------------------
sed 's/id=1/id=5/g' test.txt > test2.txt
-------------------------
netstat -na | grep 192.168.1.246:80 | grep TIME_WAIT | cut --delimiter=" " --fields="21" | cut --
fields="1" | sort | uniq | wc -l
----------------------
unix2dos filename
比如
echo "Error."
我想让Error显示为red
--------------------------
echo '^[[40;31m显示内容'
注意:^[ 的输入方法是ctrl+v键,再按ESC键
第二个 [ 是直接输入 [ 的
;前的数字是背景色,后面为前景色
背景色:
40黑41红42绿43黄44青45蓝46青47白
前景色:
30黑31红32绿33黄34蓝35紫36青37白
------------------
find dir -print|xargs grep -l yourword
------------
mkdir a{1,2,3,4,5,6}
或者
for i in 1 2 3 4 5 6; do
mkdir a$i
done
------------------------
begin='Jun 23 15:00'
end='Jun 24 15:00'
- - - - - $end - - - - -
`ls -lrtFR`
!
-----------------------------
LINUX、FREEBSD下用
#killall httpd
or
# kill -9 `ps -ef |grep httpd|awk '{print $2}'`
例如:
The WHO's top official for Asia, Dr. Shigeru Omi, announced Tuesday that the advisory warning against travel
The move now means there are no SARS-related verb=travel warnings anywhere in the world, after nearly four
-----------
sed 's/.* verb=/([^ ]/{1,/}/) .*//1/' filename
首先s///的意思是替换的意思,用后边的内容把前边的部分替换掉~
第一个".*"的意思是不"verb="前边的任何东西,可以是零个或多个
最后边的同理
中间的部分"/"是转意字符~ 两个小阔号中的内容就是后边的/1,这是sed中的后向引用."[^ ]"是非空格的意思,大阔号中的1代
如通,无任何提示,如不通,屏幕出现提示,并且发出声音告警,
----------------------------
更改一下目标地址和错误消息就可以了。
^G 的输入:Ctrl + v; Ctrl + g;
do
ping -c 1 -w 1 TARGETADDR > /dev/null 2>&1;
if [ "$?" -eq "1" ]; then
echo "ERROR_MESSAGE" && echo ^G;
fi;
sleep 300;
done
--------------------
user guest guest
prompt off
lcd /usr/local/xx
cd mm/html
mput *
cd ../../nn/htm
lcd /usr/local/yy
mput *
by
EOF
----------------
1。先找到磁带机的设备文件
ioscan -kfnCtape
2.比如是/dev/rmt/0m
3.将磁带插入磁带机
4。用tar cvf file.tar /directory写入磁带。
----------
tar cv file 是覆盖磁带的所有
tar rv file 是追加
tar xv 是显示
123,345,678,789
不打印第二列
123,678,789
-------------------
awk能做,但不如用cut更直接:
cut -d "," -f1,3 filename
----------------
awk -F, '{print $1 "," $3 }' filename
---------------
nl filename