<?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>I am LAZY bones ? &#187; CLI软件</title>
	<atom:link href="http://luy.li/category/cli/feed/" rel="self" type="application/rss+xml" />
	<link>http://luy.li</link>
	<description>all linux</description>
	<lastBuildDate>Mon, 30 Aug 2010 01:26:21 +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>Common Internet File System</title>
		<link>http://luy.li/2010/07/16/cifs/</link>
		<comments>http://luy.li/2010/07/16/cifs/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 00:56:20 +0000</pubDate>
		<dc:creator>bones7456</dc:creator>
				<category><![CDATA[CLI软件]]></category>

		<guid isPermaLink="false">http://luy.li/?p=1656</guid>
		<description><![CDATA[Common Internet File System 是samba的一部分，用于取代 smbfs 来挂载windows的共享文件夹，cifs比smbfs应用更广。 要使用 Common Internet File System 需要linux内核开启 cifs 支持。具体是要打开 File systems &#8212;> Network File Systems &#8212;> CIFS support (advanced network filesystem, SMBFS successor) 这个选项。如果是模块的话，使用前确保加载了。 然后，挂载共享文件夹，可以用mount命令的 -t cifs 选项来调用 mount.cifs。具体是： sudo mount -t cifs //机器名或IP/远程/目录/ 本地挂载点 -o user=域/用户名%密码,iocharset=utf8 当然，没有域的话，也可以省略域。如果要指定其他mount的选项也是可以的，比如指定uid和gid之类的，这里就不多说了。 另外，如果gnome-base/gvfs开启了samba支持的话，也可以在nautilus的地址栏里直接输入 smb://机器名或IP/远程/目录/ 来打开远程目录，有密码时会弹出对话框输入。 这两种方法各有各的好处。]]></description>
			<content:encoded><![CDATA[<p>Common Internet File System 是samba的一部分，用于取代 smbfs 来挂载windows的共享文件夹，cifs比smbfs应用更广。<br />
要使用 Common Internet File System 需要linux内核开启 cifs 支持。具体是要打开 File systems  &#8212;> Network File Systems  &#8212;> CIFS support (advanced network filesystem, SMBFS successor) 这个选项。如果是模块的话，使用前确保加载了。<br />
然后，挂载共享文件夹，可以用mount命令的 -t cifs 选项来调用 mount.cifs。具体是：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-t</span> cifs <span style="color: #000000; font-weight: bold;">//</span>机器名或IP<span style="color: #000000; font-weight: bold;">/</span>远程<span style="color: #000000; font-weight: bold;">/</span>目录<span style="color: #000000; font-weight: bold;">/</span> 本地挂载点 <span style="color: #660033;">-o</span> <span style="color: #007800;">user</span>=域<span style="color: #000000; font-weight: bold;">/</span>用户名<span style="color: #000000; font-weight: bold;">%</span>密码,<span style="color: #007800;">iocharset</span>=utf8</pre></div></div>

<p>当然，没有域的话，也可以省略域。如果要指定其他mount的选项也是可以的，比如指定uid和gid之类的，这里就不多说了。</p>
<p>另外，如果gnome-base/gvfs开启了samba支持的话，也可以在nautilus的地址栏里直接输入 smb://机器名或IP/远程/目录/ 来打开远程目录，有密码时会弹出对话框输入。<br />
这两种方法各有各的好处。</p>
]]></content:encoded>
			<wfw:commentRss>http://luy.li/2010/07/16/cifs/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>cryptsetup &#8211; 分区加密工具</title>
		<link>http://luy.li/2010/06/26/cryptsetup/</link>
		<comments>http://luy.li/2010/06/26/cryptsetup/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 09:58:45 +0000</pubDate>
		<dc:creator>bones7456</dc:creator>
				<category><![CDATA[CLI软件]]></category>

		<guid isPermaLink="false">http://luy.li/?p=1619</guid>
		<description><![CDATA[cryptsetup是linux下的一个分区加密工具，和之前介绍过的eCryptfs不同的是：eCryptfs是文件系统级别的加密，而cryptsetup是分区级别的，比文件系统级别工作在更底层的位置，是在经过加密的块设备上，再创建文件系统，再挂载使用。这应该是纯软件能达到的最底层的加密了吧。 我折腾这玩意，是因为上篇文章说到，我要把/home的数据备份到另一个硬盘，而那个硬盘的物理安全性并不能得到充分地保证，所以只有通过加密来确保数据的安全了。如果当年陈老师也用这玩意的话，想必不会捅出这么大的篓子，呵呵。 废话不说，简单说说安装和使用的方法。 如果你是用ubuntu这类发行版的话，安装部分就很简单了，基本就是直接安装cryptsetup这个包，就完事了。 但是如果你和我一样也是用自己编译内核的发行版，比如gentoo的话，使用中可能会出现以下错误： /proc/misc: No entry for device-mapper found Is device-mapper driver missing from kernel? Failure to communicate with kernel device-mapper driver. Cannot initialize device-mapper. Is dm_mod kernel module loaded? Command failed with code 22: Cannot initialize device-mapper. Is dm_mod kernel module loaded? 这时候你不要急着去安装 device-mapper ，因为现在 device-mapper 已经并入到更强大的 lvm2 里面了，所以你要确保装了 lvm2 和在内核选项里选择了CONFIG_DM_CRYPT，如下： -&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/cryptsetup/">cryptsetup</a>是linux下的一个分区加密工具，和之前介绍过的<a href="http://luy.li/2009/09/11/ssh_publickey_fail_in_ecryptfs/">eCryptfs</a>不同的是：eCryptfs是文件系统级别的加密，而cryptsetup是分区级别的，比文件系统级别工作在更底层的位置，是在经过加密的块设备上，再创建文件系统，再挂载使用。这应该是纯软件能达到的最底层的加密了吧。<br />
我折腾这玩意，是因为<a href="http://luy.li/2010/06/26/unitek-y-1031/">上篇文章</a>说到，我要把/home的数据备份到另一个硬盘，而那个硬盘的物理安全性并不能得到充分地保证，所以只有通过加密来确保数据的安全了。如果当年陈老师也用这玩意的话，想必不会捅出这么大的篓子，呵呵。</p>
<p>废话不说，简单说说安装和使用的方法。<br />
如果你是用ubuntu这类发行版的话，安装部分就很简单了，基本就是直接安装cryptsetup这个包，就完事了。<br />
但是如果你和我一样也是用自己编译内核的发行版，比如gentoo的话，使用中可能会出现以下错误：</p>
<blockquote><p>/proc/misc: No entry for device-mapper found<br />
Is device-mapper driver missing from kernel?<br />
Failure to communicate with kernel device-mapper driver.<br />
Cannot initialize device-mapper. Is dm_mod kernel module loaded?<br />
Command failed with code 22: Cannot initialize device-mapper. Is dm_mod kernel module loaded?</p></blockquote>
<p>这时候你不要急着去安装 device-mapper ，因为现在 device-mapper 已经并入到更强大的 lvm2 里面了，所以你要确保装了 lvm2 和在内核选项里选择了CONFIG_DM_CRYPT，如下：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">-&gt; Device Drivers
  -&gt; Multiple devices driver support
    -&gt; Device mapper support
      -&gt; Crypt target support</pre></div></div>

<p>另外，还建议选取大文件支持的CONFIG_LBDAF和CONFIG_CRYPTO_AES两个内核选项，我这边不选取前者，会无法打开加密分区（虽然说LBDAF是2T+的单文件支持，而我的硬盘一共只有80G）；后者是一个内核里的加密算法API，我们就用这个算法来加密（也可以用其他的算法）。</p>
<p>说说怎么使用：<br />
建立一个加密的分区，很简单，执行下面的命令：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> cryptsetup <span style="color: #660033;">--verbose</span> <span style="color: #660033;">--verify-passphrase</span> <span style="color: #660033;">-c</span> aes-cbc-plain luksFormat <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1</pre></div></div>

<p>我的外接硬盘在 /dev/sdb1 ，因为这个命令会摧毁这个分区的所有数据，所以程序会让你确认，输入大写的YES，回车，就会让你输入两次密码，输完就搞定了。<br />
话外音：其实cryptsetup不仅支持用密码加密，还支持用文件来加密，可以是任意类型的文件，不过解密的时候，要确保文件一个字节都不差，用这个特性可以方便地构建解密U盘。</p>
<p>好了，加密完分区以后，要使用的话，可以这样：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> cryptsetup luksOpen <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1 back</pre></div></div>

<p>其中最后的“back”，可以是任意字符串，程序会提示输入之前设置的密码，输对密码以后，文件系统里就会多出一个 /dev/mapper/back ，接下来就可以像使用 /dev/sdXX 一样地使用这个 /dev/mapper/back 了。<br />
比如，建立一个ext4文件系统，挂载，复制文件之类：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> mkfs.ext4 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>back
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>back <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> XXX <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back<span style="color: #000000; font-weight: bold;">/</span>
....</pre></div></div>

<p>使用完以后，可以这样显式地关闭加密分区：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> cryptsetup luksClose <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>back</pre></div></div>

<p>看看如果别人偷你加密后的硬盘，想挂载看你的艳照时，会怎么样？哈哈：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1 <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">mount</span>: unknown filesystem <span style="color: #7a0874; font-weight: bold;">type</span> <span style="color: #ff0000;">'crypto_LUKS'</span></pre></div></div>

<p>PS： 现在ubuntu的易用性确实越来越好了，ubuntu里插入加密的硬盘后会自动判断，并直接弹出输入密码的窗口，输完自动挂载分区。</p>
]]></content:encoded>
			<wfw:commentRss>http://luy.li/2010/06/26/cryptsetup/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>linux下的“虚拟光驱”</title>
		<link>http://luy.li/2010/03/10/virtual_cdrom_in_linux/</link>
		<comments>http://luy.li/2010/03/10/virtual_cdrom_in_linux/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 06:38:01 +0000</pubDate>
		<dc:creator>bones7456</dc:creator>
				<category><![CDATA[CLI软件]]></category>

		<guid isPermaLink="false">http://li2z.cn/?p=1397</guid>
		<description><![CDATA[每当有人问我“你的linux下有没有类似‘虚拟光驱’的软件呢？”的时候，我就会轻轻一笑，自豪地说“别把事情想得太复杂，linux下根本就不用什么另外的软件，就能虚拟光驱了。”，然后那人一般就会似懂非懂地说一句：“哦。。这样啊~” 下面，就来介绍几个虚拟光驱相关的命令： 把物理光盘做成iso镜像，下面几个命令几乎等效，假设设备是/dev/cdrom： cp /dev/cdrom xxx.iso dd if=/dev/cdrom of=xxx.iso mkisofs -r -o xxx.iso /dev/cdrom readcd -v dev=/dev/cdrom -f xxx.iso 其中，用mkisofs还可以把一个文件夹模拟成iso： mkisofs -o xxx.iso /path/to/tree 如果要使用iso文件的话，就更简单了，可以mount到任意目录下： mount -o loop xxx.iso /path 注意以上某些命令可能需要root权限。 不过，还有个终极问题没有解决，我手头有一张《浙江省汽车驾驶人理科考试智能》的光盘，估计是用了什么防拷贝技术，使用以上方法都无法正确生成ISO文件，也无法全部复制里面的内容，具体操作过程如下： lily@LLY:~$ sudo mount -o ro,loop /dev/sr0 qc lily@LLY:~$ ls qc 试题10.db 试题11.db 试题12.db 试题1.db 试题2.db 试题3.db 试题4.db 试题5.db 试题6.db 试题7.db 试题8.db 试题9.db lily@LLY:~$ [...]]]></description>
			<content:encoded><![CDATA[<p>每当有人问我“你的linux下有没有类似‘虚拟光驱’的软件呢？”的时候，我就会轻轻一笑，自豪地说“别把事情想得太复杂，linux下根本就不用什么另外的软件，就能虚拟光驱了。”，然后那人一般就会似懂非懂地说一句：“哦。。这样啊~”<br />
下面，就来介绍几个虚拟光驱相关的命令：<br />
把物理光盘做成iso镜像，下面几个命令几乎等效，假设设备是/dev/cdrom：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>cdrom xxx.iso</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;"><span style="color: #000000; font-weight: bold;">if</span></span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>cdrom <span style="color: #007800;">of</span>=xxx.iso</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mkisofs <span style="color: #660033;">-r</span> <span style="color: #660033;">-o</span> xxx.iso <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>cdrom</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">readcd <span style="color: #660033;">-v</span> <span style="color: #007800;">dev</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>cdrom <span style="color: #660033;">-f</span> xxx.iso</pre></div></div>

<p>其中，用mkisofs还可以把一个文件夹模拟成iso：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mkisofs <span style="color: #660033;">-o</span> xxx.iso <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">tree</span></pre></div></div>

<p>如果要使用iso文件的话，就更简单了，可以mount到任意目录下：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-o</span> loop xxx.iso <span style="color: #000000; font-weight: bold;">/</span>path</pre></div></div>

<p>注意以上某些命令可能需要root权限。</p>
<p>不过，还有个终极问题没有解决，我手头有一张《浙江省汽车驾驶人理科考试智能》的光盘，估计是用了什么防拷贝技术，使用以上方法都无法正确生成ISO文件，也无法全部复制里面的内容，具体操作过程如下：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-o</span> ro,loop <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sr0 qc
lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~$ <span style="color: #c20cb9; font-weight: bold;">ls</span> qc
试题10.db  试题11.db  试题12.db  试题1.db  试题2.db  试题3.db  试题4.db  试题5.db  试题6.db  试题7.db  试题8.db  试题9.db
lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">umount</span> qc
lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-o</span> ro <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sr0 qc
lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~$ <span style="color: #c20cb9; font-weight: bold;">ls</span> qc
<span style="color: #000000;">2009</span>理论模拟考试.exe  AutoRun.ico  AutoRun.rdt  system               试题10.db  试题1.db  试题4.db  试题7.db
AutoRun.ard           autorun.inf  htm          安装使用说明.html    试题11.db  试题2.db  试题5.db  试题8.db
AutoRun.exe           autorun.pro  image.jpg    读安装使用说明.html  试题12.db  试题3.db  试题6.db  试题9.db
lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~$ <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-r</span> qc qc1
<span style="color: #c20cb9; font-weight: bold;">cp</span>: 正在读入<span style="color: #ff0000;">&quot;qc/试题3.db&quot;</span>: 输入<span style="color: #000000; font-weight: bold;">/</span>输出错误
<span style="color: #c20cb9; font-weight: bold;">cp</span>: 正在读入<span style="color: #ff0000;">&quot;qc/试题4.db&quot;</span>: 输入<span style="color: #000000; font-weight: bold;">/</span>输出错误
<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~$ <span style="color: #c20cb9; font-weight: bold;">ls</span> qc1
<span style="color: #000000;">2009</span>理论模拟考试.exe  AutoRun.ico  AutoRun.rdt  system               试题10.db  试题1.db  试题4.db  试题7.db
AutoRun.ard           autorun.inf  htm          安装使用说明.html    试题11.db  试题2.db  试题5.db  试题8.db
AutoRun.exe           autorun.pro  image.jpg    读安装使用说明.html  试题12.db  试题3.db  试题6.db  试题9.db
lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~$ <span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-s</span> qc qc1
<span style="color: #000000;">398463</span>	qc
<span style="color: #000000;">349720</span>	qc1</pre></div></div>

<p>有谁知道这种变态的光盘怎么搞定吗？</p>
]]></content:encoded>
			<wfw:commentRss>http://luy.li/2010/03/10/virtual_cdrom_in_linux/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>a2p──将awk程序转成perl</title>
		<link>http://luy.li/2010/02/12/a2p/</link>
		<comments>http://luy.li/2010/02/12/a2p/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 06:31:04 +0000</pubDate>
		<dc:creator>bones7456</dc:creator>
				<category><![CDATA[CLI软件]]></category>

		<guid isPermaLink="false">http://li2z.cn/?p=1367</guid>
		<description><![CDATA[呵呵，不管你觉得有没有必要，反正，就是有这样的工具了，而且还是perl包自带的哦（看来perl确实有点怪异，哈哈）。 别的不说了，拿个小程序演示下，下面的awk程序是用来统计当前登录系统的人数的，其实就是 who &#124; wc -l BEGIN &#123; while &#40; &#34;who&#34; &#124; getline &#41; n++ print n &#125; 然后这样： lily@LLY:~/test/awk$ awk -f count.awk 3 lily@LLY:~/test/awk$ a2p count.awk &#62; count.pl lily@LLY:~/test/awk$ perl count.pl 3 哈哈，确实能执行哦，再让我们来看看转出来的perl程序，格式都还蛮工整的呢： #!/usr/bin/perl eval 'exec /usr/bin/perl -S $0 ${1+&#34;$@&#34;}' if $running_under_some_shell; # this emulates #! processing on NIH machines. # (remove #! line [...]]]></description>
			<content:encoded><![CDATA[<p>呵呵，不管你觉得有没有必要，反正，就是有这样的工具了，而且还是perl包自带的哦（看来perl确实有点怪异，哈哈）。<br />
别的不说了，拿个小程序演示下，下面的awk程序是用来统计当前登录系统的人数的，其实就是  who | wc -l</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">BEGIN <span style="color: #009900;">&#123;</span> 
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;who&quot;</span> <span style="color: #339933;">|</span> getline <span style="color: #009900;">&#41;</span> n<span style="color: #339933;">++</span> 
print n 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>然后这样：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~<span style="color: #000000; font-weight: bold;">/</span>test<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">awk</span>$ <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-f</span> count.awk
<span style="color: #000000;">3</span>
lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~<span style="color: #000000; font-weight: bold;">/</span>test<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">awk</span>$ a2p count.awk <span style="color: #000000; font-weight: bold;">&gt;</span> count.pl 
lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~<span style="color: #000000; font-weight: bold;">/</span>test<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">awk</span>$ <span style="color: #c20cb9; font-weight: bold;">perl</span> count.pl
<span style="color: #000000;">3</span></pre></div></div>

<p>哈哈，确实能执行哦，再让我们来看看转出来的perl程序，格式都还蛮工整的呢：</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
<span style="color: #000066;">eval</span> <span style="color: #ff0000;">'exec /usr/bin/perl -S $0 ${1+&quot;$@&quot;}'</span>
    <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$running_under_some_shell</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;"># this emulates #! processing on NIH machines.</span>
			<span style="color: #666666; font-style: italic;"># (remove #! line above if indigestible)</span>
&nbsp;
<span style="color: #000066;">eval</span> <span style="color: #ff0000;">'$'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$1</span><span style="color: #339933;">.</span><span style="color: #ff0000;">'$2;'</span> <span style="color: #b1b100;">while</span> <span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/^([A-Za-z_0-9]+=)(.*)/</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;"># process any FOO=bar switches</span>
&nbsp;
<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>WHO_FH<span style="color: #339933;">,</span> <span style="color: #ff0000;">'who|'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">'Cannot pipe from &quot;who&quot;.'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$,</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">' '</span><span style="color: #339933;">;</span>		<span style="color: #666666; font-style: italic;"># set output field separator</span>
<span style="color: #0000ff;">$\</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>		<span style="color: #666666; font-style: italic;"># set output record separator</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$_</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&amp;Getline2</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'WHO_FH'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$getline_ok</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff;">$n</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066;">print</span> <span style="color: #0000ff;">$n</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Getline2 <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$fh</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$getline_ok</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$_</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;</span><span style="color: #0000ff;">$fh</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">ne</span> <span style="color: #ff0000;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff;">$_</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>想学perl的同学可以折腾折腾。</p>
]]></content:encoded>
			<wfw:commentRss>http://luy.li/2010/02/12/a2p/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>exif──查看JPEG文件里的附加信息</title>
		<link>http://luy.li/2010/02/11/exif/</link>
		<comments>http://luy.li/2010/02/11/exif/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 09:08:34 +0000</pubDate>
		<dc:creator>bones7456</dc:creator>
				<category><![CDATA[CLI软件]]></category>

		<guid isPermaLink="false">http://li2z.cn/?p=1361</guid>
		<description><![CDATA[不知道什么是EXIF的可以看这里（中文）和这里（英文），简单一句话，EXIF就是存在JPG文件里的一些额外信息。 现在的数码相机拍出来的图片里，绝大多数都存有拍摄时间、快门、焦距、光圈等很多信息，稍微好点的还有GPS定位的拍摄地点呢。 在GUI下，eog等图片查看软件，都可以通过右键的“属性”菜单查看具体的EXIF信息。其实在CLI下，也是有办法提起这些信息的。这个程序的名字就叫 exif 。 安装基本靠源，就不介绍了，使用也是超简单： $ exif S7302998.JPG ‘S7302998.JPG’中的EXIF 信息标识(‘英特尔’字节顺序): --------------------+---------------------------------------------------------- 信息标识 &#124;值 --------------------+---------------------------------------------------------- Image Description &#124;&#60;Samsung D70 / D75 / S730 / S750&#62; Manufacturer &#124;Samsung Techwin Model &#124;&#60;Samsung D70 / D75 / S730 / S750&#62; Orientation &#124;左上 x-Resolution &#124;96.00 y-Resolution &#124;96.00 Resolution Unit &#124;英寸 Software &#124;708101 Date and Time &#124;2009:02:08 14:16:22 ###限于篇幅，省略点输出信息。。 对比度 [...]]]></description>
			<content:encoded><![CDATA[<p>不知道什么是EXIF的可以看<a href="http://zh.wikipedia.org/wiki/EXIF">这里</a>（中文）和<a href="http://en.wikipedia.org/wiki/EXIF">这里</a>（英文），简单一句话，EXIF就是存在JPG文件里的一些额外信息。<br />
现在的数码相机拍出来的图片里，绝大多数都存有拍摄时间、快门、焦距、光圈等很多信息，稍微好点的还有GPS定位的拍摄地点呢。<br />
在GUI下，eog等图片查看软件，都可以通过右键的“属性”菜单查看具体的EXIF信息。其实在CLI下，也是有办法提起这些信息的。这个程序的名字就叫 exif 。<br />
安装基本靠源，就不介绍了，使用也是超简单：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ exif S7302998.JPG
‘S7302998.JPG’中的EXIF 信息标识(‘英特尔’字节顺序):
--------------------+----------------------------------------------------------
信息标识                |值
--------------------+----------------------------------------------------------
Image Description   |&lt;Samsung D70 / D75 / S730 / S750&gt;
Manufacturer        |Samsung Techwin
Model               |&lt;Samsung D70 / D75 / S730 / S750&gt;
Orientation         |左上
x-Resolution        |96.00
y-Resolution        |96.00
Resolution Unit     |英寸
Software            |708101
Date and Time       |2009:02:08 14:16:22
###限于篇幅，省略点输出信息。。
对比度                 |普通
饱和度                 |普通
锐度                  |普通
Interoperability Ind|R98
Interoperability Ver|0100
--------------------+----------------------------------------------------------
EXIF 数据中含有缩略图(3915 个字节)。</pre></div></div>

<p>下一步就是找个写EXIF信息功能强一点的CLI软件，exif虽然也能写，但是好像只能逐字段挨个写，这个就不太方便了。<br />
最终我要实现的就是：<a href="http://luy.li/2009/03/30/convert_30/">压缩照片</a>，但是保留EXIF信息，哈哈。</p>
<p>========20100211 19:30:00 update========<br />
哈哈，是我把convert想得太简单了，其实convert本身就会保留EXIF的，根本无须我多操心~</p>
]]></content:encoded>
			<wfw:commentRss>http://luy.li/2010/02/11/exif/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
