Showing posts with label freeBSD. Show all posts
Showing posts with label freeBSD. Show all posts
Tuesday, September 16, 2014
Tuesday, February 12, 2013
builtin http server
有時候會有需要臨時開個 http server ,傳東西或是啥得很方便
Python 有內建
[update] Python 3 這個 module 換了名字 0w0
$ python2 -m SimpleHTTPServer 5566
Perl 的話可以用這個 CPAN module
$ perl -MHTTP::Server::Brick -e '$s=HTTP::Server::Brick->new(port=>5566); $s->mount("/"=>{path=>"./"}); $s->start'
Ruby 也有內建,不過也是比較醜
$ ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 5566, :DocumentRoot => Dir.pwd).start'
php 5.4 後也有內建... 不過誰有 php54 呢(逃
$ php -S localhost:8000 -t ./
Thursday, December 13, 2012
Running python in 32-bit mode for wxPython
在 Mac OS X 上面寫 wxpython 時,必須打開 32bit mode 不然他不會動 ...
解法:
加入以下環境變數
export VERSIONER_PYTHON_PREFER_32_BIT=yes
參考
http://stackoverflow.com/questions/2088569/how-do-i-force-python-to-be-32-bit-on-snow-leopard-and-other-32-bit-64-bit-quest
http://stackoverflow.com/questions/4665818/running-python-in-32-bit-more-for-wxpython
Wednesday, November 21, 2012
sha-bang! running scripts on Unix machines
reference: http://en.wikipedia.org/wiki/Shebang_(Unix)
sha-bang 是 Unix 系統上面的特殊慣例,由一個 # (sharp) 和一個 ! (bang) 組成
在 script 中,這個慣例用來表示要用哪個 interpreter 來解釋 / 執行這個 script
一般用絕對路徑來表示,例如 #!/bin/sh 來呼叫外部的 Bourne shell
#!/path/to/the/interpreter [arguments]
常見例子:
#!/bin/sh
#!/bin/sh -x
#!/bin/bash
#!/bin/sed -f
#!/usr/bin/awk -f
#!/usr/bin/perl
#!/usr/bin/python
#!/usr/bin/ruby
當然也可以很空虛的...
#!/bin/cat
另外,有時候為了可攜性,會用 /usr/bin/env python 這種用法來找到該機器的 interpreter 在哪邊
然後不要傻呼呼的吃到 Permission denied. 才在哭說不知道要怎麼跑 lol
chmod +x your_script
sha-bang 是 Unix 系統上面的特殊慣例,由一個 # (sharp) 和一個 ! (bang) 組成
在 script 中,這個慣例用來表示要用哪個 interpreter 來解釋 / 執行這個 script
一般用絕對路徑來表示,例如 #!/bin/sh 來呼叫外部的 Bourne shell
#!/path/to/the/interpreter [arguments]
常見例子:
#!/bin/sh
#!/bin/sh -x
#!/bin/bash
#!/bin/sed -f
#!/usr/bin/awk -f
#!/usr/bin/perl
#!/usr/bin/python
#!/usr/bin/ruby
當然也可以很空虛的...
#!/bin/cat
另外,有時候為了可攜性,會用 /usr/bin/env python 這種用法來找到該機器的 interpreter 在哪邊
然後不要傻呼呼的吃到 Permission denied. 才在哭說不知道要怎麼跑 lol
chmod +x your_script
Saturday, November 3, 2012
compress and decompress
tar options
-c, --create create a new archive
-t, --list list the contents of an archive
-u, --update only append files newer than copy in archive
-x, --extract extract files from an archive
-a, --auto-compress use archive suffix to determine the compression program
-f, --file ARCHIVE use archive file or device ARCHIVE
-v, --verbose verbosely list files processed
compress options
-j, --bzip2
-z, --gzip, --gunzip --ungzip
-J, --xz
--lzma
-Z, --compress, --uncompress
簡言之,常用的格式
create [zj]cvf Dir.xxx Dir
extract [zj]xvf Dir.xxx
懶的想的話 a 選項可以打天下 acf or axf 萬用
================================================
tar
$ tar cvf FileName.tar DirName
$ tar xvf FileName.tar
gz
$ gzip FileName
$ gunzip FileName.gz # or gzip -d
tar.gz
$ tar zcvf FileName.tar.gz DirName
$ tar zxvf FileName.tar.gz
bz2
$ bzip2 FileName # or bzip2 -z
$ bunzip2 FileName.bz2 # or bzip2 -d
tar.bz2
$ tar jcvf FileName.tar.bz2 DirName
$ tar jxvf FileName.tar.bz2
tgz (其實就是 gzip)
$ tar zcvf FileName.tgz DirName
$ tar zxvf FileName.tgz
tar.tgz
$ tar zcvf FileName.tar.tgz FileName
$ tar zxvf FileName.tar.tgz
.7z
Arch pacman: extra/p7zip
$ 7zr a FileName
$ 7zr x FileName.7z
xz
xz FileName
xz -d FileName
lzma # XZ 的一種 format
lzma FileName
lzma -z
lha # 這個很少見,比較有梗的大概是他的 man page 的 BUS 吧(?)
$ lha a FileName.lha FileName
$ lha x FileName.lha
Z (compress)
這個超級古老了,應該不會遇到 (大多已被 gzip 取代)
compress 原本是 UNIX 下的商業軟體,其 POSIX 實現是 ncompress
$ compress FileName
$ uncompress FileName.Z
tar.Z
$ tar Zcvf FileName.tar.Z DirName
$ tar Zxvf FileName.tar.Z
.zip # we love gzip!
$ zip FileName.zip DirName
$ unzip FileName.zip
.rar
$ rar a FileName.rar DirName
$ rar x FileName.rar
$ unrar x FileName.rar
-c, --create create a new archive
-t, --list list the contents of an archive
-u, --update only append files newer than copy in archive
-x, --extract extract files from an archive
-a, --auto-compress use archive suffix to determine the compression program
-f, --file ARCHIVE use archive file or device ARCHIVE
-v, --verbose verbosely list files processed
compress options
-j, --bzip2
-z, --gzip, --gunzip --ungzip
-J, --xz
--lzma
-Z, --compress, --uncompress
簡言之,常用的格式
create [zj]cvf Dir.xxx Dir
extract [zj]xvf Dir.xxx
懶的想的話 a 選項可以打天下 acf or axf 萬用
================================================
tar
$ tar cvf FileName.tar DirName
$ tar xvf FileName.tar
gz
$ gzip FileName
$ gunzip FileName.gz # or gzip -d
tar.gz
$ tar zcvf FileName.tar.gz DirName
$ tar zxvf FileName.tar.gz
bz2
$ bzip2 FileName # or bzip2 -z
$ bunzip2 FileName.bz2 # or bzip2 -d
tar.bz2
$ tar jcvf FileName.tar.bz2 DirName
$ tar jxvf FileName.tar.bz2
tgz (其實就是 gzip)
$ tar zcvf FileName.tgz DirName
$ tar zxvf FileName.tgz
tar.tgz
$ tar zcvf FileName.tar.tgz FileName
$ tar zxvf FileName.tar.tgz
.7z
Arch pacman: extra/p7zip
$ 7zr a FileName
$ 7zr x FileName.7z
xz
xz FileName
xz -d FileName
lzma # XZ 的一種 format
lzma FileName
lzma -z
lha # 這個很少見,比較有梗的大概是他的 man page 的 BUS 吧(?)
$ lha a FileName.lha FileName
$ lha x FileName.lha
Z (compress)
這個超級古老了,應該不會遇到 (大多已被 gzip 取代)
compress 原本是 UNIX 下的商業軟體,其 POSIX 實現是 ncompress
$ compress FileName
$ uncompress FileName.Z
tar.Z
$ tar Zcvf FileName.tar.Z DirName
$ tar Zxvf FileName.tar.Z
.zip # we love gzip!
$ zip FileName.zip DirName
$ unzip FileName.zip
.rar
$ rar a FileName.rar DirName
$ rar x FileName.rar
$ unrar x FileName.rar
Friday, October 19, 2012
some rsync options
筆記一下常用的 rsync options,備份東西用
rsync -avzPe ssh src des
# a: archive mode, -rlptgoD (no -H,-A,-X)
# v: verbose
# z: compressed
# P: --partial --progress
# e ssh: over ssh
rsync -avzPe ssh src des
# a: archive mode, -rlptgoD (no -H,-A,-X)
# v: verbose
# z: compressed
# P: --partial --progress
# e ssh: over ssh
Monday, September 3, 2012
newTA in CSCC
寫一篇在 CSCC (資工系計中)一個月來的心得吧
主要是修完 SA/NA 課程後想要繼續跟著經驗的大神學長姊學習,從做中學,學中做
丟出應徵信後,接到考試通知,當天帶著有點不安的心情去考試了
每個原本很輕鬆的前輩(像是 pmli, liuyh 等)突然都嚴肅了起來,真的有點不自在...
不過面試完後我發現我對系計中的看法有些改變了,也不知道這是好還是壞XD
本來還蠻想拿到這份工作的,不過面試完後卻沒那麼積極了
想到 ijsung 學長說過的話:"真正高手是不會去系計中做管理的"
希望在未來的日子裡,能努力繼續為系上服務 :)
主要是修完 SA/NA 課程後想要繼續跟著經驗的大神學長姊學習,從做中學,學中做
知道更多有關於資訊服務的東西
你好:
歡迎報名系計中助教甄選,系計中本著為全體資工師生服務的精神, 希望
能招募有能力、肯學習、有責任心、態度積極的同學。
甄選過程將會有筆試,內容主要是 UNIX 基本指令及系統管理基本概念,
還有最重要的面試, 請你先想一想你來甄選系計中助教的目的是什麼?值
班時你要注意的事情為何?你在系計中看到有那些缺點需要改進? 或是你
對系計中其他任何建議,都將列入考慮。當然, 也歡迎你對於系計中這個
工作環境,提出任何問題。
考試日期將定於 7/30(星期一) 上午 10:00,於交大資工系計中(工程三
館 324) 舉行,屆時請務必準時出席,若有時間上的問題還請盡快回信通
知。
最後,請在收到這封信之後,回信告訴我們你已收到通知了,謝謝。
交大資工系計中新助教徵選委員會
歡迎報名系計中助教甄選,系計中本著為全體資工師生服務的精神,
能招募有能力、肯學習、有責任心、態度積極的同學。
甄選過程將會有筆試,內容主要是 UNIX 基本指令及系統管理基本概念,
還有最重要的面試,
班時你要注意的事情為何?你在系計中看到有那些缺點需要改進?
對系計中其他任何建議,都將列入考慮。當然,
工作環境,提出任何問題。
考試日期將定於 7/30(星期一) 上午 10:00,於交大資工系計中(工程三
館 324) 舉行,屆時請務必準時出席,若有時間上的問題還請盡快回信通
知。
最後,請在收到這封信之後,回信告訴我們你已收到通知了,謝謝。
交大資工系計中新助教徵選委員會
凱吉學長很高興我過來考試,筆試的題目還算簡單,主要是基本的概念而已
但是面試就很慘了,當面被 chown 前輩數落的有點慘,
每個原本很輕鬆的前輩(像是 pmli, liuyh 等)突然都嚴肅了起來,真的有點不自在...
不過面試完後我發現我對系計中的看法有些改變了,也不知道這是好還是壞XD
本來還蠻想拿到這份工作的,不過面試完後卻沒那麼積極了
想到 ijsung 學長說過的話:"真正高手是不會去系計中做管理的"
=========================================
後來接到通知說上了,開心的也沒有原本期望的那麼大,第一次大 meeting 也是很簡單的自我介紹,新生訓練
linpc 跟 ywang 兩位學長很用心的準備了精美簡報,詳細的介紹在系計中工作的詳細注意事項
工作態度,TA 工作概況、系計中提供服務內容、值班須知
各種需要注意的事情,pinrt, libman ...都要慢慢熟悉
在跟幾個前輩陪值完五個班後,也算是正式的 TA 了
目前工作是 PC,Linux,BSD 三個組
BSD 比較熟,參考 SA 時學的印象跟內部文件的參考還算順利的就把試爆機裝起來的
linux 則是遇到了很多奇怪的問題...目前努力解決中
目前先做的工作是編修 cshelp 上面的 wiki,把 vim 跟 shell 的部份整理一下,也拆了三間電腦教室XDDDD
系計中內部常常可以聽到很多神奇的八卦,很可怕
希望在未來的日子裡,能努力繼續為系上服務 :)
系計中最年輕 TA,ymli 正式上任
Friday, June 29, 2012
vim tips: folding fun
本文參考自 : https://www.linux.com/learn/tutorials/442438-vim-tips-folding-fun
介紹 vim 的 folding 技巧,也就是如何乾淨的把 code 折疊起來
首先,vim folding 指令都是由 z 開頭,我的記法是 zip the code
z 開頭的指令 zt zz zb 這三個很好用,順便提一下
功能是把游標目前所在的行捲到螢幕的 top / center / bottom
這在臨時上下捲動頁面半頁或是要邊寫 function 時很好用
vim 底下:h z 可以看到 folding 相關的指令 (這邊把其他不相干的刪減掉了)
BTW,最完整的教學在 :h fold.txt 裏面可以看到
zA zA open a closed fold or close an open fold
recursively
zC zC close folds recursively
zD zD delete folds recursively
zE zE eliminate all folds
zF zF create a fold for N lines
zO zO open folds recursively
za za open a closed fold, close an open fold
zc zc close a fold
zd zd delete a fold
zf zf{motion} create a fold for Nmove text
zj zj 1 move to the start of the next fold
zk zk 1 move to the end of the previous fold
看的懂英文應該基本上就知道這幾個要怎麼用了XD
最常用的是 zf + {motion}
像是 zf2j 可以向下折疊兩行 (zip folding 2 j),就跟你用 2j 在 vim 裏面往下移動兩行一樣
另外一種方法是在 normal mode 下 :N, M fold ,N M 是行數,把 N, M 行之間的 code 折起來
再來一種是 {Visual}zf 也就是用 visual 模式下選取要 folding 的區域,然後再用 zf 幫你折起來
zf 的 motion 也可以搭配 vim 的 text object 來使用,像是 zfa} 或是 zfa{ 可以向下或向上折疊一段落
當然,也可以搭配 searching 來找,zf/pattern 就是折疊到第一個你找到的 pattern
接下來是使用 folding 的方法
zo / zc 則是拿來 open/close folding 的
zO / zC 可以 打開/關閉 底下的子 folding
當然,za 和 zA 可以把 folding 當成電燈開關一樣,打開 folded 的區塊, fold 被打開的區塊
zr / zm 是將 fold level 開啟和關閉一層
zR / zM 是對所有的 fold level 作,也就是打開 / 關閉整個檔案裡所以的 folding
在被 folded 的 code 間移動有很快的作法, zj / zk ,如同你所想的,移動到 上 / 下個 folded 的 code
zd delete 掉游標所在的 folding
zE delete 所有的 folding
最後, vim 在處理被 folding 起來的區塊時,會把他當成像是一行文一樣,也就是說,可以對他做一行的操作,像是 dd 和 yy 等
Wednesday, May 30, 2012
Tmux 用法
tmux 是噗浪上 @mosky 大大之前推薦的 terminal multiplexer
其實這玩意跟 screen 很像,不過最大差別應該在於 license 不同 (BSD vs GPL),有人不爽用XDDD
他最強大的功能在於 split pane
screen 的概念是一個 screen 底下有多個 window
tmux 則是可以用有多個 window,window 底下又可以有多個 pane, pane 又可以隨時展開成 window
tmux 還有一個特色功能就是 title 可以設成中文 (貌似是 UTF8)
不過應該沒人會無聊設 title 時還切換輸入法打中文,好像是有點雞肋的功能XDD
漫畫
src: http://pragprog.com/book/bhtmux/tmux
一般 Debian based Linux 可以用 apt-get install tmux 直接安裝
Ctrl-B (前導鍵, 類似 screen 的 Ctrl-A)
不過如果在像是 vim 或是 less 等基於 vi UI 的 pager
Ctrl-B 是 PageUp ,反而操作不便(要多按兩下)
screen 綁的 Ctrl - A 在 vim 裏面是比較不會用到的數字物件遞增的功能,較不會影響我對 vim 的使用
當然 config 寫一寫這些 key binding 都可以改的XDDD
以下常用功能介紹
基於 window
Ctrl-B c create 創建新 window
Ctrl-B & 關閉目前的 window
Ctrl-B n/p next/previous 切換到下一個 / 上一個 window
Ctrl-B [N] 切換到 [N] 號 window
Ctrl-B d detach 目前的 session / shell 下 tmux attach 可以恢復 session
Ctrl-B ? 大絕招,顯示所有 key binding
Ctrl-B ~ tmux message log
Ctrl-B l 兩個 window 間往返
Ctrl-B w window list
Ctrl-B , rename window title
基於 pane
Ctrl-B " 水平 split
Ctrl-B % 垂直 split
Ctrl-B x 關掉目前 pane
Ctrl-B ! 把目前的 pane 搬到新的 window 下
Ctrl-B Ctrl [上下左右] 調整 pane 大小
Ctrl-B Alt [上下左右] 調整 pane 大小 (一次調五格)
Ctrl-B space 切切看其他 pane 排列方式
Ctrl-B q 顯示 pane 編號 (持續一秒)
Ctrl-B t 在目前的 pane 顯示時間
Ctrl-B o 切換到下一個 pane
Ctrl-B [上下左右] 切換到該方向的 pane
Ctrl-B { 或 } 向前/後移動 pane
Ctrl-B Alt/Ctrl o 逆時針 / 順時針旋轉 pane
不過其實他的 man page 已經很完整了
C-b Send the prefix key (C-b) through to the application.
C-o Rotate the panes in the current window forwards.
C-z Suspend the tmux client.
! Break the current pane out of the window.
" Split the current pane into two, top and bottom.
# List all paste buffers.
$ Rename the current session.
% Split the current pane into two, left and right.
& Kill the current window.
' Prompt for a window index to select.
, Rename the current window.
- Delete the most recently copied buffer of text.
. Prompt for an index to move the current window.
0 to 9 Select windows 0 to 9.
: Enter the tmux command prompt.
; Move to the previously active pane.
= Choose which buffer to paste interactively from a list.
? List all key bindings.
D Choose a client to detach.
[ Enter copy mode to copy text or view the history.
] Paste the most recently copied buffer of text.
c Create a new window.
d Detach the current client.
f Prompt to search for text in open windows.
i Display some information about the current window.
l Move to the previously selected window.
n Change to the next window.
o Select the next pane in the current window.
p Change to the previous window.
q Briefly display pane indexes.
r Force redraw of the attached client.
s Select a new session for the attached client interactively.
L Switch the attached client back to the last session.
t Show the time.
w Choose the current window interactively.
x Kill the current pane.
{ Swap the current pane with the previous pane.
} Swap the current pane with the next pane.
~ Show previous messages from tmux, if any.
Page Up Enter copy mode and scroll one page up.
Up, Down
Left, Right
Change to the pane above, below, to the left, or to the right of the current pane.
M-1 to M-5 Arrange panes in one of the five preset layouts: even-horizontal, even-vertical, main-horizontal, main-ver‐
tical, or tiled.
M-n Move to the next window with a bell or activity marker.
M-o Rotate the panes in the current window backwards.
M-p Move to the previous window with a bell or activity marker.
C-Up, C-Down
C-Left, C-Right
Resize the current pane in steps of one cell.
M-Up, M-Down
M-Left, M-Right
Resize the current pane in steps of five cells.
Key bindings may be changed with the bind-key and unbind-key commands.
Monday, May 7, 2012
workstation beginer's guide
本文轉自我 BS2 個板,把圖片和 link 換一換XD
==============================================================================
本篇文章為板主半夜睡不著覺夢遊不小心打出來的文章
不保證其正確性,但很開心能與大家分享
--------------------------------------
前言:大一同學應該都能漸漸體會到,愈來愈多 老師/助教 會要求同學要在系上工作站
環境上完成作業,有鑑於大多同學對工作站 Unix-like system 很陌生,而我個人對各個
助教在解釋工作站時覺得有些小細節會有小遺漏,無法帶給同學比較完整、宏觀的教學
於是乎我來夢遊一篇教學 XD
==============================================================================
Reference.
由於我的能力以及本教學涵蓋範圍有限,希望同學有空時可以參考以下資源
《UNIX PowerTools, 3nd Edition》
《Bash Guide for Beginners》 [PDF, 2e ]
《Learning the bash Shell, 3rd Edition》
《Classic Shell Scripting》
《Essential System Administration, 3rd Edition》
《交大資工系 SA/NA 課程》 sysadm2011 netadm2012
《FreeBSD Handbook》
《工三的系計中專業的助教ㄉㄉ們》
==============================================================================
大綱
主要提這三個面向的簡單概覽 (意思就是你別想從這份教學中學到太多 :P )
about UNIX workstation
shell command
the vim editor
==============================================================================
Ch 1. Unix
1.1 history
1.2 difference between Unix-like systems
1.3 why Unix
==============================================================================
1.1 history
UNIX 是米國 AT&T 公司在 1969 年於 Bell lab 發展出來的分時多人多工
並具有強大可攜性的作業系統
最早的 UNIX 是由兩位大師 Kenneth Thompson 和 Dennis M. Ritchie
共同開發的,一開始是用組合語言邊寫,後來 DMR 發明並改用 C 來重
寫 UNIX 整個系統,此為現代 Unix-like OS 的濫觴
更多小故事可以參考 DMR 大師發表的這篇論文
《The Evolution of the Unix Time-sharing System》
==============================================================================
1.2 difference between Unix-like systems
UNIX 系統後來因為一些商業問題而有了爭議,UC Berkeley 從 UNIX 為基礎
發展出 Berkeley Software Distribution (BSD)
BSD 系統的成功後來又發展了 FreeBSD、NetBSD、OpenBSD、Darwin 等
(Mac OS X的祖先)
BSD 後來又因為一些疑似手滑別人家的 code 而遭到了質疑,部份砍掉重練(?)
後跟乖乖一樣重新改版換包裝,各位觀眾!全新的 FreeBSD 4.4-Lite!
目前 FreeBSD 最新 stable 版本為 9.0 和 8.3
系上 BSD 工作站使用的是 FreeBSD 8.2-RELEASE-p3
==============================================================================
Linux 是另一個受人喜愛的作業系統 ,由 Geek 之王,Linus Torvalds 開發
# Mr, Linux, King of Geeks, Dad of 3
Linus 大學修 OS 時,玩了一個叫作 MINIX 的 UNIX 教學版本,因為它是教育
軟體,不准在上面玩其他有趣的事情,所以 Linus 就決定刻了一個自己的 OS
Kernel,並且丟到了 FTP 上面引起各大牛人們圍觀,大家東改西改,加上了很
多有用的 tools 和 patch ,Linus 決定,將新的作業系統以 GPL 授權發行
知名的 Linux distributions 很多, Ubuntu, Debian, Fedora, OpenSuSE ...
Linux 是好用的 server 和 desktop 系統,大家可以嘗試看看(私心)
==============================================================================
各個 UNIX-like 很多,可以參考幾張經每個 UNIX 家族樹
# from wiki
Linux 家族樹
# 光是 Linux 出來的分支就有這麼多
==============================================================================
1.3 why UNIX
為什麼我們要用 Unix 呢?老實說,這是信仰問題XD 各位可以去翻翻
《The UNIX- HATERS Handbook》 - Simson Garfinkel
這本還有 DMR 大師為其寫序的大作,Unix sucks :P
此外,可以比較知名 hacker esr (Eric Steven Raymond) 的大作
《The Art of Unix Programming》
兩本相較之後,你就會明白,why Unix 這個問題
==============================================================================
Some Unix Philosophy
UNIX is not just an operating system, but a way of life.
Unix Is Fun to Hack
Write programs that do one thing and do it well.
Write programs to work together.
Write programs to handle text streams, because that is a universal
interface.
Small is beautiful.
Make each program do one thing well.
Build a prototype as soon as possible.
Choose portability over efficiency.
Store data in flat text files.
Use software leverage to your advantage.
Use shell scripts to increase leverage and portability.
Avoid captive user interfaces.
Make every program a filter.
==============================================================================
Ch 2. Shell commands
2.1 what's shell
2.2 powerful shells
2.3 basic shell commands (and builtins)
2.4 more useful commands
==============================================================================
2.1 what's shell
shell 是一層讓 user 和 system kernel 溝通的那層"殼"
Command-line shells 替 OS 提供一層 command-line interface (CLI)
也許很多人會很不習慣用指令的方式來操控電腦,大家已經習慣滑鼠點點點
的用法,但是,身為資工系學生,能夠在麻瓜面前啪啪啪打指令是基本的XD
熟悉了 shell 的操控方式,很多時候工作會比圖形介面下來的簡單且輕鬆很多
並且,shell 的一步步是可以重現的(寫成 script) 讓重複的工作可以輕鬆重用
# vgod 大神的 Sikuli 基本上就是想做到 GUI 的 scriptting XD
==============================================================================
2.2 powerful shells
各家工作站上面提供的 shell 各有所不同
常見的 shell 有 bash, tcsh, zsh, Bourne shell (sh)
bash (Bourne-Again shell) 是 Linux 上的標準 shell
tcsh 是 BSD 上常見的 shell
zsh (The last shell you'll ever need!) 地表上最強的 shell
Bourne shell 最原始的 shell ,是各家 shell 的祖先
各個 shell 基本上都完整支援 Bourne shell ,大同小異卻但各有各的超能力
==============================================================================
2.3 basic shell commands (and builtins)
builtins shell commands 是 shell 為你提供的最基本的內建功能
我們可以透過 man builtins 指令 (man for manual) 來看到各個指令提供的
功能。
man 是最強大也是你必須要會的指令
man — format and display the on-line manual pages
在工作站上有任何問題就是問男人,他會告訴你一切有關這個指令的魔法
man man
男人阿!請告訴我 man 指令的用法吧!
註:每個 shell 提供的 builtins 略有不同
==============================================================================
cd (change directory)
cd 用來改變目前所在資料夾位置
cd dir # change to dir
cd # go home ( cd 後面什麼都沒接)
cd .. # 跑到上一層
cd - # 時空跳轉,回到剛剛到過的資料夾
pwd (print working directory)
pwd 用來知道我現在人在那邊
echo (毫無反應,只是個 echo)
echo Hello world! # 印出 Hello world!
==============================================================================
bg (background)
bg 用來把工作 (process) 丟到背景執行
fg (foreground)
fg 把丟到背景的 process 拿回來
kill (kill a process)
kill 送出特定 Signal 給指定的 pid
kill -9 5566 # 送 9 號 signal (去死吧!) 給 pid 為 5566 的 process
==============================================================================
logout (logout)
從你目前的 shell 登出
a geeky way : press Ctrl-D
按下 Ctrl-D 會送一個 EOF 給你的 shell 代表告訴 shell 我要登出
簡單的 builtins 到這邊,接下來是一些常用指令教學 :D
==============================================================================
ls ( list directory contents )
ls # 列出目前這裡有什麼
ls -a # list all
ls -l # list in long format
mkdir (make directories)
mkdir dir # make the directory 'dir'
rm (remove directory entries)
rm -r dir # recursively remove everything in dir
rm -f file # force remove it
rm -rf / # make your computer faster !!!!
==============================================================================
cp (copy files)
cp file1 file2 # copy file1 to file2
cp -r dir # recursively copy everything in dir
mv (move files)
mv file1 ../ # move file1 to the father directory
mv file1 file2 # rename the file
mv file{1,2} # do the same thing
cat (concatenate files and print on the standard output)
cat file1 # print file1 out
tac (reverse cat)
==============================================================================
more (a simple pager for viewing a file)
more file1 # let's see what's in file1
less (less is more than more)
less file1 # similar to 'more file1'
both more and less are based on vi-style command keys
head (output the first part of files, default 10 lines)
head file1 # print first 10 lines of file11
tail (output the last part of files, default 10 lines)
tail file1 # print last 10 lines of file1
==============================================================================
2.4 more useful commands
這部份要提的是資工系學生必會的幾個好用指令
screen # 一個 ssh 連線,多個 user session
irssi # a IRC client for UNIX
gcc # GNU's compiler collection
==============================================================================
screen (screen manager with VT100/ANSI terminal emulation)
當你今天要在工作站同時做很多事情時,我們不必開多個 ssh 連線過去
screen 可以幫我們在本機端模擬出 login sessoin 讓我們能同時使用很多個
shell 分別做不同的工作
screen 最強大的功能是可以把現在的 screen detach 起來,下次從別處 ssh
到工作站時可以把 screen 拿回來,繼續剛剛為完成的工作
這個功能在編譯或是跑大型程式時很好用,掛 BBS 和 IRC 也很方便
screen 功能強大,請參考 #177VUE1 #17DP0JL [P_xatier @bs2.to] 兩篇文章
==============================================================================
irssi (a modular IRC client for UNIX)
Internet Relay Chat (IRC) 是網路上真正高手雲集之處
如果你想多認識世界各地的大神們,上 IRC 找準沒錯!
irssi 是 UNIX 機器上的 IRC client
irssi IRC 的操作方法繁多無法一一列舉,請參考這兩篇優質教學
Lzy's 用 screen + irssi 上 irc 之鄉民版教學 (含Q&A)
erepublik IRC的推廣文! (這篇漫畫超好笑XD)
系上在 Freenode 上面也有 IRC channel,/j #nctuNASA ILoveCSCC # 後面是密碼
/j #nctucsie # 這邊都沒人
/j #nctucs # 系計中ㄉㄉ專用
==============================================================================
gcc / g++ (GNU project C and C++ compiler)
在工作站上面寫 C code 常常會用到的標準 complier
gcc test.c # default complie to 'a.out'
gcc test.c -o test # set the output file named 'test'
gcc -c test.c # only compile (output .o files)
常見的 gcc flags
-std=c99 -std=c++0x -ansi # using different standard
-Wall -Wextra -pedantic # warning options
-O2 -O3 -Os -Ofast # optimization options
-lm # link to the math lib
==============================================================================
screen, irssi, gcc 的功能強大到遠遠不只你想像的那樣,這邊給出幾個 ref 參考
GNU Screen manual
Irssi documentation and tutorials
GCC online documentation
screen 和 irssi 教學很短,一下子就唸完了
gcc 的 manual 超精美XD 當作床邊故事來看吧 :P
==============================================================================
Ch 3. the vim editor
3.1 vi, vim, and emacs
3.2 vim starters
3.3 master
==============================================================================
3.1 vi, vim, and emacs
遠在古老 UNIX 時代,各個巫師都喜歡自己刻一個自己順手的 editor ,有個叫
Bill Joy 的 hacker 發展了自己的 editor: vi
vi 的使用就像開車一樣,切換排檔的概念,不同 mode 底下能完成不同的事
常見的有 command mode 和 insert mode,分別能輸入指令和直接輸入文字
vi 已成為 UNIX 底下比備的標準編輯器,幾乎所有的 UNIX 都可以找到 vi
或是其衍生產品
MJ12Net : The vi editor
==============================================================================
vim, Vi IMproved 是 Bram Moolenaar 所開發的,當年他買了一台機器,可惜上面
沒有他愛用的 vi ,於是,他就自己在這台機器上面把 vi 給刻了出來(抖)
vim 承襲了 vi 的特性,並加入了許多強大的功能,並具有 vim script 的高度拓
展性,使得 vim 在 UNIX 界受到眾多 hackers 的喜愛
vim script 讓大家可以自由的替 vim 開發 plugins ,完成更強大的功能
更多請參考 vim.org
功能強大的代表就是 vim 不是很好學的,請參考 編輯器學習曲線圖比較XD
==============================================================================
emacs 則是是作業系統(誤) 為
在 UMIX 瀏覽器大戰中,vim 和 emacs 是敵對的文化,分別有兩派人馬支持著
emacs 是由 GNU 創辦人, 糟老頭 RMS (Richard M. Stallman) 在 MIT 開發的
emacs 最為人所知的是他的強大巨集拓展,以 Lisp 語言為基礎,emacs 提供了
強大的工作環境,你能在上面做任何你想做的事,包括泡咖啡和上噗浪(?)
http://en.wikipedia.org/wiki/Emacs#Extensibility
emacs 特性是依賴組合鍵,平常可以任意輸入文字,加上特殊按鍵組合可以打開
各種神奇功能 (PS. Emacs 的快捷鍵會引發腕管綜合症(誤))
有這麼一句話『emacs 是強大的作業系統,只是上面缺乏了一個好的編輯器』
關於編輯器之神(vim) 和神的編輯器(emacs) 的戰爭,請參考
wiki: Editor war
==============================================================================
3.2 vim starters
剛剛提到, vim 要上手非常不容易,我也不打算在這裡介紹 vim 的使用(毆)
提供以下資源,看完的(並實際動手練習)可以學會簡單的 vim 操作 (依序閱讀)
yannesposito: Learn Vim Progressively
vgod: 淺談模式”mode”與文字編輯的技術與學習
鳥哥的 Linux 私房菜: vim 程式編輯器
大家來學VIM(一個歷久彌新的編輯器)
cheat sheets (懶的看前面落落長文章的話)
vgod: 給程式設計師的Vim入門圖解說明
bullium.com : Vim Commands Cheat Sheet
VIM QUICK REFERENCE CARD
http://jrmiii.com/attachments/Vim.pdf
==============================================================================
3.3 master
對於有時間的人,可以去翻翻去看官方的精美 vim 教學
vim book
vimcdoc
Vim Tips Wiki
對於沒時間的人,可以玩玩看 vim 的簡單教學 (強烈建議去玩看看!!)
在工作站上打 vimtutor 指令,花個 20 分鐘,親身體驗 vim 的有趣世界
學習 vim 是一趟無法回頭的旅程(?) 一旦陷進去可能就會愛上這個 editor XD
==============================================================================
本夢遊教學到這邊結束
希望這份教學對同學們有幫助 :D
所有不懂的東西歡迎來問我
無論是站內信或是直接找我都可以
最後,送你們一張很棒的 cheat sheet
感謝您花時間閱讀 :D
==============================================================================
--
沒有人會為弱者流眼淚
--
▄▄▄▄ ▄▄ ▄▄▄ . . .‘‘ .
▇▄█ █ ▄▄█ . ‘ . . telnet://bs2.to
▄█▄█ ▄█ █▄▄ 。 .‘ .
Friday, May 4, 2012
Jail in FreeBSD
Jail 是 FreeBSD 上面提供 OS level virtualization 的工具
他提供了比 chroot 還要更強大的功能
可以把一台 FreeBSD 裝在裏面
========================================
建一台 jail 很簡單只要幾個步驟
http://www.freebsd.org/doc/handbook/jails-build.html
# setenv D /usr/jail/jailname
# mkdir -p $D
# cd /usr/src
# make buildworld # 要很久,請用 screen 掛著
# umount -f /tmp # 這邊因為 tmp 是不能 exec 的,所以要先 unmount 掉
# make installworld DESTDIR=$D
# make distribution DESTDIR=$D
# mount -t devfs devfs $D/dev
改 rc.conf
#vim /etc/rc.conf
jail_enable="YES"
jail_list="jailname"
jail_jailname_rootdir="/usr/jail/jailname"
jail_jailname_hostname=".xxxxxxxxxxxxxxxxxxxxxxxxx"
jail_jailname_ip="10.0.0.14"
jail_jailname_devfs_enable="YES"
jail_jailname_devfs_ruleset="devfsrules_jail"
# /etc/rc.d/jail start jailname
關機
# /etc/rc.d/jail stop jailname
現在有幾個 jail
#jls
JID IP Address Hostname Path
3 10.0.0.14 ********** /usr/jail/jailname
#jexec N /bin/tcsh # N 是第幾個 jail ID
先裝好 portmaster 和基本 tools
記得 jail 的網卡要在外面 rc.conf 裏面設 alias 像這樣
ifconfig_em1_alias0="inet 10.0.0.14 netmask 255.255.255.0"
jail 裏面的 /etc/resolv.conf 也要一下,不然 DNS 找不到
search example.org
nameserver 140.113.1.1
要 ping 測試的話要在外面改 sysctl
# sysctl security.jail.allow_raw_sockets=1
在 jail 裏面要出來的話就 Ctrl - D 就好了
他提供了比 chroot 還要更強大的功能
可以把一台 FreeBSD 裝在裏面
========================================
建一台 jail 很簡單只要幾個步驟
http://www.freebsd.org/doc/handbook/jails-build.html
# setenv D /usr/jail/jailname
# mkdir -p $D
# cd /usr/src
# make buildworld # 要很久,請用 screen 掛著
# umount -f /tmp # 這邊因為 tmp 是不能 exec 的,所以要先 unmount 掉
# make installworld DESTDIR=$D
# make distribution DESTDIR=$D
# mount -t devfs devfs $D/dev
改 rc.conf
#vim /etc/rc.conf
jail_enable="YES"
jail_list="jailname"
jail_jailname_rootdir="/usr/jail/jailname"
jail_jailname_hostname=".xxxxxxxxxxxxxxxxxxxxxxxxx"
jail_jailname_ip="10.0.0.14"
jail_jailname_devfs_enable="YES"
jail_jailname_devfs_ruleset="devfsrules_jail"
把 ports 系統搬過去
# cp -r /usr/ports /usr/jail/jailname/usr/ports
開機
# /etc/rc.d/jail start jailname
關機
# /etc/rc.d/jail stop jailname
現在有幾個 jail
#jls
JID IP Address Hostname Path
3 10.0.0.14 ********** /usr/jail/jailname
#jexec N /bin/tcsh # N 是第幾個 jail ID
先裝好 portmaster 和基本 tools
記得 jail 的網卡要在外面 rc.conf 裏面設 alias 像這樣
ifconfig_em1_alias0="inet 10.0.0.14 netmask 255.255.255.0"
jail 裏面的 /etc/resolv.conf 也要一下,不然 DNS 找不到
search example.org
nameserver 140.113.1.1
要 ping 測試的話要在外面改 sysctl
# sysctl security.jail.allow_raw_sockets=1
在 jail 裏面要出來的話就 Ctrl - D 就好了
DHCP NAT on FreeBSD
結果還是放棄 Linux server 方案了
KVM 的 Bridge tune 很久還是 tune 不通 orz
最後跟 Apua 借了兩台 VM
=================================
DHCP
# whereis isc-dhcp42-server
isc-dhcp42-server: /usr/ports/net/isc-dhcp42-server
請一邊服用 Handbook 說明
先改 dhcpd.conf 設定檔
# vim /usr/local/etc/dhcpd.conf
option domain-name "example.org";
option domain-name-servers 10.0.0.5; # 我自己的 IP
option subnet-mask 255.255.255.0;
default-lease-time 600;
max-lease-time 7200;
KVM 的 Bridge tune 很久還是 tune 不通 orz
最後跟 Apua 借了兩台 VM
=================================
DHCP
# whereis isc-dhcp42-server
isc-dhcp42-server: /usr/ports/net/isc-dhcp42-server
請一邊服用 Handbook 說明
先改 dhcpd.conf 設定檔
# vim /usr/local/etc/dhcpd.conf
option domain-name "example.org";
option domain-name-servers 10.0.0.5; # 我自己的 IP
option subnet-mask 255.255.255.0;
default-lease-time 600;
max-lease-time 7200;
subnet 10.0.0.0 netmask 255.255.255.0 { # 要 Listen 的 subnet
range 10.0.0.10 10.0.0.20; # 發這段出去
option routers 10.0.0.5; # 從我家流出去
}
host ftp { # 定義一組 host <=> MAC <=> static IP
hardware ethernet 00:50:56:b4:01:4c;
fixed-address 10.0.0.14;
}
改 /etc/rc.conf
#vim /etc/rc.conf
# for NAT
pf_enable="YES"
pflog_enable="YES"
gateway_enable="YES"
# 要 listen 的網卡的 interface 設好
ifconfig_em1="inet 10.0.0.5 netmask 255.255.255.0"
# 開啟 dhcpd
dhcpd_enable="YES"
# 要 listen 這張
dhcpd_ifaces="em1"
dhcpd_conf="/usr/local/etc/dhcpd.conf"
dhcpd_withumask="022"
最後一步,開啟服務
# /usr/local/etc/rc.d/isc-dhcpd start
error log in /var/log/messages
要 listen 的 subnet 跟發出去的 range 要一樣,我卡這關卡好久XD
NAT
這裡用 pf 來設,handbook 上面是用另一套 ipfw
在 pf.conf 裏面加上
#vim /etc/pf.conf
ext_if="em0" # 接外網
int_if="em1" # 接內網
ext_ip="my public IP" # public IP
int_ip="10.0.0.5" # DHCP 發的
lan_net="10.0.0.0/24" # subnet
nat on $ext_if from { $lan_net } to any -> ($ext_if)
Wednesday, May 2, 2012
Initial a FreeBSD machine
每次都會忘記
筆記一下標準步驟
參考這兩份 SA 講義
Install FreeBSD
Installing Applications
handbook 官方
=========================================
boot with a CD (iso)
contry selection => Taiwan
keymap => USA ISO
custom
partition
"C" for Create
"S" for bootable
"Q" to quit
boot manager
standard / bootmgr
label
"C" for Create
/ and swap
distribution
custom
base / kernels / man / src / ports
media
CD/DVD
commit
yes!
post installation
root password
user / group magememant
/bin/tcsh
'wheel' group
time zone => Asia/Taiwan
networking
interface, sshd
exit install
=========================================
initial ports system (sysinstall)
pick up the server in NCTU CS
/etc/portsnap.conf
SERVERNAME=portsnap.tw.FreeBSD.org
update ports tree (maybe time comsumming)
$ portsnap fetch extract update
$ cd /usr/ports/ports-mgmt/portmaster
$ make install clean
$ portmaster ports-mgmt/portaudit
=========================================
basic tools
vim
screen
mutt
wget / curl
Subscribe to:
Posts (Atom)