linux脚本结束语,读《Linux Shell脚本攻略》第9章笔记—结束语
1. ps
-e:(every),選項-ax(all)也可以生成同樣的輸出
-f:顯示更多列
-o:指定想要顯示的列(pcpu,pid,ppid,pmem,comm,cmd,user,nice,time,etime,tty,euid,stat)
-o的參數以逗號操作符(,)作為定界符,值得注意的是逗號操作符與它分隔的參數之間是沒有空格的。在大多數情況下,選擇-o都是和選項-e結合使用的
(-eo),因為它需要列出運行在系統中的每一個進程。但是如果-o需要使用某些過濾器,例如列出特定用戶擁有的進程,那么就不再使用-e,-e和過濾器
結合使用將沒有任何實際效果,依舊會顯示所有的選項
–sort:將ps命令的輸出根據特定的列進行排序
-C:找出給定命令名對應的進程ID(如:# ps -C java -o pid=或者# pgrep java,pgrep只需要命令名的一部分作為輸出參數來提取Bash命令(pgrep jav也可以),ps需要輸入命令準確的全名)
-L:顯示線程的相關信息
ps -eo cmd e:顯示進程的環境變量
2. 圖像文件的批量縮放及格式轉化
#!/bin/bash
#Filename: image_help.sh
#Description: A script for image management
if [ $# -ne 4 -a $# -ne 6 -a $# -ne 8 ];
then
echo Incorrect number of arguments
exit 2
fi
while [ $# -ne 0 ];
do
case $1 in
-source) shift; source_dir=$1 ; shift ;;
-scale) shift; scale=$1 ; shift ;;
-percent) shift; percent=$1 ; shift ;;
-dest) shift ; dest_dir=$1 ; shift ;;
-ext) shift ; ext=$1 ; shift ;;
*) echo Wrong parameters; exit 2 ;;
esac;
done
for img in `echo $source_dir/*` ;
do
source_file=$img
if [[ -n $ext ]];
then
dest_file=${img%.*}.$ext
else
dest_file=$img
fi
if [[ -n $dest_dir ]];
then
dest_file=${dest_file##*/}
dest_file="$dest_dir/$dest_file"
fi
if [[ -n $scale ]];
then
PARAM="-resize $scale"
elif [[ -n $percent ]];
then
PARAM="-resize $percent%"
fi
echo Processing file : $source_file
convert $source_file $PARAM $dest_file
done
結束語
很久沒有仔細的看完整本書并記下筆記,曾經幾度想過放棄,但是不能半途而廢,終于堅持下來了,呵呵。過程雖然枯燥乏味,但是學到很多有用的技巧,以后得多練練,其實還是有點意思的,哈哈,感覺自己awk數組方面不太熟悉,下一本書《sed與awk》。
Wed Jan 23 11:14:44 CST 2013
總結
以上是生活随笔為你收集整理的linux脚本结束语,读《Linux Shell脚本攻略》第9章笔记—结束语的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 工作中常用的linux命令,工作中常用的
- 下一篇: linux检测病毒工具,Linux下查杀