Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Managing Linux Shell Commands and Accessing Help Resources

Tech 1

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:

  1. Command word – the executable or built-in name.
  2. Options – modifiers that adjust behavior. Short options use a single hyphen (-l), while long options use two (--all).
  3. 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

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.