1. 批量杀进程
> kill -9 `ps -aef| grep process_name | awk '{ print $2 }'`
> ps -aef | grep process_name | awk '{ print $2 }' | xargs -i -t kill {}
2. 批量改文件内容
#!/bin/sh
#Name: rs4d - Replace String for current Directory recursively.usage="Usage: sh thisscript oldstring newstring"
[ -n "$1" -a -n "$2" ] || { echo $usage; exit 0; }d=`pwd`
echo
echo "CAUTION: all subdirs may be affected!"
echo
echo "Dir: $d"
echo "Old string: /"$1/""
echo "New string: /"$2/""
echo "Correct?[y/n]"read flag
[ $flag == "y" ] || { exit 0; }
print "OK"for i in `find . -exec grep -l $1 {} /;`; do
echo Editting $i
ed -s $i <<EOF
1,/$s/$1/$2/g
w
EOF
done
3. 批量文件改名
- 改后缀
#cat C_FileName
source=*.$1
target=$2
for f in $source; do
base=`basename $f .$1`
mv $f $base.$2
done
#The End - 改大小写
for file in `find . `; do
FILE=`echo $file | tr '[a-z]' '[A-Z]'`
[ $file != $FILE ] && mv $file $FILE
done - 去掉空格
有一系列文件,(文件名中间有空格):
Shortcut to ACDSee32.exe.lnk
Shortcut to EXESCOPE.EXE.lnk
Shortcut to FTERM.exe.lnk
...
如何将文件名中的"shortcut to"去掉?
方法一:
ls | sort | awk '{print "mv /"" $0 "/" /"" $0 "/""}' | sed s/Shortcut/ to/ //2 | sh
正则表达式中“/2”的意思在于“每一行中第二个与之匹配的位置”。
方法二:
while read file ; do
eval mv /'$file/' `echo $file | sed 's/Shortcut/ to/ //g'`
done <<!
`ls *Sh*`
!