<?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>林健的BLOG &#187; 命令行</title>
	<atom:link href="http://blog.linjian.org/articles/tag/%e5%91%bd%e4%bb%a4%e8%a1%8c/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.linjian.org</link>
	<description>有容乃大，无欲则刚</description>
	<lastBuildDate>Sun, 29 Aug 2010 13:56:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>试用Windows的UNIX/POSIX子系统（SUA）</title>
		<link>http://blog.linjian.org/articles/windows-posix-sua/</link>
		<comments>http://blog.linjian.org/articles/windows-posix-sua/#comments</comments>
		<pubDate>Mon, 04 May 2009 12:07:58 +0000</pubDate>
		<dc:creator>Jian Lin</dc:creator>
				<category><![CDATA[Windows应用]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[命令行]]></category>
		<category><![CDATA[实验]]></category>

		<guid isPermaLink="false">http://blog.linjian.org/?p=338</guid>
		<description><![CDATA[　　以前研究Windows的基本概念时，我就知道它有一个POSIX子系统，可以在Windows下编译运行使用了POSIX库的程序。但这一直停留在书本概念层面，直到昨天看到Jeep同学的Windows系统上安装了一个Subsystem for UNIX-based Applications时，我便决定也安装试用一下。 　　有关Windows的POSIX子系统是什么、怎么用的问题，可以参考Wikipedia或Microsoft TechNet [英文][中文]上的介绍。它历经了NT时代的Microsoft POSIX subsystem、XP/2000时代的Microsoft Windows Services for UNIX (SFU)以及2003 R2/Vista/2008时代的Subsystem for UNIX-based Applications (SUA)等版本，对POSIX标准的支持日臻完善。我的系统是来自MSDNAA/IEEE的Windows Server 2008，自然要使用最新版的SUA。至于SUA和cygwin在实现机理和功能性能上有什么区别，我还没有仔细研究。但从直观感觉上，Windows原生支持的SUA是比cygwin快一点儿；按照Wikipedia上的这个说法，cygwin是对POSIX是“partial”兼容，而SFU/SUA则是“full”兼容。 　　很多人安装SUA的目的并不是要向Windows移植什么重要的UNIX/Linux应用，有时候我们仅仅是为了在Windows中使用一个类UNIX的Shell以及丰富的GNU utilities，毕竟这类久经考验的命令行工具比Windows Command Prompt的那些命令好使很多。对于工作环境要求在Windows和Linux间来来回回切换的人们，也省得敲错命令。安装SUA之后，预装的Shell是C Shell和Korn Shell，还安装了包括vi、gcc在内的300多个命令行工具。同时，Windows的Path环境变量中自动添加了SUA相关目录，这样在Windows Command Prompt和Power Shell中也可以使用很多GNU utilities了。当然，UNIX Shell的内部命令是不可以在这里使用的。此外，在Power Shell中，Power Shell命令别名（如ls、cp）会优先于同名的GNU utilities调用。总之，使用SUA或cygwin这类UNIX Shell+GNU utilities的模拟环境，相比手工添加的“容错”命令或者GnuWin32这类独立命令级的移植要“真实”和顺手得多，但缺点就是体积庞大。 　　为了检验SUA的能力，我拿我相对熟悉的GNU bash做了实验。从官方下载bash-4.0版源代码，在SUA的C Shell环境中解压，运行./configure通过。但在make时报错： execute_cmd.c: In function `time_command': execute_cmd.c:1145: error: storage size of `dtz' isn't known 　　查看execute_cmd.c源代码，发现这句代码有注释： struct timezone [...]]]></description>
			<content:encoded><![CDATA[<p>　　以前研究Windows的基本概念时，我就知道它有一个POSIX子系统，可以在Windows下编译运行使用了POSIX库的程序。但这一直停留在书本概念层面，直到昨天看到Jeep同学的Windows系统上安装了一个Subsystem for UNIX-based Applications时，我便决定也安装试用一下。<br />
　　有关Windows的POSIX子系统是什么、怎么用的问题，可以参考<a href="http://en.wikipedia.org/wiki/Interix">Wikipedia</a>或Microsoft TechNet [<a href="http://technet.microsoft.com/en-us/library/cc772343.aspx">英文</a>][<a href="http://technet.microsoft.com/zh-cn/library/cc772343.aspx">中文</a>]上的介绍。它历经了NT时代的<a href="http://en.wikipedia.org/wiki/Microsoft_POSIX_subsystem">Microsoft POSIX subsystem</a>、XP/2000时代的<a href="http://en.wikipedia.org/wiki/Microsoft_Windows_Services_for_UNIX">Microsoft Windows Services for UNIX (SFU)</a>以及2003 R2/Vista/2008时代的<a href="http://en.wikipedia.org/wiki/Subsystem_for_UNIX-based_Applications">Subsystem for UNIX-based Applications (SUA)</a>等版本，对POSIX标准的支持日臻完善。我的系统是来自<a href="http://www.ieee.org/web/membership/students/branchresources/microsoftofferstudents.html">MSDNAA/IEEE</a>的Windows Server 2008，自然要使用最新版的SUA。至于SUA和<a href="http://www.cygwin.com/">cygwin</a>在实现机理和功能性能上有什么区别，我还没有仔细研究。但从直观感觉上，Windows原生支持的SUA是比cygwin快一点儿；按照<a href="http://en.wikipedia.org/wiki/POSIX">Wikipedia上的这个说法</a>，cygwin是对POSIX是“partial”兼容，而SFU/SUA则是“full”兼容。<br />
　　很多人安装SUA的目的并不是要向Windows移植什么重要的UNIX/Linux应用，有时候我们仅仅是为了在Windows中使用一个类UNIX的Shell以及丰富的GNU utilities，毕竟这类久经考验的命令行工具比Windows Command Prompt的那些命令好使很多。对于工作环境要求在Windows和Linux间来来回回切换的人们，也省得敲错命令。安装SUA之后，预装的Shell是C Shell和Korn Shell，还安装了包括vi、gcc在内的300多个命令行工具。同时，Windows的Path环境变量中自动添加了SUA相关目录，这样在Windows Command Prompt和Power Shell中也可以使用很多GNU utilities了。当然，UNIX Shell的内部命令是不可以在这里使用的。此外，在Power Shell中，Power Shell命令别名（如ls、cp）会优先于同名的GNU utilities调用。总之，使用SUA或cygwin这类UNIX Shell+GNU utilities的模拟环境，相比手工添加的<a href="http://blog.linjian.org/articles/use-vista-as-linux/">“容错”命令</a>或者<a href="http://gnuwin32.sourceforge.net/">GnuWin32</a>这类独立命令级的移植要“真实”和顺手得多，但缺点就是体积庞大。<br />
　　为了检验SUA的能力，我拿<a href="http://blog.linjian.org/articles/gnu-bash-analysis/">我相对熟悉的GNU bash</a>做了实验。从官方下载bash-4.0版源代码，在SUA的C Shell环境中解压，运行./configure通过。但在make时报错：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">execute_cmd.c: In function `time_command':</li>
<li>execute_cmd.c:1145: error: storage size of `dtz' isn't known</li></ol></div>
<p>　　查看execute_cmd.c源代码，发现这句代码有注释：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">struct timezone dtz; /* posix doesn't define this */</li></ol></div>
<p>　　看来这个struct timezone不是POSIX标准的东西。通过上下文，我发现这里是处理time（计时）关键字的函数。于是查看configure的帮助，得知只要加一个“--disable-command-timing”参数即可禁用time关键字（这时输入time将改用/bin/time程序做计时）。再次make，execute_cmd.c通过，但又出现以下错误：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">getcwd.c: In function `_path_checkino':</li>
<li>getcwd.c:80: error: `MP_RMDOT' undeclared (first use in this function)</li>
<li>getcwd.c:80: error: (Each undeclared identifier is reported only once</li>
<li>getcwd.c:80: error: for each function it appears in.)</li></ol></div>
<p>　　查看./lib/sh/getcwd.c的源代码，果然没有找到MP_RMDOT宏的定义。在全部源代码中搜索，发现这一定义在externs.h中，在./lib/sh/makepath.c中也有使用，唯独在./lib/sh/getcwd.c中使用了却没有引用其定义。也许这是bash-4.0的一个bug？使用Linux下的gcc编译连接是通过的，但SUA下的gcc版本也许有更严格的名字连接策略，导致无法编译通过。于是我将“#define MP_RMDOT 0x04”的定义手工加入./lib/sh/getcwd.c，再次make，全部通过。实验运行无误！<br />
　　需要注意的是，SUA提供的是编译和运行使用了POSIX库的程序的环境，并不提供UNIX二进制文件的运行支持。它编译生成和支持运行的可执行文件仍然是Windows的PE格式，而不是ELF之类。SUA支持的只是仅使用了标准库和POSIX库的程序的源代码级移植，对于使用了Linux等环境特有的系统调用的程序，也不可能不加修改地编译运行。<br />
　　有空再研究一下SUA在我们的工程中能有什么实际点的应用。</p>
<hr />原文链接：<a href="http://blog.linjian.org/articles/windows-posix-sua/">http://blog.linjian.org/articles/windows-posix-sua/</a>，作者：<a href="http://blog.linjian.org/">林健</a>。
<br />本作品采用<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/">知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议</a>进行许可。
<br />(Digital fingerprint: 
 993d4981d6d552510db9a08493b2dbec)<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li><a href="http://blog.linjian.org/articles/windows-network-commands/" title="Windows网络环境切换常用命令">Windows网络环境切换常用命令</a></li><li><a href="http://blog.linjian.org/articles/pgina-authentication/" title="GINA 与 pGINA——实现自定义的 Windows 用户身份认证">GINA 与 pGINA——实现自定义的 Windows 用户身份认证</a></li><li><a href="http://blog.linjian.org/articles/smartq-v5-experience/" title="智器（SmartQ）V5 使用半月杂记">智器（SmartQ）V5 使用半月杂记</a></li><li><a href="http://blog.linjian.org/articles/ipv6-icmpv6-error/" title="解决 IPv6 路由发现协议得到错误地址的问题">解决 IPv6 路由发现协议得到错误地址的问题</a></li><li><a href="http://blog.linjian.org/articles/c-pointer-alignment-access/" title="一道 C 语言指针访存题目的引申">一道 C 语言指针访存题目的引申</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.linjian.org/articles/windows-posix-sua/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Windows网络环境切换常用命令</title>
		<link>http://blog.linjian.org/articles/windows-network-commands/</link>
		<comments>http://blog.linjian.org/articles/windows-network-commands/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 09:46:15 +0000</pubDate>
		<dc:creator>Jian Lin</dc:creator>
				<category><![CDATA[Windows应用]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[命令行]]></category>
		<category><![CDATA[网络]]></category>

		<guid isPermaLink="false">http://blog.linjian.org/?p=177</guid>
		<description><![CDATA[　　简单总结一下用Windows命令行设置常用网络配置的命令。将它们保存为批处理文件（.bat），方便笔记本电脑用户在不同网络环境下快速切换配置。 一、设置IP与DNS 1、设置为DHCP： a) 对于Windows XP cmd /c netsh interface ip set address name="Local Area Connection" source=dhcp cmd /c netsh interface ip set dns name="Local Area Connection" source=dhcp b) 对于Windows Vista、Windows 7 cmd /c netsh interface ip set address name="Local Area Connection" source=dhcp cmd /c netsh interface ip set dnsserver name="Local Area Connection" source=dhcp （中文系统下“Local [...]]]></description>
			<content:encoded><![CDATA[<p>　　简单总结一下用Windows命令行设置常用网络配置的命令。将它们保存为批处理文件（.bat），方便笔记本电脑用户在不同网络环境下快速切换配置。</p>
<p>一、设置IP与DNS</p>
<p>1、设置为DHCP：<br />
a) 对于Windows XP<br />
cmd /c netsh interface ip set address name="Local Area Connection" source=dhcp<br />
cmd /c netsh interface ip set dns name="Local Area Connection" source=dhcp<br />
b) 对于Windows Vista、Windows 7<br />
cmd /c netsh interface ip set address name="Local Area Connection" source=dhcp<br />
cmd /c netsh interface ip set dnsserver name="Local Area Connection" source=dhcp<br />
（中文系统下“Local Area Connection”应替换为“本地连接”一类的名称，下同）</p>
<p>2、设置为固定IP：<br />
cmd /c netsh interface ip set address name="Local Area Connection" source=static addr=10.2.54.123 mask=255.255.255.0 gateway=10.2.54.1 gwmetric=1</p>
<p>3、设置多个DNS服务器：<br />
a) 对于Windows XP<br />
cmd /c netsh interface ip set dns name="Local Area Connection" source=static addr=10.87.130.1<br />
cmd /c netsh interface ip add dns name="Local Area Connection" 10.87.130.2<br />
b) 对于Windows Vista、Windows 7<br />
cmd /c netsh interface ip set dnsserver name="Local Area Connection" source=static addr=10.87.130.1<br />
cmd /c netsh interface ip add dnsserver name="Local Area Connection" 10.87.130.2</p>
<p>二、设置主机名解析文件</p>
<p>有时候可能需要针对不同的环境使用不同的主机名解析文件，以便在不修改其它软件配置的情况下使用统一的域名访问不同的服务。<br />
copy E:\Program\Batches\netenv\hosts.1 C:\Windows\System32\drivers\etc\hosts 或<br />
copy E:\Program\Batches\netenv\hosts.2 C:\Windows\System32\drivers\etc\hosts</p>
<p>“hosts.1”文件内容：<br />
127.0.0.1       localhost<br />
10.87.1.1       mail_host.linjian.org</p>
<p>“hosts.2”文件内容：<br />
127.0.0.1       localhost<br />
202.204.80.1    mail_host.linjian.org</p>
<p>三、设置路由表</p>
<p>在局域网内同时使用两种外网登录工具（如“亿邮”+“教育网直通车”）时可能有用。<br />
添加：<br />
route -p add 10.0.0.0 mask 255.0.0.0 10.2.54.1<br />
删除：<br />
route delete 10.0.0.0</p>
<p>四、设置代理服务器</p>
<p>可以将不同网络环境下的代理服务器配置存储在不同的注册表文件中，需要改变的时候导入注册表。<br />
reg import E:\Program\Batches\netenv\proxy.reg 或<br />
reg import E:\Program\Batches\netenv\noproxy.reg</p>
<p>“proxy.reg”文件内容：<br />
Windows Registry Editor Version 5.00<br />
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]<br />
"ProxyEnable"=dword:00000001<br />
"ProxyHttp1.1"=dword:00000001<br />
"ProxyOverride"="<local>"<br />
"ProxyServer"="60.28.31.194:80"</p>
<p>“noproxy.reg”文件内容：<br />
Windows Registry Editor Version 5.00<br />
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]<br />
"ProxyEnable"=dword:00000000</p>
<p>五、ADSL或VPN接入</p>
<p>连接：<br />
rasdial Entryname Username Password<br />
断开：<br />
rasdial Entryname /DISCONNECT</p>
<p>　　组合调用上述命令，建立适用于不同环境下的网络配置批处理文件。最后，别忘了修改批处理文件（或其快捷方式）的属性，让它默认以Administrator身份运行，这样才能保证上述设置有权限执行。</p>
<hr />原文链接：<a href="http://blog.linjian.org/articles/windows-network-commands/">http://blog.linjian.org/articles/windows-network-commands/</a>，作者：<a href="http://blog.linjian.org/">林健</a>。
<br />本作品采用<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/">知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议</a>进行许可。
<br />(Digital fingerprint: 
 993d4981d6d552510db9a08493b2dbec)<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li><a href="http://blog.linjian.org/articles/ipv6-icmpv6-error/" title="解决 IPv6 路由发现协议得到错误地址的问题">解决 IPv6 路由发现协议得到错误地址的问题</a></li><li><a href="http://blog.linjian.org/articles/windows-posix-sua/" title="试用Windows的UNIX/POSIX子系统（SUA）">试用Windows的UNIX/POSIX子系统（SUA）</a></li><li><a href="http://blog.linjian.org/articles/smartq-v5-mifi/" title="使用智器 V5 实现山寨 MiFi">使用智器 V5 实现山寨 MiFi</a></li><li><a href="http://blog.linjian.org/articles/pgina-authentication/" title="GINA 与 pGINA——实现自定义的 Windows 用户身份认证">GINA 与 pGINA——实现自定义的 Windows 用户身份认证</a></li><li><a href="http://blog.linjian.org/articles/s3-sync-tools/" title="三款面向 Amazon S3 的开源文件同步工具之对比">三款面向 Amazon S3 的开源文件同步工具之对比</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.linjian.org/articles/windows-network-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
