- 重定向输出
| > | 输出内容保存到文件 |
| >> | 输出内容追加到文件 |
标准输出和错误输出同时重定向:
$ kill -1 1234 > /dev/null 2>&1
-
重定向输入
$ more < killout.txt
$ ps > abc.txt
$ sort abc.txt > pssort.out
用管道可以优化为:
$ ps | sort > pssort.out
可以在命令行直接执行,也可以写在脚本文件中执行
#!/bin/sh
for i in `ls -a`
do
echo $i
donetime1=`date +%s%N|cut -c1-13`
while true; do
time2=`date +%s%N|cut -c1-13`
time_gap=$((${time2}-${time1}))
if [ $time_gap -gt 100 ]; then
time1=$time2
...
else
...
fi
donepara=$1
curtime=`date "+%Y-%m-%d %H:%M:%S"`
if [ ! $para ]; then
echo "Current Time : $curtime"
elif [ "$para" == "start" ];then
echo "Start Time : $curtime"
elif [ "$para" == "end" ];then
echo "End Time : $curtime"
else
echo "Current Time : $curtime"
fised -i 's/XX = g++/XX = g++ -pg/g' `find | grep "Makefile$"`
sed -i 's/XX = g++/XX = g++ -DMULTI_STREAM/g' Makefile while(`pgrep -f prepare1 | wc -l`)
do
sleep 1
done
等待prepare1执行完后再继续后面的代码
echo -e "please input a value:\c"