首頁·終端機命令

ls

檔案與目錄

用法

ls -la [path]

列出目錄裡有什麼;以點開頭的名字要加 -a 才會顯示。

常用選項

選項含義
-lOne line per entry with mode, owner, size and time
-aInclude names that begin with a dot
-hSizes as 4.0K instead of 4096, together with -l
-tSort by modification time, newest first
-rReverse whatever order is in effect
-SSort by size, largest first
-RWalk into subdirectories
-dShow the directory itself instead of its contents

範例

ls -lh

Long listing with readable sizes.

ls -lat

Newest first, hidden files included.

ls -d */

Only the directories in this folder.

搬移、刪除和尋找。有些命令不會再問一次,所以順手加 -i 是在救自己。

怎麼看

  • 方括號 [ ] 表示這部分可以不寫。
  • 省略號 … 表示可以寫多個。
  • 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。

常見問題

Q. ls 是做什麼的?

列出目錄裡有什麼;以點開頭的名字要加 -a 才會顯示。

Q. 怎麼寫?

ls -la [path] —— 方括號表示可以省略的部分。

Q. 值得記的選項有幾個?

這裡列了 8 個,完整列表在 man ls。這條命令屬於檔案與目錄。

相關命令

man 手冊: man ls