Dec 24th, 2013 by samlin35
2013年12月24日 星期二
configure 時缺少 ncurses
Dec 24th, 2013 by samlin35
2013年10月1日 星期二
sh infinite loop
2013年5月31日 星期五
顯示檔案中第幾行的內容
顯示檔案中第幾行的內容
May 31th, 2013 by Chuan-Hsien LinLast Modified on May 31th, 2013
有同事問我怎麼在 Linux 中顯示出檔案中的某一行,像這樣的功能使用 sed 來做是非常簡單地就可以辦到了,由以下的簡單的範例來說明用法。
[sam@sever ~]$ cat testfile
12345
abcdefghijkl
678901234
mnopqrstuvwxyz
[sam@sever ~]$ sed -n '2p' testfile
abcdefghijkl
在 testfile 這個檔案裡有四行文字,接著使用 sed -n '2p' testfile 可以將第二行的內容顯示出來。如果要顯示別行,就將 2 改成該行號即可。
2013年1月11日 星期五
Fedora 17 更改 host name
Jan 11th, 2013 by samlin35
Environment:
OS: Fedora 17 64bit
ip address: 192.168.205.116 (by DHCP)
netmask: 255.255.0.0
hostname: testpc1
假設我們要將原 host name 是 testpc1 設定成 testpc2,步驟如下:
1. 使用 root 帳號。
$ su
2. 編輯 /etc/hosts,將 host name 是 testpc1 的字眼都改成 testpc2。我的 /etc/hosts 如下:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 testpc2
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 testpc2
3. 編輯 /etc/sysconfig/network,將裡頭的 HOSTNAME 指定成你要的 hostname。我的 /etc/sysconfig/network 如下:
NETWORKING=yes
HOSTNAME=testpc2
4. 使用 hostname 指令設定一次。
# hostname testpc2
5. 重新登入後,就會看到提示符號有正常顯示,使用 hostname 指令查看,也可看到已使用新的 hostname 了。
[sam@testpc2 ~]$
# hostname
testpc2
Fedora 17 切換 runlevel
Jan 11th, 2013 by samlin35
如果要讓 Fedora 17 開機後就跑在文字模式 (Text Mode) 下的話,執行:
# ln -sf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target
如果要跑在圖形模式 (Graphical Mode) 的話,執行:
# ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
以上動作記得使用 root 帳號來執行,不然會出現 Permission denied 的錯誤訊息。
另外,從 Fedora Documentation 可以知道 Fedora 現在定義的 Runlevel 如下,並且 level 2, level 4 已不再使用。
0 — Halt
1 — Single-user text mode
2 — Not used (user-definable)
3 — Full multi-user text mode
4 — Not used (user-definable)
5 — Full multi-user graphical mode (with an X-based login screen)
6 — Reboot
參考資料:
2009年11月19日 星期四
好閃的便當
2009年11月17日 星期二
白目買家
我最近新買了台傻瓜相機 Canon S90,所以想把手上的 Canon SX200 賣掉。
話說昨晚接到一通電話讓我喜出望外,是打來要跟我買相機的,於是昨晚就認真的找配件出來整理了一翻,一一的盤點無誤,內心有點忐忑不安,又幾分期待。
然後今天相約在某加樂福,等我們會面後,我拿出包裝來給買家看,結果他臉色一沉,原來他想買的是 Canon SX20,不是我這台 SX200,然後他一直說是我在二手買賣區貼文寫錯,我當然也不相信,因為我都用複製貼上的,已經貼過好多次了,怎可能手殘貼錯呢!明明就是他白目看錯吧!後來買家勉強把玩了一下我的相機,不過我知道他是不會買的,於是我跟他說,『如果不是你要的, 也沒關係啦。』想說也差不多該閃人了,買賣不成仁義在,也不用口出惡言罵他幾句白目!
結果我想說收拾一下要閃了,時間還早,還可以回公司加班趕東西,結果他好意的說要請我喝飲料,想說不喝白不喝,於是我們就在美食街坐下來聊天,聊了很多攝影方面的東西,其實我是還蠻想離開的,不過喝人家請的飲料,就陪他聊幾句也罷!大概聊了約半小時飲料都喝完後,我們就各自解散了,結束了這場鬧劇。
今天真的是遇到白目的買家了。
2009年7月15日 星期三
Linux 上使用 NTFS
July 14th, 2009 by Chuan-Hsien Lin
Last Modified on July 14th, 2009
先來說說我的環境,我是使用一塊 ARM 相容的開發板,Linux Kernel 採用 2.6.22.18。
可以看的出來,硬碟中有個 NTFS 的 Partition。
-sh-3.2# fdisk -l Disk /dev/sda: 82.3 GB, 82348277760 bytes 255 heads, 63 sectors/track, 10011 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 1 123 987966 7 HPFS/NTFS
尚未在 Linux Kernel 勾選支援 NTFS,直接去掛載 NTFS Partition 會出現問題。
-sh-3.2# mount -t ntfs /dev/sda1 /mnt/hd1
mount: mounting /dev/sda1 on /mnt/hd1 failed: No such device
由於 Linux Kernel 本身就可支援 NTFS 了,所以我們 make menuconfig 來設定支援 NTFS,
<*> NTFS file system support
[*] NTFS write support
再來執行一次 mount,成功的掛載了,
-sh-3.2# mount -t ntfs /dev/sda1 /mnt/hd1
NTFS volume version 3.1.-sh-3.2# mount
rootfs on / type rootfs (rw)
/dev/root on / type nfs (rw,vers=2,rsize=4096,wsize=4096,hard,nolock,proto=udp,timeo=11,retrans=2,sec=sys,addr=192.168.51.15)
proc on /proc type proc (rw)
devpts on /dev/pts type devpts (rw)
/dev/sda1 on /mnt/hd1 type ntfs (rw,uid=0,gid=0,fmask=0177,dmask=077,nls=iso8859-1,errors=continue,mft_zone_multiplier=1)
雖然掛載後,但卻是只能讀不能寫入,
-sh-3.2# touch /mnt/hd1/testfile
touch: /mnt/hd1/testfile: Permission denied
如果想要可以讀寫 NTFS,得使用別的方式,目前比較流行的是使用 ntfs-3g 這個套件。
安裝好 ntfs-3g 去執行的話,會發現少了 fuse 套件,
-sh-3.2# ./ntfs-3g /dev/sda1 /mnt/hd1
modprobe: cannot parse modules.dep
ntfs-3g-mount: fuse device is missing, try 'modprobe fuse' as root
由於後來的 Linux Kernel 裡面都內建了 FUSE 了,所以在 make menuconfig 時指定,
<*> Filesystem in Userspace support
然後重新編譯 Linux Kernel 後,進到 target board 後再來 mount 一次就可成功了,
./ntfs-3g /dev/sda1 /mnt/hd1
如果要可以格式化 NTFS 的 partition 的話,得再裝另一個套件 nefsprogs, 這套件裡有蠻多針對 NTFS 運作相關的程式,像我就會使用產生出來的 mkntfs 去格式化 NTFS,用 ntfslabel 去寫 label。
相關資源:
ntfs-3g
http://www.ntfs-3g.org/
nefsprogs
http://www.linux-ntfs.org/
NTFS FAQ (中文)
http://www.linux-ntfs.org/doku.php?id=ntfs-zh_tw
2009年7月7日 星期二
學英語好用連結
學英語好用連結
July 6th, 2009 by Chuan-Hsien Lin
Last Modified on July 9th, 2009
Yahoo!奇摩新聞 - 英語新聞
http://tw.digest.news.yahoo.com/
台灣英語網
http://www.english.com.tw/
english-test.net
http://www.english-test.net/
線上英漢字典與翻譯 - n詞酷
http://www.nciku.com.tw/
不只有字典查詢功能,還有豐富的情境會話。可建立自己的單字本,進行測驗。
Yahoo!奇摩字典
http://tw.dictionary.yahoo.com/
Google 字典
http://www.google.com.tw/dictionary
Longman English Dictionary Online
http://www.ldoceonline.com/
cdict 線上英漢字典
http://cdict.net/
2009年7月5日 星期日
Linux 好用網站
Linux 好用網站
July 4th, 2009 by Chuan-Hsien Lin
Last Modified on July 6th, 2009
Jserv's blog
http://blog.linux.org.tw/~jserv/
鳥哥的 Linux 私房菜
http://linux.vbird.org/
IBM developerWorks 的 Linux 專區
http://www.ibm.com/developerworks/linux/
http://www.ibm.com/developerworks/cn/linux/ (中國)
The Linux Kernel Archives
http://www.kernel.org/
要下載 Linux Kernel 的 Source code 就是這。