π§Ύ 1. Command Syntax in Linux
A typical Linux command follows this structure:
command [options] [arguments]
command: the name of the command/tool to runoptions: start with-or--, modify how the command runsarguments: what the command acts on (e.g., file names, user names)
π§ Example:
ls -l /home/ivanls: command-l: option to list in long format/home/ivan: argument (the directory to list)
π 2. Built-in vs. External Commands
β Built-in Commands
- These are part of the shell itself (like
bash) - Executed without launching a separate program
- Typically used for basic tasks like changing directories or setting variables
Examples:
cdechoexitaliasexport
Faster and always available within the shell.
β External Commands
- These are separate executable programs stored in files
- Located in directories like
/bin,/usr/bin,/usr/local/bin, etc. - Executing them spawns a new process
Examples:
lscatgrepnanoping
Stored as binaries or scripts outside the shell.
π΅οΈ 3. How to Identify Built-in vs. External Commands
π Use the type command
type <command>Examples:
type cd
# Output: cd is a shell builtin
type ls
# Output: ls is /bin/lsIf it says βbuiltin,β itβs built into the shell. If it shows a path (
/bin/ls), itβs an external command.
π 4. Finding the Location of a Command
π Use the which command
which <command>This shows the path to the executable used when you run a command.
Example:
which ls
# Output: /bin/ls
which nano
# Output: /usr/bin/nanoOnly works for external commands (does not detect built-ins).
π§ Bonus: Alternative β command -v
command -v <command>Example:
command -v cd
# Output: cd
command -v ls
# Output: /bin/lsWorks for both built-in and external commands, similar to
type.
π§ͺ Summary Table
| Goal | Command | Example |
|---|---|---|
| Check if a command is built-in or external | type | type echo β built-in |
| Find exact file path of external command | which | which grep β /bin/grep |
| Portable way to find command | command -v | command -v ls β /bin/ls |