2017年6月30日 星期五

Ubuntu 16.04設定DNS

以前手動設定DNS是在把DNS server加在 /etc/resolv.conf 這個檔案裡面,但在Ubuntu 16.04(Xenial Xerus)卻不是直接編輯/etc/resolv.conf 這個檔案,因為這個檔案會被 一個叫做 resolvconf 的程式所控制。以下提供兩種解法:

解法1:

現在則是直接將dns-nameserver加入到 /etc/network/interfaces 裡面
在每一張interface裡面,分別加入下面的設定:
  • dns-nameserver 8.8.8.8 8.8.4.4
這樣就會加入兩個dns servers了

2017年6月29日 星期四

Ubuntu 16.04僅更新安全性套件

Ubuntu登入時,都會通知是否有套件需要更新、其中有幾個屬於安全性更新。若想要知道究竟哪些套件屬於安全性更新,下指令:
  • apt-get -s dist-upgrade |grep "^Inst" |grep -i security 
若要安裝這些安全性更新套件,則是以root的身份下指令:
  • apt-get -s dist-upgrade | grep "^Inst" | grep -i security | awk -F " " {'print $2'} | xargs apt-get --yes install

2017年6月28日 星期三

Mac開啓SSD的TRIM

在Mac OS X 10.9.5 (Mavericks) 上面想用terminal直接開啟非Apple原廠SSD的TRIM功能:
  1. 備份原來的driver
    sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage-backup
  2. 修改driver的內容
    sudo perl -pi -e 's|(^\x00{1,20})[^\x00]{9}(\x00{1,20}\x54)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
  3. 更新系統的快取、讓系統用新的driver
    1. sudo kextcache -system-prelinked-kernel
    2. sudo kextcache -system-caches
    3. sudo touch /System/Library/Extensions/
  4. 重新開機後,用指令確認有沒有TRIM support
    system_profiler SPSerialATADataType | grep 'TRIM'

2017年6月26日 星期一

GNU time:計算程式執行時間

UNIX-like系統上(像是Linux或BSD或Mac),用來計算執行程式的時間的指令是time,或叫做GNU time。使用方法:
  • time command
這個指令會回傳三個時間,參考What do 'real', 'user' and 'sys' mean in the output of time(1)?的說明:
  • real:實際上從開始執行指令到結束指令花的時間,包含CPU處理的時間、系統做I/O的時間等。一般來說我們說跑多久指的就是這個時間
  • user:CPU花在跑這個程式的時間。"The amount of CPU time spent in user-mode code (outside the kernel)"
  • sys:因為跑這支程式系統核心使用的CPU時間。"The amount of CPU time spent in the kernel within the process."
所以說 User+Sys 就是整個程式在CPU裡面跑的時間。由於現在多核心的出現,所以有時候會出現CPU跑的時間比整個程式執行的時間還長的情況。