🧾 1. Command Syntax in Linux

A typical Linux command follows this structure:

command [options] [arguments]
  • command: the name of the command/tool to run
  • options: start with - or --, modify how the command runs
  • arguments: what the command acts on (e.g., file names, user names)

πŸ”§ Example:

ls -l /home/ivan
  • ls: 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:

  • cd
  • echo
  • exit
  • alias
  • export

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:

  • ls
  • cat
  • grep
  • nano
  • ping

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/ls

If 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/nano

Only 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/ls

Works for both built-in and external commands, similar to type.


πŸ§ͺ Summary Table

GoalCommandExample
Check if a command is built-in or externaltypetype echo β†’ built-in
Find exact file path of external commandwhichwhich grep β†’ /bin/grep
Portable way to find commandcommand -vcommand -v ls β†’ /bin/ls