What is the difference between the commands test -e path and test -f path?



A. They are equivalent options with the same behaviour.
B. The -f option tests for a regular file. The -e option tests for an empty file.
C. Both options check the existence of the path. The -f option also confirms that it is a regular file.
D. The -f option tests for a regular file. The -e option tests for an executable file.

題解

「test」指令可以檢查檔案或是比較數值。「-e」參數用來判斷檔案是否存在。「-f」參數用來判斷檔案是否存在且是否為正規檔案(regular file),正規檔案是,檔案類型符號為「-」的檔案,如果是符號連結,則要去判斷最終連結到的檔案。所以答案是選項C。