關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • Linux Memory Management

    Posted on January 28th, 2009 Sam Tang No comments

    好文推介,介紹 Linux 的記憶體管理:

    Memory management is the heart of operating systems; it is crucial for both programming and system administration. In the next few posts I’ll cover memory with an eye towards practical aspects, but without shying away from internals. While the concepts are generic, examples are mostly from Linux and Windows on 32-bit x86. This first post describes how programs are laid out in memory. Each process in a multi-tasking OS runs in its own memory sandbox. This sandbox is the virtual address space, which in 32-bit mode is always a 4GB block of memory addresses.

    Anatomy of a Program in Memory


  • 重新設定 MySQL root 密碼

    Posted on January 26th, 2009 Sam Tang No comments

    如果忘記了 MySQL 的 root 密碼,可以透過以下方法重新設定:

    1. 停止 MySQL server。

    # /etc/init.d/mysql stop

    2. 啟動 MySQL server,並加上 –skip-grant-tables 參數,便可以略過輸入密碼的過程:

    # mysqld_safe –skip-grant-tables &

    3. 用 root 連接到 MySQL server,輸入:

    mysql -u root

    4. 進入 MySQL server 後,輸入以下幾行 SQL 語句:
    mysql> use mysql;
    mysql> update user set password=PASSWORD("newpass") where User=’root’;
    mysql> flush privileges;
    mysql> quit

    5. 重新啟動 MySQL 即可。


  • “==” 及 “===” 在 PHP 的分別

    Posted on January 23rd, 2009 Sam Tang 1 comment

    在 PHP 裡面,兩個比較運算式 "==" 及 "===" 的分別是,"==" 用作檢查變數的值是否相同;而 "==" 則會檢查變數的值及資料型態。

    "==":

    PHP:
    1. <?php
    2. $str_var = "123";
    3. if($str_var == 123){
    4.     echo "Yes";
    5. }else{
    6.     echo "No";
    7. }
    8. ?>

    以上程式碼執行結果會輸入 "Yes",因為變數 $str_var 及整數 123 是相同的值,但如果改用 "===" 便會有不同的結果:

    "==="

    PHP:
    1. <?php
    2. $str_var = "123";
    3. if($str_var === 123){
    4.     echo "Yes";
    5. }else{
    6.     echo "No";
    7. }
    8. ?>

    以上程式碼會輸入 "No",因為雖然 $str_var 及 123 的值是相同,但兩者的資料型態不同。 (用引號包著的 "123" 是字串;而沒有引號的 123 則是整數)

    但如果將程式碼改成以下這樣,便會輸出 "Yes"

    PHP:
    1. <?php
    2. $str_var = 123;
    3. if($str_var === 123){
    4.     echo "Yes";
    5. }else{
    6.     echo "No";
    7. }
    8. ?>


  • 透過 Linux 恢復 Windows 系統管理員密碼

    Posted on January 22nd, 2009 Sam Tang 1 comment

    如果忘記了 Windows 的 administrator 密碼,可以透過 Linux 的 Live CD 進行恢復,而這裡會使用 Ubuntu 作為例子:

    1. 使用 Ubuntu Live CD 開機

    2. 安裝一個名為 "chntpw" 的程式

    $ sudo apt-get install chntpw

    3. 安裝 "chntpw" 後,便要將 Windows 的 NTFS 分割區掛載。

    4. 進入 Windows 分割區下的 system32/config 目錄,然後輸入:

    $ sudo chntpw SAM

    5. 出現了一堆訊息後,系統會提示 reset 密碼,如果想設成空密碼,可以輸入星號 *,重新開機後便可以進入 Windows。


  • Ubuntu 8.10 安裝 Java

    Posted on January 21st, 2009 Sam Tang No comments

    安裝 Ubuntu 後系統預設沒有安裝 Java,以下是安裝方法:

    $ sudo apt-get install sun-java6-jre sun-java6-plugin

    安裝後再設定 Firefox 成支援 java

    $ sudo ln -s /usr/lib/jvm/java-6-sun-1.6.0.10/jre/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/firefox/plugins/

  • 只針對檔案或目錄 chmod

    Posted on January 21st, 2009 Sam Tang 1 comment

    在 Unix Like 環境可以用 chmod 改變檔案或目錄的權限,以下方法可以只針對檔案或目錄 chmod:

    1. 在當前目錄下遁迴 chmod 檔案:
    find . -type f -exec chmod 0600 {} \;

    2. 在當前目錄下遁迴 chmod 目錄:
    find . -type d -exec chmod 0755 {} \;


  • 改變需要勇氣,投進 Linux 桌面懷抱

    Posted on January 20th, 2009 Sam Tang No comments

    由剛開始用電腦開始已經使用 Windows,那時好像是 Windows 3.x 的版本,至今已經十幾年。雖然這段時間也有使用 Ubuntu 及 EeePC,但主要的作業系統還是 Windows,原因可能是因為沒有改變的勇氣。

    一般上我的工作也是寫程式及管理主機,全都可以在 Linux 下完成,上個月買了一個新硬碟來灌 Ubuntu,將在 Windows 下面的資料複製到新硬碟後,直接將裝有 Windows 的硬碟拆除,免得自己想開 Windows。 但裝有 Windows 的硬碟也要留著,只怕在什麼時候真的要開個 Windows,手邊又沒有的話就麻煩了。

    到目前的情況是進展良好,證實我的工作是全部在 Linux 下完成,只是自己不願作出改變。


  • Ubuntu 9.04 將會支援 Ext4 filesystem

    Posted on January 14th, 2009 Sam Tang 1 comment

    新一代的 Ext 檔案系統 Ext4,而 Ubuntu 的下一個版本 9.04 也會支援。而 Ext4 在上個月發佈的 Linux kernel 2.6.28 正式被納入。Ext4 的設計提供更佳的效能及可靠度,而檔案系統可支援的容量相應增加到 1 exabyte,及縮短 fsck 所須的時間。

    Linux 硬件網站 Phoronix 公佈了基於 Ext4 的效能測試報告,最突出的是 IOzone 測試對大型檔案的寫入效能,結果顯示效能比 XFS, JFS, ReiserFs 及 Ext3 都大幅領先。


  • Linux 系統管理員輕鬆工作技巧

    Posted on January 13th, 2009 Sam Tang No comments

    列出 10 個系統管理員的小技巧:

    There are thousands of tricks you can learn from someone's who's an expert at the command line. The best systems administrators are set apart by their efficiency. And if an efficient systems administrator can do a task in 10 minutes that would take another mortal two hours to complete, then the efficient systems administrator should be rewarded (paid more) because the company is saving time, and time is money, right?

    The trick is to prove your efficiency to management. While I won't attempt to cover that trick in this article, I will give you 10 essential gems from the lazy admin's bag of tricks. These tips will save you time -- and even if you don't get paid more money to be more efficient, you'll at least have more time to play Halo.

    Lazy Linux: 10 essential tricks for admins