顯示具有 Linux Skills 標籤的文章。 顯示所有文章
顯示具有 Linux Skills 標籤的文章。 顯示所有文章

2011/04/13

vbindiff : Good tools for compare binary files.

vbindiff is a graphical windows tools for compare binary file. It can easy find out what bytes different in ASCII or EBCDIC mode. more information in manual page :) SYNOPSIS vbindiff file1 [ file2 ] DESCRIPTION Movement Keys ------------- Up Move one line (16 bytes) towards the beginning of the file Down Move one line (16 bytes) towards the end of the file Left Move one byte towards the beginning of the file Right Move one byte towards the end of the file PageUp Move one page towards the beginning of the file PageDn Move one page towards the end of the file Home Move to the beginning of the file End Move to the end of the (shorter) file F Search for a string or byte sequence G Move to a specified file position Other Keys ---------- Enter Move to the next difference between the files Space (same as Enter) C Toggle between ASCII and EBCDIC display E Edit currently displayed section of file Esc Exit VBinDiff Q Exit VBinDiff

2011/04/12

SD card automount for Embedded Linux

If we want to using SD card auto mount.

Please reference manual page of command "mdev".

#  mdev --helpBusyBox v1.18.4 (2011-04-01 22:32:35 CST) multi-call binary.
Usage: mdev [-s]
-s      Scan /sys and populate /dev during system boot
It can be run by kernel as a hotplug helper. To activate it: echo /sbin/mdev > /proc/sys/kernel/hotplug

It uses /etc/mdev.conf with lines[-]DEVNAME UID:GID PERM [>|=PATH] [@|$|*PROG]

 

Follow above information.

step 1. make sure build the feature "hotplug" to kernel

step 2. edit /etc/mdev.conf like below :

sd.*    0:0     660     */sbin/automount.sh     $MDEV

mmc.*   0:0     660     */sbin/automount.sh     $MDEV

step 3. add /sbin/automount.sh like below:

 

automount

 

step 4.  Add command at /etc/rc.d/rc.sysinit

# echo /sbin/mdev > /proc/sys/kernel/hotplug

2011/04/11

Bash Introduction (4/12)

4/12 Present in Alphanetworks.

 

 

2010/03/25

Standard I/O Redirection

Linux 提供三種 I/O Streams 給程式使用

STDIN (0) : default is keyboard.

STDOUT (1) : default is terminal.
STDERR (2) : default is terminal.

而 STDOUT 和 STDERR 可以被重新導向至檔案 ( I/O Redirection ), 作法如下:

$ binary > (將 STDOUT 重新導向)
$ binary 2> (將 STDERR 重新導向)
$ binary &> (將所有輸出重新導向)
$ binary 2>&1 (將 STDERR 重新導向至 STDOUT)
$ binary >&2 (將STDOUT 重新導向至 STDERR)

使用 > 輸出導向的檔案預設會被完全覆蓋, 也可改用 >> 來添加在原檔案的結尾

而關閉 File Description 的方式則如下:

$ n<&- (關閉 Input File Description n)
$ 0<&- , $ <&- (關閉 STDIN)
$ m>&- (關閉 Output File Description m)
$ 1>&- , $ >&- (關閉 STDOUT)
reference : http://tldp.org/LDP/abs/html/io-redirection.html


2010/03/14

Linux 底下處理減號開頭的檔案名稱

在 Linux 底下, 由於減號(-) 通常都被來利用為指令的 Option,

因此若我們執行檔案處理的指令時,

若遇到減號開頭的檔名 (Example : -filename)

則通常會無法順利執行,

例如:

$ rm -filename

$ mv -filename filename

$ cp -filename filename

002.jpg

這幾個執行的結果都是失敗的!

遇到這種情況我們通常可以透過 ./ 或是 -- 來解決:

$ cp ./-filename filename

$ rm -- filename

003.jpg

當然啦,在UNIX底下, 減號是非常常用的特殊符號, 極度不建議拿來命名檔案或資料夾,

但若真的遇到這種狀況的話, 就透過以上的方式來處理囉 :)

2010/03/09

X over ssh

一般我們遠端使用 Linux or Unix 主機時,

常常是透過 telnet 或是 ssh 來做文字模式的操作 如果我們希望遠端使用 Linux 或是 Unix 系統的圖形介面,

常用的方式有 VNC, 另一種就是透過 ssh 來啟動 X 圖形介面.

X 視窗系統(目前版本為 X11) 提供了圖形介面來代替文字操作介面, 多數 Unix-linx 的作業系統都有支援,

ssh 則是使用 Secure shell, 透過網路來做兩台主機間的溝通. 可以在加密的狀態下使兩台有ssh的裝置透過網路連接

如果我們透過 ssh 使用 X windows system,

就可以透過遠端連線來使用圖形話GUI介面,
要使用 X over ssh 要先準備幾個項目
1. 首先在本機端 (local) 安裝 X server
2. 遠端系統必須預先安裝 xterm, xeyes, xcalc, xlogo, xedit, xload, xclock, and twm, mwm, Gnome and/or KDE
3. 選擇性安裝 xsnow, rclock, rxvt, xpaint, xdaliclock, Blackbox, wmaker, and fvwm2

4. 防火牆必須允許 ssh 通過
5. 遠端系統必須運行 sshd .

當準備好以上幾個項目後, 就可以透過簡單的指令來實作 X over ssh  

只要在平常ssh 指令後加上 "-X" option, 就能讓 X windows 通過 ssh 來運行

例如:

ssh -X 192.168.0.100
若是遠端的主機使用標準外的ssh port (default port 22),
則可以加上 "-p" 來指定使用的 port.

ssh -X -p 8080 192.168.0.100

當login近遠端的主機後, 及可以透過 command line 帶起圖形介面的APP.



這邊的例子是透過 X 啟動遠端主機的 Wireshark,


要注意的是, 雖然 wireshark 是開在 local 的畫面,


但實際上透過網路鯊魚擷取到的封包是遠端主機網路介面抓到的喔!


另外也可以在透過ssh -X 連線到遠端主機後,

執行遠端的 gnome 介面或是 kde 介面,

就可以以圖形介面來操作系統囉!

kde介面:

$ startkde

gnome 介面:

$ gnome-session



reference:

http://www.vanemery.com/Linux/XoverSSH/X-over-SSH2.html

2010/03/04

Vim Session

Vim 7 除了相當好用的 Vim Tab Pages 功能外,
也能搭配 mksession 來儲存目前 Vim 的狀態,
例如,每次工作實都開了一些Vim Tab Pages,
或是設定了一些 .vimrc 中非預設的設定
但關掉 Terminal 後就通通消失,
Tab Page要重開, 設定也要重新設定過,

這時候就可以利用 mksession的功能囉!





:mksession 預設會幫你在目前的目錄底下產生 Session.vim
裡面記錄了已經開啟的 Tab 資訊以及其他設定,
也可以用縮寫 :mks

下次開始 Vim 時, 只要加上 -S Session.vim,






或是開啟 Vim 後使用 :source Session.vim,




就能恢復上次工作的狀態了:)




當然,也可以自己決定Session檔的名稱,
只要在 mksession 時指定檔案名稱即可

:mksession filename

要注意的是如果Session file 已經存在,
則必須要加上 ! 來覆蓋已存在的檔案.

:mksession! filename


搭配Tab Pages 真的是蠻方便的功能唷^^b



2010/02/07

Vim Tab Page 功能

Vim Tab功能


:tae[dit] or tabnew + filename     開新 tab page
:tabc 
:tabc[lose] {count}
:tabo[nly]

:tabn[ext] 下一個tab
:tabp[revious] 上一個tab



:tabm[move] [N] 移動目前的Tab Page順序到第N頁, 若N為0則移動到第一頁.

:tabfind filename* 尋找當前目錄檔案filename開頭的檔名
:tabs  列出以開啟的tab
:tabdo %s/foo/boo/g  將開啟的tab中所有foo替換成boo

Note that : Tab Page 是 Vim 7 開始加入的新功能

--

2010/01/25

[ssh notes]ssh config

在~/.ssh/config
可設定預設ssh連到主機的 Account 和 port.

example:

Host 名稱
HostName DomainName
User 預設登入帳號
Port port number

2010/01/11

[vim skills] makeprg and errorformat

makeprg 與 errformat 讓 vim 結合了編譯器的功能

透過 makeprg 可以在vim 中執行 Makefile ,
而 errorformat 則記錄了編譯過程中的錯誤與警告,
讓我們可一邊撰寫程式碼, 一邊除錯

而 makeprg 選項的功能是定義編譯時執行的指令,
當我們在 vim 的command mode 輸入 :make 時,
makeprg 所代表的指令就會被執行, 預設為 make.



我們也可以將makeprg設定為其他的指令, 例如:

那我們在執行 :make 時, 就會執行 make clean啦!
(當然應該不會有人把make設定為make clean吧...)

而如果邊一時發生錯誤呢?
以下是一個錯誤示範:

當我們在 command line 敲下 :make後, 一堆錯誤就跑出來啦!

這邊我們可以用 :cl 來列出所有的錯誤訊息

第一個數字就是錯誤代號,可以用在 :cc 指令
:cc 會跳到最近一個錯誤發生的地方(沒用過當然就是跳到最開始的錯誤囉...)
而 :cc4 就會跳到錯誤代號4的程式碼的位置,





很方便吧:)

其他常用來觀察錯誤的指令如下

:cl 列出所有錯誤
:cn 跳到下一個錯誤
:cp 跳到上一個錯誤
:cc 跳到最近觀察過的錯誤,若cc後帶有數字,則跳到該錯誤
:cr 跳回第一個錯誤
:cla 跳到最後的錯誤

其他更詳細的設定與說明, 可以參考 vim的 help file 中的quickfix部分.


參考資料:
Anthony的<<用vim寫程式快n倍>>