Managing Linux Shell Commands and Accessing Help Resources
Toggling and Managing Internal Commands
Internal shell commands can be disabled or enabled dynamical. Use enable -n to turn off a built-in and enable to restore it.
[root@localhost opt]# enable -n cd
[root@localhost opt]# cd /mnt/
[root@localhost opt]#
After disabling cd, the command no longer functions, and the prompt remains in the current directory.
Working with the Command Hash Table
The shell maintains a hash table to speed up external command lookups. Entries can be removed individually or cleared entirely.
- Remove a single entry:
hash -d <command> - Clear the entire table:
hash -r
[root@localhost mnt]# hash
hits command
1 /usr/bin/mv
2 /usr/bin/ls
6 /usr/bin/cd
[root@localhost mnt]# hash -d ls
[root@localhost mnt]# hash
hits command
1 /usr/bin/mv
6 /usr/bin/cd
If a hashed binary is moved to a different location, the shell will still reference the old path. Clearing the hash entry allows the shell to locate the new path.
[root@localhost mnt]# mv /usr/bin/ls /usr/local/bin/
[root@localhost mnt]# ls
-bash: /usr/bin/ls: No such file or directory
[root@localhost mnt]# hash -r
[root@localhost mnt]# ls
Desktop Documents Downloads
Linux Command Structure
A typical command line consists of three components:
- Command word – the executable or built-in name.
- Options – modifiers that adjust behavior. Short options use a single hyphen (
-l), while long options use two (--all). - Arguments – targets such as files, directories, or users.
# Long format listing
ls -l
# Human-readable sizes
ls -lh
# Multiple commands separated by semicolons
cd /var/log; ls -lt
Options such as -a, -b, -c can usually be combined into -abc, though certain tools enforce order when options require their own arguments (e.g., tar -xzvf archive.tar.gz).
Command-Line Editing Shortcuts
Efficient editing is possible with these key combinations:
| Shortcut | Action |
|---|---|
| Tab | Auto-complete command or path; press twice to list possibilities |
Backslash \ |
Escape character or force a line continuation |
| Ctrl + a | Move cursor to the begining of the line |
| Ctrl + e | Move cursor to the end of the line |
| Ctrl + u | Delete from cursor to the start of the line |
| Ctrl + k | Delete from cursor to the end of the line |
| Ctrl + w | Delete the word before the cursor |
| Alt + d | Delete the word after the cursor |
| Ctrl + l | Clear the screen |
| Ctrl + c | Abort the current input or running command |
| Ctrl + s / Ctrl + q | Freeze / unfreeze terminal output |
| Up/Down arrows | Navigate through command history |
Obtaining Command Help
Internal Command Help
Use help to display usage information for shell built-ins.
[root@localhost ~]# help echo
echo: echo [-neE] [arg ...]
Write arguments to the standard output.
Examples of echo options:
# Suppress trailing newline
echo -n "Processing"
# Interpret backslash escapes
echo -e "Line1\nLine2\nLine3"
# Tab characters
echo -e "Col1\tCol2\tCol3"
# Remove previous character with backspace
echo -e "Error\b\b\bFix"
External Command Help
Most external commands support --help for a quick summary.
ls --help
useradd --help