首頁·終端機命令

type

行程與系統

用法

type [-a] <name>

直接問 shell 某個名稱到底是什麼——別名、函式、內建還是檔案,這正是只看 PATH 的 `which` 看不到的部分。

常用選項

選項含義
-aEvery meaning of the name, in the order the shell would consider them.
-tOne word only: alias, keyword, function, builtin or file.
-PForce a PATH lookup even if the name is also an alias or function (bash).
-fIgnore shell functions.

範例

type -a ls

Reveals the alias first and the /bin/ls binary second.

type -t rm

Prints "file" if nothing is shadowing it, "alias" if something is.

看什麼在跑、什麼在吃機器。先弄清是什麼,再決定殺不殺。

怎麼看

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

常見問題

Q. type 是做什麼的?

直接問 shell 某個名稱到底是什麼——別名、函式、內建還是檔案,這正是只看 PATH 的 `which` 看不到的部分。

Q. 怎麼寫?

type [-a] <name> —— 方括號表示可以省略的部分。

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

這裡列了 4 個,完整列表在 man type。這條命令屬於行程與系統。

相關命令

man 手冊: man type