Finding Commands (which, type)
Sometimes you need to know where a command is located or what type of command it is. which and type help you find this information.
which - Find Command Location
which shows the path to an executable:
which ls
which python
which bash
type - Command Classification
type tells you what kind of command something is:
type cd
type ls
type echo
Types of Commands
| Type | Description | Example |
|---|---|---|
| Built-in | Part of the shell | cd, echo, pwd |
| Executable | Binary program | ls, grep, cat |
| Alias | Shortcut | ll -> ls -la |
| Function | Shell function | Custom functions |
| Keyword | Shell keyword | if, for, while |
Why Does This Matter?
Understanding command types helps you:
- Debug issues with commands
- Know where programs are installed
- Understand shell behavior
- Write better scripts
which vs type
| Feature | which | type |
|---|---|---|
| Shows path | Yes | Sometimes |
| Shows type | No | Yes |
| Built-ins | Not found | Found |
| Aliases | Not found | Found |
Notice: which cd might say "not found" because cd is a shell built-in, not an executable.
Exercise: Find Command Type
Determine what type of command 'cd' is:
type Options
type -t ls # Just the type word
type -a echo # All locations
type -p ls # Path only (like which)
Finding Multiple Commands
which ls cat grep # Multiple at once
type ls cat grep # Types of multiple commands
Checking if Command Exists
Useful in scripts:
# Check if command exists
if type python3 &> /dev/null; then
echo "Python 3 is installed"
fi
whereis - Extended Search
whereis finds binaries, source, and man pages:
whereis ls
# ls: /bin/ls /usr/share/man/man1/ls.1.gz
Real-World Uses
Find Python Version
which python
which python3
Check Available Shells
which bash zsh fish
Verify Installation
which node # Is Node.js installed?
which docker # Is Docker installed?
Key Takeaways
whichfinds the location of executablestypeshows what kind of command something is- Built-in commands won't show in
which - Use
type -ato see all definitions - Essential for debugging and scripting
التالي · الدرس 23 من 40
Output Redirection
قراءة 2 دقيقة
أنهيت 22 من 40 درسًا

اسأل Byte عن هذا الدرس
محادثة خاصة حول هذا الدرس. قرأ Byte الدرس كاملًا، ويجيب خلال ثوانٍ، ويُظهر القسم الذي تأتي منه كل إجابة. يمكنك السؤال بأي لغة.
الأسئلة والأجوبة
أسئلة عامة حول هذا الدرس. يجيب AI Tutor فورًا بلغتك، ويراجع فريق FreeAcademy الإجابات، ويمكن لكل المتعلمين قراءتها.

