顯示具有 terminal 標籤的文章。 顯示所有文章
顯示具有 terminal 標籤的文章。 顯示所有文章

2014年11月8日 星期六

[Linux] 在 UTF8 Terminal 環境下,找尋 Big5 檔案內的關鍵字 @ Ubuntu 14.04

最近想要研究一些老檔案,都是 Big5 編碼,接著就想著到底該怎樣叫 grep 幫你查資料,因為 pattern 要用 Big5 編碼,但 Terminal 是 UTF-8 環境。

我想到的是先把 pattern 轉成 big5 後,透過 xxd 轉乘 hex code,然後一樣將 input 透過 xxd 輸出後用 grep 去找,結果堪用,但不是很方便。

問一下高手,高手獻技:

$ grep -r `echo -ne "大學" | piconv -f utf8 -t big5` target_files

還差一點,因為 Terminal 環境編碼關係,解法:

$ LC_ALL=C grep -r `echo -ne "大學" | piconv -f utf8 -t big5` target_files

此時 Terminal 輸出會亂掉,所以再把 output 從 Big5 轉成 UTF-8:

$ LC_ALL=C grep -r `echo -ne "大學" | piconv -f utf8 -t big5` target_files | piconv -f big5 -t utf8

若想要有 grep highlight ,那就再叫 grep 做一次吧 XD

$ LC_ALL=C grep -r `echo -ne "大學" | piconv -f utf8 -t big5` target_files | piconv -f big5 -t utf8 | grep "大學"

收工!

2014年10月24日 星期五

[Linux] Docker 使用筆記 - 透過 nsenter 進入當前 container 操作環境 @ Ubuntu 14.04

早期的 Docker 可以直接用 lxc-attach 取得 container 的 terminal 環境:

$ sudo docker ps --no-trunc
$ sudo lxc-attach -n CONTAINER_ID


但新版的只會噴 lxc-attach: failed to get the init pid 訊息,所以可以改用 nsenter 來操作吧!

$ sudo docker version
Client version: 1.0.1
Client API version: 1.12
Go version (client): go1.2.1
Git commit (client): 990021a
Server version: 1.0.1
Server API version: 1.12
Go version (server): go1.2.1
Git commit (server): 990021a

$ curl https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.gz | tar -zxf-
$ cd util-linux-2.24
$ ./configure --without-ncurses
$ make nsenter
$ sudo cp nsenter /usr/local/bin

$ sudo docker inspect --format "{{ .State.Pid }}" CONTAINER_ID_OR_NAME
$ sudo nsenter --target $PID --mount --uts --ipc --net --pid
root@##############:/#

2013年10月23日 星期三

[OSX] 使用 Command line 啓動 VNC 和設定連線密碼 @ Mac OSX 10.8

如果說,都用 Mac OS X 遠端 Mac OS X,那的確不太需要設定 VNC 密碼,因為會轉換到 Mac OS X 自己的協定,但如果是從 Windows/Linux 連到 Mac OS X 的話,設定密碼還是安全一點點。

啓動 VNC:

$ sudo defaults write /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled -bool false
$ sudo launchctl load /System/Library/LaunchDaemons/com.apple.screensharing.plist


設定 VNC 密碼:

$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -off -restart -agent -privs -all -allowAccessFor -allUsers -clientopts -setvncpw -vncpw VNC_PASSWORD
Starting...
bind(): Address already in use
com.apple.screensharing: Already loaded
Activated Remote Management.
Stopped ARD Agent.
Stopped VNC Privilege Proxy
buffalo: Set user remote access.
macports: Set user remote access.
ookon: Set user remote access.
Set the client options.
Setting allow all users to YES.
Setting all users privileges to ##########.
Done.