參考資料:
C 語言中的 sscanf() 函數
2014年10月30日 星期四
linux script
1. 判斷檔案是否存在
#!/bin/bash
file="/etc/hosts"
if [ -f "$file" ]
then
echo "$file found."
else
echo "$file not found."
fi -b FILE
FILE exists and is block special
-c FILE
FILE exists and is character special
-d FILE
FILE exists and is a directory
-e FILE
FILE exists
-f FILE
FILE exists and is a regular file
-g FILE
FILE exists and is set-group-ID
-G FILE
FILE exists and is owned by the effective group ID
-h FILE
FILE exists and is a symbolic link (same as -L)
-k FILE
FILE exists and has its sticky bit set
-L FILE
FILE exists and is a symbolic link (same as -h)
-O FILE
FILE exists and is owned by the effective user ID
-p FILE
FILE exists and is a named pipe
-r FILE
FILE exists and read permission is granted
-s FILE
FILE exists and has a size greater than zero
-S FILE
FILE exists and is a socket
-t FD file descriptor FD is opened on a terminal
-u FILE
FILE exists and its set-user-ID bit is set
-w FILE
FILE exists and write permission is granted
-x FILE
FILE exists and execute (or search) permission is granted參考資料:
Bash Shell: Check File Exists or Not
2014年10月23日 星期四
預設不啟動x window
為了節省資源,
在fedora可以預設把x window關掉。
打以下指令
# mv /etc/systemd/system/default.target /etc/systemd/system/default.target.bak
# ln -s /lib/systemd/system/runlevel2.target /etc/systemd/system/default.target
這樣下一次開機就不會啟動x window了
不過,若要啟動的話,
只要打
# startx
指令即可
參考資料:
Fedora 下设置系统不启动X window
Linux 的開機啟動流程
2014年10月22日 星期三
putty藍色字體看不清楚的問題
用putty連到linux server會出現藍色字體看不清楚的問題。
原本的顏色

選擇Colours的ANSI Blue,並且設定為以下數值
Red: 56
Green: 109
Blue: 199
這樣比較可以看的清楚了。

參考資料:
在putty 中设置字体的颜色和背景
2014年9月10日 星期三
Mapping of Address and Port (MAP)
最近在研究MAP這個東東,
這個東西主要是用來做什麼的呢?
眾所皆知, IPv4 address都已經發完了。
IPv6絕對是未來的方向。
可以想像的,
IPv4未來會成為IPv6網路的孤島。
可能會有總總因素,會讓使用者(client)或服務提供者(server)只能使用IPv4 network的情況,
而如何透過IPv6的網路來傳送IPv4的封包,
就是MAP要做的事情。
而要在IPv6的網路上傳輸,必需要有IPv6 address。
問題是如何把IPv4轉換成IPv6 address。
通常有兩個主要的方式,
stateful, stateless
什麼是stateful呢?
就是在每一個IPv4與IPv6轉換的設備上會有轉換的記錄,
例如:
292.11.45.1→2001:34:55:99:ac::2
292.45.11.3→2001:34:55:99:ac::3
也就是說每當要轉換時,必需由讀取這一個記錄,
才能了解要怎麼轉換。
而stateless則是會有一個演算法,
使得IPv4與IPv6可以直接透過這一個演算法來互相轉換。
一般來說都會比較推薦stateless的方式(原因是什麼我目前還不太清楚)。
而MAP主要分為
Mapping of Address and Port with Encapsulation (MAP-E)
與
Mapping of Address and Port with Translation (MAP-T).
這兩個主要的差別在於MAP-E是用封裝的方式,
直接在IPv4的封包外再加上IPv6的header,
這樣的好處是可以完整保存IPv4的封包。
但是,要傳送的封包是會比較大一點,因為額外加了IPv6的封包了嘛。
而MAP-T則是把IPv4的header轉換成IPv6的header,
缺點是額外做轉換的動作,
效能來說可能會比較慢一點。
先暫時寫到這裡,
最近一直在研究這個東西,
應該還會持續一段時間。
參考資料:
【自由谈】城域网IPv6过渡技术——MAP技术(1)
2014年9月1日 星期一
linux下停用IPv6
直接寫入1到
/proc/sys/net/ipv6/conf/all/disable_ipv6
就可以關掉整個IPv6的支援。
可以填到
/usr/etc/rcS裡面寫入
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
其它方式可以參考
Linux 下關閉支援 IPv6 提升效能