command ‐ #system #troubleshooting - five4nets/Linux-Knowledgebase GitHub Wiki
command
Built-in Tutorial
🧠 Linux 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
.
command
to bypass a function
4. Use myfunc() { echo "This is a function"; }
command myfunc # Will fail if no binary named `myfunc` exists
command
with -p
to ignore custom PATH
5. Use command -p ls
Runs ls
using a default PATH
, useful in restricted environments.
command
?
🧠 Why Use - 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
- GNU Bash Manual:
command
- Linuxize: Bash Builtins
- GeeksforGeeks: command Built-in in Linux
- man7.org: bash(1) Manual
Happy scripting! 🧑💻
Let me know if you'd like a version that includes comparisons with `builtin` or `type`!