command ‐ #system #troubleshooting - five4nets/Linux-Knowledgebase GitHub Wiki

🧠 Linux command Built-in Tutorial

The command built-in in Linux is used to run a command while bypassing shell function lookup. It ensures that you're executing the actual binary or built-in command, not a shell alias or function with the same name.


📋 Basic Syntax

command [options] <command_name> [arguments...]
  • <command_name>: The command you want to run.
  • arguments: Arguments passed to the command.
  • options: Modify behavior (e.g., -v, -V, -p).

🔧 Common Options

Option Description
-v Print the command that would be executed
-V Print detailed information about the command
-p Use a default value for PATH, ignoring shell functions and aliases

🧪 Examples

1. Run a command while ignoring shell functions or aliases

command ls

This runs the actual ls binary, even if ls is aliased (e.g., alias ls='ls --color=auto').

2. Check what will be executed

command -v ls

Returns the path to the ls binary, e.g., /bin/ls.

3. Get verbose information about a command

command -V cd

Might return: cd is a shell builtin.

4. Use command to bypass a function

myfunc() { echo "This is a function"; }
command myfunc  # Will fail if no binary named `myfunc` exists

5. Use command with -p to ignore custom PATH

command -p ls

Runs ls using a default PATH, useful in restricted environments.


🧠 Why Use command?

  • To bypass aliases or functions that override standard commands.
  • To ensure consistency in scripts by calling the original command.
  • To debug shell behavior when a command isn't acting as expected.

📚 References


Happy scripting! 🧑‍💻


Let me know if you'd like a version that includes comparisons with `builtin` or `type`!