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.
![](https://blogger.googleusercontent.com/img/a/AVvXsEgTGIzkg4E9E5afsNLs11VomUJP1ksAtdnDfwhPKDEARHn2wTA6V-Cspln2wg6vEhGl4Uw4cCmbfoBe3q7d1K6V-ZK4dpi9I4IpjHuZCukRMZ5l3CEiBQfwJhtoJMM1KHWWt29R7zBfjuOfuPw--06Mv8x4Msg8vaFoCaToJrgDBVEPuwVBA1Yk6Yrs=s16000)
Categories of Shell Commands
- File and Directory Commands
- Process Management Commands
- Networking Commands
- System Information Commands
- Disk Usage and Storage Commands
- Text Processing Commands
- User Management Commands
- Miscellaneous Commands
1. File and Directory Commands
Command | Description |
---|
ls | Lists files and directories |
cd | Changes the current directory |
pwd | Prints the current working directory |
mkdir | Creates a new directory |
rmdir | Removes an empty directory |
touch | Creates an empty file |
cp | Copies files or directories |
mv | Moves or renames files or directories |
rm | Deletes files or directories |
find | Searches for files in a directory tree |
Examples:
- List all files, including hidden ones:
- Create a new directory:
2. Process Management Commands
Command | Description |
---|
ps | Displays information about running processes |
top | Shows a real-time view of system processes |
kill | Terminates a process by its PID |
jobs | Lists background jobs |
bg | Resumes a job in the background |
fg | Brings a job to the foreground |
killall | Kills processes by name |
Examples:
- Kill a process with a specific PID:
- Show all processes:
3. Networking Commands
Command | Description |
---|
ping | Checks connectivity to a host |
ifconfig | Displays network interface information |
curl | Transfers data from or to a server |
wget | Downloads files from the web |
netstat | Displays network connections |
ssh | Connects to a remote server securely |
Examples:
- Ping a server to test connectivity:
- Download a file from the web:
4. System Information Commands
Command | Description |
---|
uname | Displays system information |
uptime | Shows how long the system has been running |
whoami | Prints the current user |
hostname | Displays the system's hostname |
df | Shows disk space usage |
free | Displays memory usage |
Examples:
- Show kernel version:
- Check memory usage:
5. Disk Usage and Storage Commands
Command | Description |
---|
df | Displays available disk space |
du | Shows disk usage of files and directories |
mount | Mounts a filesystem |
umount | Unmounts a filesystem |
Examples:
- Display human-readable disk usage:
- Check directory size:
6. Text Processing Commands
Command | Description |
---|
cat | Displays the contents of a file |
more | Displays file content one screen at a time |
less | Similar to more , but allows backward navigation |
grep | Searches for patterns in text |
awk | A powerful text processing tool |
sed | Stream editor for filtering and transforming text |
Examples:
- Search for a pattern in a file:
- Replace text in a file:
7. User Management Commands
Command | Description |
---|
who | Shows who is logged in |
whoami | Displays the current user |
adduser | Adds a new user |
passwd | Changes a user's password |
su | Switches to another user account |
Examples:
- Add a new user:
- Switch to another user:
8. Miscellaneous Commands
Command | Description |
---|
echo | Prints text to the terminal |
date | Displays the current date and time |
clear | Clears the terminal screen |
history | Shows the history of commands |
alias | Creates shortcuts for commands |
Examples:
- Create an alias:
- View command history:
Tips for Using Shell Commands
Use Command Options:
Most commands have options (-h
or --help
) that provide detailed usage information.
Combine Commands:
Use pipes (|
) and redirection (>
, >>
) to chain commands.
Learn Manual Pages:
Use man
to access detailed documentation for commands.
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!