Shell Commands

Shell Commands

Shell Commands: A Comprehensive Guide

Shell commands are the fundamental building blocks for interacting with the operating system in the command-line interface (CLI). They enable users to perform tasks such as file manipulation, process management, networking, and system configuration.

Categories of Shell Commands

  1. File and Directory Commands
  2. Process Management Commands
  3. Networking Commands
  4. System Information Commands
  5. Disk Usage and Storage Commands
  6. Text Processing Commands
  7. User Management Commands
  8. Miscellaneous Commands

1. File and Directory Commands

CommandDescription
lsLists files and directories
cdChanges the current directory
pwdPrints the current working directory
mkdirCreates a new directory
rmdirRemoves an empty directory
touchCreates an empty file
cpCopies files or directories
mvMoves or renames files or directories
rmDeletes files or directories
findSearches for files in a directory tree

Examples:

  • List all files, including hidden ones:
    ls -a
  • Create a new directory:
    mkdir new_folder

2. Process Management Commands

CommandDescription
psDisplays information about running processes
topShows a real-time view of system processes
killTerminates a process by its PID
jobsLists background jobs
bgResumes a job in the background
fgBrings a job to the foreground
killallKills processes by name

Examples:

  • Kill a process with a specific PID:
    kill 1234
  • Show all processes:
    ps aux

3. Networking Commands

CommandDescription
pingChecks connectivity to a host
ifconfigDisplays network interface information
curlTransfers data from or to a server
wgetDownloads files from the web
netstatDisplays network connections
sshConnects to a remote server securely

Examples:

  • Ping a server to test connectivity:
    ping google.com
  • Download a file from the web:
    wget http://example.com/file.zip

4. System Information Commands

CommandDescription
unameDisplays system information
uptimeShows how long the system has been running
whoamiPrints the current user
hostnameDisplays the system's hostname
dfShows disk space usage
freeDisplays memory usage

Examples:

  • Show kernel version:
    uname -r
  • Check memory usage:
    free -h

5. Disk Usage and Storage Commands

CommandDescription
dfDisplays available disk space
duShows disk usage of files and directories
mountMounts a filesystem
umountUnmounts a filesystem

Examples:

  • Display human-readable disk usage:
    df -h
  • Check directory size:
    du -sh /path/to/directory

6. Text Processing Commands

CommandDescription
catDisplays the contents of a file
moreDisplays file content one screen at a time
lessSimilar to more, but allows backward navigation
grepSearches for patterns in text
awkA powerful text processing tool
sedStream editor for filtering and transforming text

Examples:

  • Search for a pattern in a file:
    grep "pattern" file.txt
  • Replace text in a file:
    sed 's/old/new/g' file.txt

7. User Management Commands

CommandDescription
whoShows who is logged in
whoamiDisplays the current user
adduserAdds a new user
passwdChanges a user's password
suSwitches to another user account

Examples:

  • Add a new user:
    sudo adduser username
  • Switch to another user:
    su username

8. Miscellaneous Commands

CommandDescription
echoPrints text to the terminal
dateDisplays the current date and time
clearClears the terminal screen
historyShows the history of commands
aliasCreates shortcuts for commands

Examples:

  • Create an alias:
    alias ll='ls -la'
  • View command history:
    history

Tips for Using Shell Commands

  1. Use Command Options: Most commands have options (-h or --help) that provide detailed usage information.

  2. Combine Commands: Use pipes (|) and redirection (>, >>) to chain commands.

    ls -l | grep "pattern"
  3. Learn Manual Pages: Use man to access detailed documentation for commands.

    man ls

Conclusion

Shell commands are a powerful way to interact with your operating system, automate tasks, and manage resources. By mastering these commands, you can unlock the full potential of your command-line environment.

Let me know if you'd like more details or specific examples!

Souy Soeng

Souy Soeng

Our website teaches and reads PHP, Framework Laravel, and how to download Admin template sample source code free. Thank you for being so supportive!

Github

Post a Comment

CAN FEEDBACK
close