通過終端安裝apt-cyg之前選要安裝以下軟件包
wget
tar
gawk
bzip2
Cygwin終端安裝
wget http://apt-cyg.googlecode.com/svn/trunk/apt-cyg -P /bin
chmod.exe +x /bin/apt-cyg
去googlecode手工下載安裝
svn --force export http://apt-cyg.googlecode.com/svn/trunk/ /bin/
chmod +x /bin/apt-cyg
去github手工下載安裝
https://codeload.github.com/transcode-open/apt-cyg/zip/master
解壓到用戶目錄
mv apt-cyg /bin/
chmod +x /bin/apt-cyg
apt-cyg使用
apt-cyg install : to install packages
apt-cyg remove : to remove packages
apt-cyg update: to update setup.ini
apt-cyg show: to show installed packages
apt-cyg packageof : to locate parent packages
apt-cyg find : to find packages matching patterns
*apt-cyg describe : to describe packages matching patterns</PATTERN(S)></PATTERN(S)>
apt-cyg配置
*配置安裝源
apt-cyg -m http://mirrors.163.com/cygwin/
export LANG="zh_CN.GBK" alias ls="ls --color=auto" alias dir="ls --color=auto" export PS1="\[\e]0;\w\a\]\[\e[32m\]\u@\h:\[\e[33m\]\w\[\e[0m\]\$ " alias ..="cd .." alias ...="cd ..." $ apt-cyg install wget You must install wget, tar, gawk, xz and bzip2 to use apt-cyg.
目錄
Cygwin使用
(轉自)http://w.gdu.me/wiki/cygwin/index.html
Update: 2013-01-04
常用軟件安裝
- 安裝Cygwin時,應安裝上:wget, tar, gawk, bzip2, nc, xz, openssh
安裝apt-cyg
- 修改x86/x86_64源、xz壓縮包支持的apt-cyg:apt-cyg
123456789101112
wget http://w.gdu.me/wiki/files/shell/apt-cygchmod+x apt-cygmvapt-cyg/usr/local/bin/apt-cyg --helpcygcheck --help# 修改軟件源apt-cyg --mirror http://mirrors.163.com/cygwin - 201308后Cygwin版本變更,需修改apt-cyg(使用上面已修改過的版本即可)
- 軟件源路徑變更
- 2013-08-08后Cygwin分為x86、x86_64兩個安裝包,源路徑也改不同路徑(x86、x86_64),因此apt-cyg下載setup.bz2和setup.ini時發生404錯誤。
12345678910
vim/usr/loccal/bin/apt-cyg# 將:wget -N $mirror/setup.bz2wget -N $mirror/setup.ini# 改為:wget -N $mirror/x86/setup.bz2wget -N $mirror/x86/setup.ini# 或:wget -N $mirror/x86_64/setup.bz2wget -N $mirror/x86_64/setup.ini
- 2013-08-08后Cygwin分為x86、x86_64兩個安裝包,源路徑也改不同路徑(x86、x86_64),因此apt-cyg下載setup.bz2和setup.ini時發生404錯誤。
- 添加xz壓縮包支持
12345678910
diffapt-cyg apt-cyg.bak353,358c353<echo$file|grep".xz$">/dev/null2>&1<if["$?"="0"];then<cat$file| xz -d |tar>"/etc/setup/$pkg.lst"xvf - -C /<else<cat$file| bunzip2 |tar>"/etc/setup/$pkg.lst"xvf - -C /<fi--->cat$file| bunzip2 |tar>"/etc/setup/$pkg.lst"xvf - -C /
- 軟件源路徑變更
安裝常用工具
|
1
2
3
|
# apt-cyg install man cygwin-doc
apt-cyg
install
vim
screen
wget subversion openssh pwgen
gzip
bzip2
curl
rsync
bash
-completion \
lftp nc tree p7zip connect-proxy util-linux bind-utils inetutils
|
安裝python環境
|
1
|
apt-cyg
install
python python-crypto
|
- 安裝easy_install
- 參考:http://atbrox.com/2009/09/21/how-to-get-pipvirtualenvfabric-working-on-cygwin/
1234567
#sh setuptools-0.6c11-py2.6.eggapt-cyginstallpython-setuptoolseasy_install pippipinstallmoin
- 參考:http://atbrox.com/2009/09/21/how-to-get-pipvirtualenvfabric-working-on-cygwin/
常用工具設置
Cygwin終端
- ~/.minttyrc
1234567
BoldAsFont=noFont=YaHei Consolas hybridFontHeight=12#BackgroundColour=0,43,53BackgroundColour=11,22,33ForegroundColour=191,191,191FontSmoothing=full - 顏色、字體選擇參數
背景顏色:(RGB)0,40,51;或11,22,33(就是這個Wiki頁面的背景色) 字體顏色:(RGB)31,148,150(較暗);或191,191,191 目錄顏色:(RGB)255,128,128 壓縮文件顏色:(RGB)128,128,0 字體:Consolas,Courier New,Fixedsys,YaHei Consolas hybrid
- YaHei Consolas hybrid.1.12字體下載:
bashrc
- ~/.bashrc
12345678
aliasgrep='grep --color'# show differences in colouraliasegrep='egrep --color=auto'# show differences in colouraliasfgrep='fgrep --color=auto'# show differences in colouraliasls='ls -hF --color=tty'# classify files in colouraliasll='ls -la'# long listaliasla='ls -A'# all but . and ..aliasl='ls -CF'#aliasssh="ssh -S none"
- ~/.bash_profile
123
PS1="[\w]$"#彩色的PS1會造成命令編輯時光標定位錯誤#PS1="\e[0;32m[\u@\h \W]\$ \e[m"
screen設置
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#
# ~/.screenrc
#
# 啟動時不顯示歡迎屏幕
startup_message off
# 定義screen的功能鍵為Ctrl-A。向終端輸入Ctrl-A時應按 Ctrl-A a。
#escape ^Aa
# 屏幕緩沖區 1024 行。
defscrollback 1024
# 顯示窗口列表
caption always
"%-w%{= BW}%50>%n %t%{-}%+w%<"
# 按 Ctrl-A w 或 Ctrl-A Ctrl-W 顯示窗口列表
bind w windowlist -b
#bind ^w windowlist -b
#在使用screen過程中,經常會遇到“閃屏”的問題,這是可以關掉的。
#快速關掉:也就是先輸入CTRL + a,再輸入CTRL + g。
#永久關閉:修改/etc/screenrc 加入
vbell off
|
~/.vimrc
- vim沒有語法高亮,需加載基本設置
1
cd/usr/share/vim&&cpvim74/vimrc_example.vim vimrc
- .vimrc設置
詳見:vimrc
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
" ~/.vimrc
set
mouse=c
set
nobackup
"
set
paste
set
fileformats=unix,dos,mac
set
fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set
encoding=utf-8
"
set
termencoding=cp936
let
&termencoding = &encoding
language messages en_US.UTF-8
"language messages zh_CN.UTF-8
" colo murphy
" tab
set
tabstop=4
set
cindent shiftwidth=4
set
autoindent shiftwidth=4
" TAB -> Space
set
expandtab
|
~/.ssh/config
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#ssh_config
#~/.ssh/config
IdentitiesOnly
yes
ServerAliveInterval 60
GSSAPIAuthentication no
Host m*
Port 22
User root
ControlMaster auto
ControlPath ~/.
ssh
/master-
%r@%h:%p
#ProxyCommand connect-proxy -S 127.0.0.1:2223 %h %p
Host mNagios
Hostname 172.16.16.150
|
其他設置
SSH Server
- OS修改環境變量:path增加c:/cygwin/bin
- OS增加環境變量:CYGWIN=ntsec tty
- Cygwin安裝必要的套件:OpenSSH,cygrunsrv
- Change permissions and ownership on some files:
123456
# 以下代碼沒測試過,慎用cd/;chmod-R og-w .chmodog+w/tmptouch/var/log/sshd.logchownsystem:system/var/log/sshd.log/var/empty/etc/ssh_h*chmod755/var/empty - Cygwin設定OpenSSH:
1
ssh-host-configShould privilege separation be used? (yes/no) :yes Should this script create a local user 'sshd' on this machine? (yes/no) :yes Do you want to install sshd as service? (yes/no) :yes Default is "ntsec" . CYGWIN=ntsec tty - 啟動OpenSSH:net start sshd
1
cygrunsrv -S sshd - 停止OpenSSH:net stop sshd
crontab
- 在Windows上安裝系統服務 cron,開機即運行。
1
cygrunsrv -Icron-p/usr/sbin/cron-a -D - 啟動服務
1
cygrunsrv -Scron
nontsec
這在 Cygwin 下創建的文件,其他管理員不可寫,是所謂的 ntsec 在起作用。通過 NTFS 的權限設置,模擬 UNIX 的權限。可以通過 CYGWIN 環境變量修改。如:
|
1
|
export
CYGWIN=
"nontsec nosmbntsec"
|
中文亂碼設置
**若存在中文問題才進行以下設置。**
- Rethat Cygwin安裝后目錄中文即正常,以下設置不一定需要。
- ~/.bashrc
123456789101112131415
exportSVN_EDITOR=vim# Redhat Cygwin中未做以下設置,中文正常aliasls='ls --color --show-control-chars'exportLESSCHARSET=latin1aliasless='/bin/less -r'#export LC_ALL=zh_CN.UTF-8#export LC_CTYPE=zh_CN.UTF-8#export LANG=zh_CN.UTF-8#export OUTPUT_CHARSET="GBK"#stty cs8 -istrip#stty pass8exportCYGWIN="nontsec nosmbntsec"
- ~/.inputrc
12345
# Allow 8-bit input/outputsetmeta-flag onsetconvert-meta offsetinput-meta onsetoutput-meta on
技巧收集
- Howto get version info?
1
cygcheck -c cygwin - 查看系統信息、軟件包
12345
cygcheck -h#幫助cygcheck -s#sysinfocygcheck -l#已安裝包列表cygcheck -c#列出並校驗已安裝的包cygcheck -p vim#從cygwin.com源查詢包 - 給curl安裝CA Certificates
1
curl http://curl.haxx.se/ca/cacert.pem >/usr/ssl/certs/ca-bundle.crt - 同步Windows用戶和組
1234
mkpasswd -l >/etc/passwdmkgroup -l >/etc/group# 如果有Domain的話,需要加上-d domainname - 設置Cygwin/mintty字體和大小
- 界面中設置:右鍵菜單->Options->Text,然后選擇你喜歡的字體和大小。
- 如果沒有你相要的字體,但Windows中有,可修改配置文件:
~/.minttyrc,添加以下設置:BoldAsFont=no #Font=Courier New Font=YaHei Consolas hybrid FontHeight=12
- 給Cygwin添加more/col/whereis等命令:安裝util-linux包:
apt-cyg install util-linux - 給Cygwin添加telnet/ftp工具:
apt-cyg install inetutils - 給Cygwin安裝dig命令
- 安裝
bind-utils包:apt-cyg install bind-utils - 檢查系統中已設置好DNS:
ipconfig /all
- 安裝
- 得到Windows格式的路徑名?
1
cygpath -d -m"`pwd`" - 用Explorer打開當前目錄
12345
#!/bin/sh# openexplorer.shd=$1;[ -z"$d"] && d=$(pwd)d=$(cd"$d">/dev/null2>&1;pwd)Explorer/e,"$(cygpath -d -w $d)" - Cygwin error:
-bash: fork: retry: Resource temporarily unavailable- http://stackoverflow.com/questions/9300722/cygwin-error-bash-fork-retry-resource-temporarily-unavailable
- http://cygwin.wikia.com/wiki/Rebaseall
- 錯誤現象
-bash-4.1$ wc m1.txt 3 [main] bash 2216 child_info_fork::abort: data segment start: parent(0x26D000) != child(0x38D000) -bash: fork: retry: Resource temporarily unavailable 2013930 4027950 74968256 m1.txt - 處理辦法
rkosegi's Answer seems to be working for everyone (myself included). But, just so you don't have to follow the daisy chain of links: (assuming Cygwin is installed at C:\cygwin): 1.Open Task Manager and close any processes that look to be Cygwin related. 2.Open C:\Cygwin\bin in Windows Explorer 3.Verify that dash.exe, ash.exe, rebase.exe, and rebaseall exist in this folder - If any of them are missing, re-run Cygwin setup and select the dash, ash, and rebase packages 4.right-click your C:\Cygwin folder, uncheck Read-only (if its checked), and press OK. - When an error about not being able to switch some files comes up, select "Ignore All". Wait for this process to complete. 5.Browse to C:\Cygwin\bin in Windows Explorer 6.Right click dash.exe and click "Run as Administrator". A command Prompt should appear with nothing but a $ 7.Type /usr/bin/rebaseall -v, hit enter, and wait for the process to complete. - If you get errors about Cygwin processes running, try Step 1 again. If that still doesn't work, Restart your computer into safe mode and try these steps again. 8.Try opening Cygwin again. This process worked for me. I hope it works for you guys too. Source: http://cygwin.wikia.com/wiki/Rebaseall
