Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Essential Shell Commands

1. Introduction

This lesson covers essential shell commands that every Linux system administrator should know. Mastering these commands will help you navigate the Linux environment, manage files, and perform system monitoring efficiently.

2. Basic Commands

Note: Commands are case-sensitive in Linux.
  • pwd: Prints the current working directory.
  • cd: Changes the current directory.
  • ls: Lists files and directories.
  • man: Displays the manual for a command.

Examples

pwd
/home/user
cd /var/log
ls -l

3. File Management

  • cp: Copies files or directories.
  • mv: Moves or renames files or directories.
  • rm: Removes files or directories.
  • mkdir: Creates a new directory.
  • rmdir: Removes an empty directory.

Examples

cp file1.txt file2.txt
mv file1.txt /home/user/documents/
rm file2.txt

4. System Monitoring

  • top: Displays running processes and system resource usage.
  • htop: An enhanced version of top with a user-friendly interface.
  • df: Displays disk space usage.
  • free: Displays memory usage.

Examples

top
df -h
free -m

5. Networking

  • ping: Tests connectivity to another host.
  • ifconfig: Displays network interface configuration.
  • netstat: Displays network connections and statistics.
  • curl: Transfers data from or to a server.

Examples

ping google.com
ifconfig
curl http://example.com

6. Best Practices

  • Always back up important data before running destructive commands.
  • Use man to read command manuals before executing unfamiliar commands.
  • Be cautious with sudo as it executes commands with elevated privileges.
  • Use version control for scripts and critical configurations.

7. FAQ

What is a shell?

A shell is a command-line interface that allows users to interact with the operating system by executing commands.

How do I get help with a command?

You can use the man command followed by the command name to access the manual page for that command, e.g., man ls.

What is the difference between rm and rm -r?

The rm command deletes files, while rm -r recursively deletes directories and their contents.