<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>阿债的山寨实验室 &#187; nohup</title>
	<atom:link href="http://blog.declab.com/tag/nohup/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.declab.com</link>
	<description></description>
	<lastBuildDate>Thu, 27 May 2010 03:45:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Linux的几个操作，记录备忘</title>
		<link>http://blog.declab.com/server/2009/linux%e7%9a%84%e5%87%a0%e4%b8%aa%e6%93%8d%e4%bd%9c%ef%bc%8c%e8%ae%b0%e5%bd%95%e5%a4%87%e5%bf%98/</link>
		<comments>http://blog.declab.com/server/2009/linux%e7%9a%84%e5%87%a0%e4%b8%aa%e6%93%8d%e4%bd%9c%ef%bc%8c%e8%ae%b0%e5%bd%95%e5%a4%87%e5%bf%98/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 14:24:28 +0000</pubDate>
		<dc:creator>阿债</dc:creator>
				<category><![CDATA[服务器管理]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[charset]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nohup]]></category>

		<guid isPermaLink="false">http://rblog.declab.com/2009/1/linux%e7%9a%84%e5%87%a0%e4%b8%aa%e6%93%8d%e4%bd%9c%ef%bc%8c%e8%ae%b0%e5%bd%95%e5%a4%87%e5%bf%98/</guid>
		<description><![CDATA[1. 后台运行命令，不显示命令产生的输出，使用nohup
2. 批量替换文件内容，比如将所有当前目录及子目录下.html文件中的gb2312替换成utf-8
3. 批量转换文件编码(含自动判断原文件编码)


No related posts.

以上关联文章由 <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a> 提供支持。]]></description>
			<content:encoded><![CDATA[<p><span id="more-48"></span><br />
1. 后台运行命令，不显示命令产生的输出，使用nohup</p>
<pre lang="bash">nohup command &gt; /dev/null 2&gt;&amp;1 &amp;</pre>
<p>把command替换成您的命令和参数<br />
此段参考 http://www.niutian365.com/blog/article.asp?id=204</p>
<p>标准输入(0)、标准输出(1)、标准错误(2)</p>
<p>2&gt;&amp;1 的意思是将标准错误输出到和标准输出相同的地方</p>
<p>2. 批量替换文件内容，比如将所有当前目录及子目录下.html文件中的gb2312替换成utf-8</p>
<pre lang="bash">find -type f -name '.html' | xargs perl -i -pe s%gb2312%utf-8%g</pre>
<p>此段参考 http://blog.chinaunix.net/u/12973/showart_397701.html</p>
<p>3. 批量转换文件编码(含自动判断原文件编码)<br />
此段参考 http://www.lpi-china.org/bbs/viewthread.php?tid=2912<br />
比如将所有当前目录及子目录下.php文件GB2312或Big5编码转换成utf-8</p>
<pre lang="bash">find . -type f -name '*.php' | xargs -l sh cc.sh</pre>
<p>所使用的cc.sh脚本内容如下<br />
<!--more--></p>
<pre lang="bash">#!/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 "File is not existed.FILE="${fname};
exit;
fi
################################################
# f_code：现有文件的编码，当不太清楚现有文件的编码的时候，
# 可以同时指定的几种可能的编码
# t_code：希望转换成的目标编码
################################################
#比如要将GB2312或者UTF-8的文件转换成BIG5（繁体）文件
t_code="BIG5" #目标编码
f_code="GB2312 UTF-8" #可以转换的文字编码

#判断系统文字编码是否为GB2312，是的话则将BIG5或者UTF-8编码的文件转换成系统一样
#的GB2312
echo $LANG | grep -i GB2312&gt; /dev/null
if [ $? -eq 0 ] ; then
t_code="GB2312" #目标编码
f_code="BIG5 UTF-8" #可以转换的文字编码
fi

#判断系统文字编码是否为BIG5, 是的话则将GB2312或者UTF-8编码的文件转换成系统一样
#的GB2312
echo $LANG | grep -i BIG5 &gt; /dev/null
if [ $? -eq 0 ] ; then
t_code="BIG5" #目标编码
f_code="GB2312 UTF-8" #可以转换的文字编码
fi
#如果要把GB2312,BIG5文字编码的文件统一转换成UTF-8,则应该这样
t_code="UTF-8" #目标编码
f_code="GB2312 BIG5" #可以转换的文字编码

#当然你也可以任意设置你需要互相转换的编码，但主意要保证编码之间可以自由转换。比如
#你要将GB2312转换成某种西欧编码，则没有什么意义了。
normal_msg=""
error_msg=""
#依次尝试从可以转换的文字编码开始对文件进行编码转换
for code in ${f_code} ; do
#文字编码转换
iconv -f $code -t $t_code ${fname} &gt; ${tmpfile}
#转换成功，一旦转换成功则不用再尝试用其他编码来读取文件
if [ $? -eq 0 ] ; then
normal_msg="ICONV SUCCESSED! FILENAME=${fname} F_CODE=$code,T_CODE=$t_code"
break
else #转换失败
if [ ! -z "${error_msg}" ] ; then
error_msg="${error_msg} "
fi
error_msg="${error_msg}ICONV FAILED! FILENAME=${fname} F_CODE=$code,T_CODE=$t_code"
fi
done
#输出转换结果消息
#转换成功，则输出转换成功消息；所有尝试转换都失败的时候，则输出所有转换失败消息
if [ -z "${normal_msg}" ] ; then
echo -e ${error_msg}
else
cp -f ${tmpfile} $fname
echo ${normal_msg}
fi

#删除临时文件
if [ -f ${tmpfile} ] ; then
rm -f ${tmpfile};
fi
</pre>


<p>No related posts.</p>
<p>以上关联文章由 <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a> 提供支持。</p>]]></content:encoded>
			<wfw:commentRss>http://blog.declab.com/server/2009/linux%e7%9a%84%e5%87%a0%e4%b8%aa%e6%93%8d%e4%bd%9c%ef%bc%8c%e8%ae%b0%e5%bd%95%e5%a4%87%e5%bf%98/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
