الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

type

Show what a command name really is: an alias, a shell keyword, a function, a built-in or a program file.

المستوى
امتحان RHCSA
المجموعة
الطرفية والمساعدة
يحتاج root
لا
الحزمة
bash (built-in)

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

type is built into Bash. It answers the question "if I type this name, what will run?" It knows about aliases, functions and shell built-ins, which a tool like which cannot see.

Use it when a command does something you did not expect: maybe an alias with the same name hides the real program, or a script found a different program in $PATH.

The help text is in Bash itself: help type.

طريقة الكتابة

type [-afptP] NAME [NAME ...]

الخيارات 5

الأكثر استخدامًا

-t
Print only one word: alias, keyword, function, builtin, file, or nothing if not found.
-a
Show every place where NAME is found: alias, function, built-in and every file in $PATH.
-p
Print the path of the file that would run, but only when NAME is a file (nothing for an alias or built-in).
-P
Search $PATH for a file, even when NAME is also an alias, function or built-in.
-f
Do not look for shell functions.

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Find out what a name is

    type ls
    ls is aliased to `ls --color=auto'

    On RHEL, ls is an alias that adds colors.

  2. 2Show every match, in the order Bash uses them

    type -a ls
    ls is aliased to `ls --color=auto'
    ls is /usr/bin/ls

    The first line wins. The program file is only used when there is no alias.

  3. 3Get one word for a script

    type -t cd
    builtin

    Possible answers: alias, keyword, function, builtin, file.

  4. 4Check if a command is installed before you use it

    if type -P jq >/dev/null; then echo "jq found"; else echo "please install jq"; fi

    type -P returns an error code when the program is not in $PATH. Good for install checks.

  5. 5See if a name is a shell keyword

    type if
    if is a shell keyword

    Keywords like if, for and [[ are part of the Bash language.

  6. 6Find the real program behind an alias

    type -P grep
    /usr/bin/grep

    Shows the file even though grep is also an alias.

  7. 7Look at a shell function

    type my_backup

    If my_backup is a function, Bash prints its full code. Useful to debug functions from ~/.bashrc.

  8. 8Check several names at once

    type -t python3 docker podman kubectl
    file
    file

    Names that are not found print nothing in -t mode. Here only two of four are installed.

  9. 9Find out why an old version of a tool runs

    type -a terraform
    terraform is /usr/local/bin/terraform
    terraform is /usr/bin/terraform

    Two copies are installed. The first one in $PATH wins; remove or rename the old one.

  10. 10Detect a hidden alias in a security review

    type sudo

    If an attacker added alias sudo=... to a .bashrc, type shows it. Real sudo is /usr/bin/sudo.

  11. 11Use type in a script to require a tool

    type -P rsync >/dev/null || { echo "rsync is missing" >&2; exit 1; }

    Stops the script early with a clear message.

انتبه

  • type is a Bash built-in. It does not exist as a program file, so sudo type does not work.
  • which does not know functions and built-ins (it only searches files), so the two can give different answers.

نصائح للحفظ

  • type = what runs, type -a = everything that could run, type -P = only the file.
  • Remember the order Bash uses: alias → keyword → function → built-in → file in $PATH.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man type