關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • "Argument list too long" 問題

    Posted on March 18th, 2006 Sam Tang 2 comments

    昨天升級 Email Server 的 SquirrelMail,當我將舊版本 SquirrelMail 下面的 data 目錄資料複製到新版本時,出現了 "Argument list too long",然後找了找,發現原來在 Linux 下用 cp, mv, rm 這些指令時,如果輸入的檔案數目太多會出現 "Argument list too long" 錯誤。

    因為在 Linux Kernel 內對 command-line arguments 限製了記億體的使用,就例如在一個目錄下有很多檔案,如果用 "cp * /home/user/",那便會出現這個問題,以下列出兩個解決辦法:

    1. 分開多個指令執行: 可以將檔案分成幾個指令執行,例如:

    cp [0-9]* /path/to/
    cp [a-l]* /path/to/
    cp [m-z]* /path/to/

    2. 使用 find 指令: 另一個方法是用 find 指令,可以一句便完成:

    find /file_from/* -type f -name '*' -exec cp {} /path/to/. \;

    以上指令會將 /file_from/ 目錄下的所有檔案覆製到 /path/to/ 下面。

    P.S. 如果想修改 kernel 以解決問題,可以開啟在 kernel source 下面的 include/linux/binfmts.h 檔案,在開頭的位置裡面有一行 "#define MAX_ARG_PAGES 32",將 32 改成更大的數值,例如 64 或 128,然後重新編譯 kernel。


     

    2 responses to “"Argument list too long" 問題”

    1. [...] “Argument list too long” 問題 (tags: Tech OS UNIX Tips) [...]

    2. [...] 參考網站: 1.Real-Blog – Argument list too long 問題 2.4wei-diary – Argument list too long   [...]

    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word