Cygwin FAQ

3.1. Q Howto get version info?

        bash$ cygcheck -c cygwin

3.2. Q 安装注意事项

  • gzip

gzip 版本 1.3.3-4 可用。高版本如: 1.3.5-1 使 tar -z 命令运行不正常。

3.3. Q Howto setup default text format, CRLF(dos) or LF(unix)?

  • 修改注册表项:HKEY_LOCAL_MACHINESOFTWARECygnus SolutionsCygwinmounts v2...cygdrive flags。 cygdrive flags是一个DWORD值,&0x2 == 0x2 为 Unix Style,否则为 Dos like style。

  • 设置环境变量 CYGWIN, 使得在 pipe 等模式下的处理方式:export CYGWIN=nobinmode

3.4. Q 为什么在 Cygwin 下创建的文件,其他管理员不可写?

这是所谓的 ntsec 在起作用。通过 NTFS 的权限设置,模拟 UNIX 的权限。可以通过 CYGWIN 环境变量修改。如:
        bash$ export CYGWIN="nontsec nosmbntsec"

3.5. Q 如何让 ls 能够显示中文文件名?

因为 ls 不使用 readline 来显示, 因而不能用 .inputrc 控制。即 less 和 ls 需要特别设置。在 .bashrc 中加入如下 alias:
	alias less='/bin/less -r'
	alias ls='/bin/ls -F --color=tty --show-control-chars'

3.6. Q 如何在按 TAB 键进行文件名扩展时忽略大小写,这样在 Windows 下才方便噢?

参见:  [Cygwin User's Guide]

Customizing bash

Three initialization files that control the behavior of bash: .profile, .bashrc and .inputrc.

.profile

It is executed when bash is started as login shell, e.g. from the command bash --login.

建议

  • 在 PATH 后加上 ":.",这样可以象在 DOS 下,执行本目录下程序;

.bashrc

.bashrc is similar to .profile but is executed each time an interactive bash shell is launched.

.inputrc

.inputrc controls how programs using the readline library (including bash) behave.


# Ignore case while completing
set completion-ignore-case on
# Make Bash 8bit clean
set meta-flag on
set output-meta on # to show 8-bit characters
set convert-meta off # to show it as character, not the octal representation

但是并不能保证 ls 显示中文。因为这些工具不使用 readline 来显示。象 less 和 ls 需要特别设置。在 .bashrc 中加入如下 alias:

	alias less='/bin/less -r'
	alias ls='/bin/ls -F --color=tty --show-control-chars'

3.7. Q 如何在 Cygwin 中运行 crontab?

如下:
  • 在Windows上安装系统服务 cron,开机即运行。

        bash$ cygrunsrv -I cron -p /usr/sbin/cron -a -D
  • 启动服务

        bash$ cygrunsrv -S cron

3.8. Q 配置 SSH client?

  • 为了能够通过公钥验证进行SSH登陆其他服务器,先要在本地建立 SSH 公钥私钥对:

        bash$ ssh-keygen -t rsa1
        bash$ ssh-keygen -t rsa
        bash$ ssh-keygen -t dsa
  • 建立无口令登录

需要将本机的 *.pub 拷贝(cat>>)到服务器中 $HOME/.ssh/ 下的 authorized_keys (ssh1) 和 authorized_keys2 (ssh2) 文件中去。

3.9. Q 如何在 cygwin 中运行 sshd (SSH Server)?

如下:
  • 设置 Windows 环境变量,添加“CYGWIN = ntsec tty”

  • Config SSHD, running:

        bash$ ssh-host-config -y

根据提示,输入 CYGWIN=ntsec tty

  • Change permissions and ownership on some files:

        bash$ cd /; chmod -R og-w . 
        bash$ chmod og+w /tmp 
        bash$ touch /var/log/sshd.log 
        bash$ chown system:system /var/log/sshd.log /var/empty /etc/ssh_h* 
        bash$ chmod 755 /var/empty 

  • start the service:

        bash$ cygrunsrv -S sshd

3.10. Q 如何在 cygwin 中配置 Email?

As follows:
  • ssmtp & mutt
    • ssmtp

            bash$ /usr/bin/ssmtp-config
    

    When using mutt as the mail client, add the following line to your $HOME/.muttrc file:

            set sendmail="/usr/sbin/ssmtp"
    

  • mutt
    • Make sure you have the Cygwin ssmtp package installed

    check file /etc/ssmtp/ssmtp.conf
    • vi .bashrc and/or .bash_profile

            export MAIL=~/Mail/inbox
            export EDITOR=nano
    

    If you have nano installed (and I stongly recommend that you do)
    • Createthe following directory structure in your HOME directory:

            ~/Mail
               |
               -- inbox (EMPTY FILE, NOT DIRECTORY)
               |
               -- sent (EMPTY FILE, NOT DIRECTORY)
               |
               -- received (EMPTY FILE, NOT DIRECTORY)
               |
               -- postponed (EMPTY FILE, NOT DIRECTORY)
    
    • Create a ~/.muttrc file that looks like this:

            # The file/directory where your incoming mail will be spooled to
            # (same as 'set spoolfile' below)
            mailboxes ~/Mail/inbox
            
            # Mail account setup.  I know nothing about IMAP, so you're
            # on your own there.
            set sendmail="/usr/sbin/ssmtp"
            #set pop_host="your.pop3.mail.server.com"
            #set pop_last=yes
            #set pop_user="your_email_username"
            #set pop_pass="your_email_password"
            set from="your_complete@email_address.com"
            
            # Mail folder setup.
            set folder=~/Mail
            set mbox_type=mbox
            set spoolfile=+inbox
            set mbox=+received
            set postponed=+postponed
            set record=+sent
    

    • mutt command line

            mutt [...] address
            参数:
                -a file : attach a file to message
                -b address: BCC
                -c address: CC
                -F muttrc
                -H draft: draft contain both header and body
                -s subject: subject of the message
                -x : emulate the mailx compose mode
            
            环境变量:
                EMAIL : user's email address
                MAIL  : user's spool mailbox
            示例:
                bash$ echo "contents" | mutt -x -s "subject" mail@address
                bash$ echo  | mutt -x -s "subject" -i filename mail@address
    

  • exim & minires
    • exim

        Exim is a fully featured mail transfer agent, a drop-in replacement for sendmail.
            bash$ /usr/bin/exim-config
            bash$ view /etc/exim.conf 
            bash$ vi /etc/aliases
                      postmaster: your_login_name
            bash$ vi /etc/reslov.conf
                      nameserver 10.0.0.7
                      search your.domain
            bash$ cygrunsrv -I exim -p /usr/bin/exim -e CYGWIN=nontsec   
                      -a "-bdf -q15m" -d "Exim Mail Transfer Agent" 
                      -1 /var/log/exim/cygrunsrv_out.log -2 /var/log/exim/cygrunsrv_err.log
            bash$ cygrunsrv -S exim
    

3.11. Q 如何得到 Dos/Windows? 格式的路径名?

        bash$ cygpath -d -m "`pwd`"

3.12. Q Setup Xinetd

  • start init service

        bash$ /usr/bin/init-config

  • chkconfig 工具用来维护 /etc/rc.d 下的脚本
    • 若要启动 sshd 执行 "/sbin/chkconfig --add sshd"

  • xinetd config

        bash$ /usr/bin/xinetd-config

3.13. Q other command?


ttcp, netsnoop

3.14. Q XFree86 under Cygwin?

  • add /usr/X11R6/bin to PATH;
  • start Xwindow using startxwin.bat(dos/windows), or startxwin.sh(cygwin);
  • if has a firewall installed, open port "6000" of local server;
  • run xclient in local machine, just set environment: export DISPLAY=127.0.0.1:0.0
  • if run xclient in remote machine, give authorize to remote host:

bash$ /usr/X11R6/bin/xhost remote_hostname_or_ip_address
  • telnet/ssh to remote host;
  • set environment DISPLAY, like: export DISPLAY=<IP_of_Cygwin_XFree86>:0.0
  • xterm

3.15. Q 安装后的设置综述?

  • binmode or textmode?
执行  mount 命令,如果不是 textmode,修改注册表 HKEY_LOCAL_MACHINESOFTWARECygnus SolutionsCygwinmounts v2...cygdrive flags。 cygdrive flags是一个DWORD值,&0x2 == 0x2 为 Unix Style,否则为 Dos like style。

  • 修改 ~/.inputrc 文件,加入如下内容

# Ignore case while completing
set completion-ignore-case on
# Make Bash 8bit clean
set meta-flag on
set output-meta on # to show 8-bit characters
set convert-meta off # to show it as character, not the octal representation

  • 修改 /etc/profile, 加入如下内容:

set -o vi

alias less='/bin/less -r'
alias ls='/bin/ls -F --color=tty --show-control-chars'

# glob filenames in a case-insensitive manner
shopt -s nocaseglob

export SGML_CATALOG_FILES=/share/catalog.sgml
export XML_CATALOG_FILES=/share/catalog.xml
export CYGWIN="nobinmode nontsec nosmbntsec"
export PATH=$PATH:.

  • 修改登录用户的主要组:

        bash$ vi /etc/passwd

默认属于 513 组(对于域控制器是Domain Users,非域控制器为 NONE),个人偏好设置为 544(Administrator)

  • 建立 symbol link:
    • 因为一些脚本默认的 md5 摘要程序是 md5, 而非 md5sum;

            bash$ ln -s /usr/bin/md5sum /usr/bin/md5
    
    • 设置 DOCBOOK DTD/DSSSL 路径

            bash$ ln -sf /cygdrive/e/HOME/WORK/johnson_homepage/worldhello/share /share
    

    • 设置 usemodwiki 路径映射

    mkdir /repos
    cd /repos/
    ln -s /cygdrive/d /d
    ln -s /d/HOME/WORK/johnson_homepage/worldhello/usemod JohnsonUseModWiki
    ln -s /d/HOME/WORK/johnson_homepage/worldhello/wiki .
    

    • 设置建立工作路径

            bash$ ln -sf /cygdrive/e/HOME/WORK/ ~/work
wall john's 新屋: cygwin 汉化即其他新特性
homewj.spaces.live.com/Blog/cns!1pav0HyE-t7RIT4zpR...
cygwin 汉化即其他新特性
使用cygwin的原因
最近在研究java的源码,源码官方的编译文档里提到一个unix环境到windows移植的
工具包MKS,在网上百觅不得,于是想起了久违的cygwin,使用之后居然能启动java
那庞大makefile系统,于是觉得有必要写点东西向大家推介推介。
安装
http://www.cygwin.com/下载网络安装setup.exe,该安装程序会一步步提示,只
是选取安装包的那一节自己注意点,针对自己的需要看看有什么要额外装的。比如
编译java源码时就要多选取几个:perl、gawk、make、binutils(好像就这几个,
反正编译时会有提示找不到那个执行程序,届时用setup.exe到网上再下就可以了。
),另外vim这个包是linux下编辑文本必备的,在windows下的cygwin中也是如此。
cygwin环境汉化
修改三个文件:
1、~/.bashrc BASH的配置文件
# base-files version 3.4-2
# WARNING #
# IF THIS .bashrc IS MODIFIED IT WILL NOT BE UPDATED BY THE CYGWIN
# SETUP PROGRAM.  IT BECOMES YOUR RESPONSIBILITY.
#
# The latest version as installed by the Cygwin Setup program can
# always be found at /etc/defaults/etc/skel/.bashrc
# User dependent .bashrc file
# See man bash for more options...
# Don't wait for job termination notification
# set -o notify
# Don't use ^D to exit
# set -o ignoreeof

# Don't put duplicate lines in the history.
# export HISTCONTROL=ignoredups
# Ignore some controlling instructions
# export HISTIGNORE="[   ]*:&:bg:fg"

# Some example alias instructions
# If these are enabled they will be used instead of any instructions
# they may mask.  For example, alias rm='rm -i' will mask the rm
# application.  To override the alias instruction use a \ before, ie
# \rm will call the real rm not the alias.
# Interactive operation...
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
# Default to human readable figures
# alias df='df -h'
# alias du='du -h'
# Misc :)
# alias less='less -r'                          # raw control characters
# alias whence='type -a'                        # where, of a sort
# alias grep='grep --color'                     # show differences in colour
# Some shortcuts for different directory listings
# alias ls='ls -hF --color=tty'                 # classify files in colour
# alias dir='ls --color=auto --format=vertical'
# alias vdir='ls --color=auto --format=long'
# alias ll='ls -l'                              # long list
# alias la='ls -A'                              # all but . and ..
# alias l='ls -CF'                              #

# Some example functions
# function settitle() { echo -n "^[]2;$@^G^[]1;$@^G"; }
###################### 以下为添加部分 ################################
# cygwin中取\usr\share\locale\zh_CN\LC_MESSAGES中*.mo文件,如果提示信息中
# 的字符集为utf8则会显示有误(不知何解?,magiclinux无类似情况),为gb2312
# 则正常,大概与gettext这个模块有关,这个模块的作用是使linux程序提示信息
# 区域话,即不同地区用不同语言,即常说的i18n;像我们设置的zh_CN.GBK,“.”
# 之前部分“zh_CN”表示地区即“中国大陆”,后面部分“GBK”表示字符集编码,
# 像我们下面的设置,当程序调用时会到\usr\share\locale\目录中查找,发现地
# 区为“zh_CN”则到该目录中查找程序对应的*.mo文件,*.mo文件的名称是在调用
# 的程序中设置了的。然后取该语种的对应提示,然后按编码(在mo文件中指明了)
# 处理该文字。
# 当然这些不是自动处理的,要在程序中调用像setlocale、textdomian、gettext
# 这样的函数处理。
# 在cygwin中有些程序,做了下面的设置,因为对应的mo文件中编码为utf8而无法
# 显示,我是直接将它删除,之后程序会因为找不到mo文件而用默认的英文来显示
# 的。(下面的编码设置并没有错,应该是cygwin程序中的BUG,只是设置了LC_ALL
# 就没必要设LANG了,有的文档上面这样写的:))
export set LC_ALL=zh_CN.GBK
export set LANG=zh_CN.GBK
#export set LC_CTYPE=zh_CN.UTF-8
#export set CHARSET=UTF-8
# 解决ls中文显示问题
alias ls='ls --show-control-chars'
alias dir='ls --show-control-chars'
alias less='less --raw-control-chars'
# 添加清屏处理
alias clear='clearn'
alias clr='clearn'
# 添加whereis的别名
alias whereis='which'
2、~/.inputrc BASH中命令行输入出控制的配置文件
# base-files version 3.4-2
# WARNING
#
# IF THIS .inputrc IS MODIFIED IT WILL NOT BE UPDATED BY THE CYGWIN
# SETUP PROGRAM.  IT BECOMES YOUR RESPONSIBILITY.
#
# The latest version as installed by the Cygwin Setup program can
# always be found at /etc/defaults/etc/skel/.inputrc
# don't beep at me
# set bell-style visible
# the following line is actually
# equivalent to "\C-?": delete-char
"\e[3~": delete-char
# VT
"\e[1~": beginning-of-line
"\e[4~": end-of-line
# kvt
"\e[H":beginning-of-line
"\e[F":end-of-line
# rxvt and konsole (i.e. the KDE-app...)
"\e[7~":beginning-of-line
"\e[8~":end-of-line
###################### 以下为添加部分 ################################
# 关闭bash命令行8字节字符转义符的转换
set convert-meta off
# 使bash命令行支持8字节字符输入
set input-meta on
# 使bash命令行支持8字节字符输出
set output-meta on
# 让bash的命令行已vi模式执行,屏蔽掉下面一行,BASH的命令行操作
# 就像vi中编辑文本一样,默认为INSERT模式,可以在BASH启动后直接
# 输入:set -o vi,来启动该开关,set +o vi关闭该模式,但在cygwin
# 中调用set +o vi关闭时会出现一些乱码,估计也是一个BUG
#set editing-mode vi
3、~/.vimrc vim的资源控制文件
" 显示语法高亮度
:syntax on
" 设置字符编码,可使显示中文光标移动和字符删除操作变为双字节
:set encoding=cp936
" 设置vim中TAB缩进为4个空格
:set ts=4

cygwin的新特性
windows驱动器的管理
cygwin启动后,windows中驱动器自动挂接到cygdrive目录。
比如:
wj@wj-server1 ~
$ ls /cygdrive
c  d  e
cygdrive是一个虚拟目录,它在注册表中设置。
看看这个:
wj@wj-server1 ~
$ regtool get '\HKLM\software\Cygnus Solutions\Cygwin\mounts v2\cygdrive prefix'
/cygdrive
regtool是cygwin中注册表的操作工具,get选项会把上面注册表项的值显示出来。
我们把/cygdrive该成/media试试。
wj@wj-server1 ~
$ regtool set '\HKLM\software\Cygnus Solutions\Cygwin\mounts v2\cygdrive prefix' '/media'
重启cygwin
wj@wj-server1 ~
$ ls /media
c  d  e
在cygwin中也可以这样操作驱动器,比如我们要进入到E盘
wj@wj-server1 ~
$ cd e:
wj@wj-server1 /media/e
$
wj@wj-server1 /media/e
$ ls
DZSW20050606.rar   EDUMS20050606.rar  cvs     ftp.txt  music    temp
Downloads          Recycled           ebook  job      oracle   work
EDUMS20050529.rar  ctais              film   linux    rav.rar  全国DNS地址.txt
直接输盘符cd就可以了。等同于下面的操作。
wj@wj-server1 ~
$ cd /media/e
wj@wj-server1 /media/e
$
另外, '\HKLM\software\Cygnus Solutions\Cygwin\mounts v2\'下面的项可以制
定目录的连接关系,比如该项下面有一个项叫‘/’该项中有个值‘native’为字
符串‘C:\cygwin’,cygwin启动的时候就会将根目录‘/’指向‘C:\cygwin’本地
目录。所以你无论从那个目录启动bash.exe程序,根目录是不会变的,以前的好像
不是,默认的关联还有‘/usr/bin’指向‘C:\cygwin/bin’所以cygwin中/usr/bin
和/bin其实是同一个目录,因为根目录/为‘C:\cygwin’,‘/usr/lib’指向
‘C:\cygwin/lib’,同理/usr/lib与/lib为同一个目录。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值