Linux的几个操作,记录备忘
阿债
posted @ 2009年7月22日 00:38
in 未分类
, 1607 阅读
1. 后台运行命令,不显示命令产生的输出,使用nohup
nohup command > null 2>&1 &
把command替换成您的命令和参数
此段参考 http://www.niutian365.com/blog/article.asp?id=204
2. 批量替换文件内容,比如将所有当前目录及子目录下.html文件中的gb2312替换成utf-8
find -type f -name '.html' | xargs perl -i -pe s%gb2312%utf-8%g
此段参考 http://blog.chinaunix.net/u/12973/showart_397701.html
3. 批量转换文件编码(含自动判断原文件编码)
此段参考 http://www.lpi-china.org/bbs/viewthread.php?tid=2912
比如将所有当前目录及子目录下.php文件GB2312或Big5编码转换成utf-8
find . -type f -name '*.php' | xargs -l sh cc.sh
所使用的cc.sh脚本内容如下
#!/bin/bash
#文件名
fname=$1
#临时文件,用来保存转换的结果
tmpfile="cc`date %0H%0M%0S`.liu"
#没有输入文件名
if [ -z ${fname} ] ; then
echo "Bad file name. ";
exit;
fi
#输入的文件不存在
if [ ! -f ${fname} ] ; then
echo ...
评论 (0)