售前咨询
技术支持
渠道合作

读《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

 

上一篇:

下一篇:

相关文章