In the domain of Cybersecurity and Linux System Administration, understanding the fundamental Linux commands is pivotal for both system management and security operations. Linux commands are the building blocks for interacting with the operating system, and their proficiency is essential for effective system administration and cybersecurity tasks. Below, we consider some of the most commonly used Linux commands, providing a detailed explanation of their purposes, functionalities, and examples to illustrate their practical applications.
1. `ls` – List Directory Contents
The `ls` command is used to list the contents of a directory. It is one of the most frequently used commands as it helps users and administrators to see the files and directories within a specified directory.
Usage:
{{EJS76}}Common Options:
- `-l`: Long listing format. Provides detailed information about files and directories. - `-a`: Lists all files, including hidden files (those starting with a dot `.`). - `-h`: Human-readable format, making file sizes easier to read.Example:
bash ls -lah /var/logThis command lists all files in the `/var/log` directory in a long listing format, including hidden files, with human-readable file sizes.
2. `cd` - Change Directory
The `cd` command is used to change the current working directory. It is essential for navigating the file system.
Usage:
{{EJS78}}Example:
bash cd /etcThis command changes the current directory to `/etc`.
3. `pwd` - Print Working Directory
The `pwd` command prints the full path of the current working directory. It is useful for confirming the directory you are currently in.
Usage:
{{EJS80}}Example:
bash pwdIf the current directory is `/home/user`, the command will output `/home/user`.
4. `cp` - Copy Files and Directories
The `cp` command is used to copy files and directories from one location to another.
Usage:
{{EJS82}}Common Options:
- `-r`: Recursively copy directories and their contents. - `-i`: Prompt before overwrite. - `-v`: Verbose mode, showing files being copied.Example:
bash cp -r /home/user/docs /backup/docsThis command copies the `docs` directory from `/home/user` to `/backup`.
5. `mv` - Move or Rename Files and Directories
The `mv` command moves files and directories from one location to another. It is also used to rename files and directories.
Usage:
{{EJS84}}Example:
bash mv /home/user/file.txt /home/user/docs/file.txtThis command moves `file.txt` from `/home/user` to `/home/user/docs`.
6. `rm` - Remove Files and Directories
The `rm` command is used to remove files and directories.
Usage:
{{EJS86}}Common Options:
- `-r`: Recursively remove directories and their contents. - `-i`: Prompt before each removal. - `-f`: Force removal without prompt.Example:
bash rm -rf /home/user/tempThis command forcefully removes the `temp` directory and its contents.
7. `chmod` - Change File Modes or Access Permissions
The `chmod` command is used to change the access permissions of files and directories.
Usage:
{{EJS88}}Example:
bash chmod 755 /home/user/script.shThis command sets the permissions of `script.sh` to `755` (rwxr-xr-x).
8. `chown` - Change File Owner and Group
The `chown` command changes the ownership of a file or directory.
Usage:
{{EJS90}}Example:
bash chown root:root /var/www/htmlThis command changes the owner and group of `/var/www/html` to `root`.
9. `ps` - Report a Snapshot of Current Processes
The `ps` command displays information about the currently running processes.
Usage:
{{EJS92}}Common Options:
- `-e`: Display all processes. - `-f`: Full-format listing.Example:
bash ps -efThis command displays a full-format listing of all running processes.
10. `top` - Display Linux Tasks
The `top` command provides a dynamic, real-time view of the system's running processes.
Usage:
{{EJS94}}Example:
bash topRunning this command will show a real-time display of system processes, CPU usage, memory usage, and more.
11. `kill` - Terminate a Process
The `kill` command is used to send a signal to a process, usually to terminate it.
Usage:
{{EJS96}}Example:
bash kill -9 1234This command forcefully terminates the process with PID 1234.
12. `df` - Report File System Disk Space Usage
The `df` command displays the amount of disk space used and available on file systems.
Usage:
{{EJS98}}Common Options:
- `-h`: Human-readable format. - `-T`: Display file system type.Example:
bash df -hThis command shows disk space usage in a human-readable format.
13. `du` - Estimate File Space Usage
The `du` command estimates file space usage.
Usage:
{{EJS100}}Common Options:
- `-h`: Human-readable format. - `-s`: Summarize total size.Example:
bash du -sh /home/userThis command shows the total size of the `/home/user` directory in a human-readable format.
14. `grep` - Print Lines Matching a Pattern
The `grep` command searches for patterns within files and outputs the matching lines.
Usage:
{{EJS102}}Common Options:
- `-i`: Ignore case. - `-r`: Recursively search directories. - `-v`: Invert match, showing lines that do not match the pattern.Example:
bash grep -r "error" /var/logThis command searches for the term "error" in all files within `/var/log`.
15. `find` - Search for Files in a Directory Hierarchy
The `find` command searches for files and directories within a directory hierarchy based on specified criteria.
Usage:
{{EJS104}}Common Expressions:
- `-name`: Search by name. - `-type`: Search by type (e.g., `f` for files, `d` for directories). - `-mtime`: Search by modification time.Example:
bash find /home/user -name "*.txt"This command finds all `.txt` files within `/home/user`.
16. `tar` - Archive Files
The `tar` command is used to create, extract, and manipulate tar archives.
Usage:
{{EJS106}}Common Options:
- `-c`: Create a new archive. - `-x`: Extract files from an archive. - `-v`: Verbose mode. - `-f`: Specify the archive file.Example:
bash tar -cvf backup.tar /home/user/docsThis command creates a tar archive named `backup.tar` containing the `docs` directory.
17. `ssh` - Secure Shell
The `ssh` command is used to securely connect to remote systems.
Usage:
{{EJS108}}Common Options:
- `-p`: Specify port. - `-i`: Specify identity file for key-based authentication.Example:
bash ssh -i ~/.ssh/id_rsa user@192.168.1.10This command connects to the remote system at `192.168.1.10` using the specified identity file for authentication.
18. `scp` - Secure Copy
The `scp` command is used to securely copy files between hosts.
Usage:
{{EJS110}}Common Options:
- `-r`: Recursively copy directories. - `-P`: Specify port.Example:
bash scp -P 2222 /home/user/file.txt user@remote:/home/userThis command copies `file.txt` to the remote system on port `2222`.
19. `rsync` - Remote Sync
The `rsync` command is used for fast and versatile file copying and synchronization.
Usage:
{{EJS112}}Common Options:
- `-a`: Archive mode, which preserves permissions, timestamps, and other attributes. - `-v`: Verbose mode. - `-z`: Compress file data during the transfer. - `-P`: Show progress during transfer.Example:
bash rsync -avz /home/user/docs user@remote:/backup/docsThis command synchronizes the `docs` directory to the remote system, preserving attributes and compressing data during the transfer.
20. `crontab` - Schedule Tasks
The `crontab` command is used to schedule tasks to run at specified intervals.
Usage:
{{EJS114}}Common Options:
- `-e`: Edit the crontab file. - `-l`: List the crontab file. - `-r`: Remove the crontab file.Example:
bash crontab -eThis command opens the crontab file for editing, allowing you to schedule tasks.
21. `sudo` - Execute a Command as Another User
The `sudo` command allows a permitted user to execute a command as the superuser or another user.
Usage:
{{EJS116}}Example:
bash sudo apt-get updateThis command runs `apt-get update` with superuser privileges, updating the package list.
22. `apt-get` - APT Package Handling Utility
The `apt-get` command is used to handle packages in Debian-based distributions.
Usage:
{{EJS118}}Common Commands:
- `update`: Update the package list. - `upgrade`: Upgrade all packages. - `install`: Install a package. - `remove`: Remove a package.Example:
bash sudo apt-get install vimThis command installs the `vim` text editor.
23. `yum` - Yellowdog Updater Modified
The `yum` command is used to manage packages in RPM-based distributions.
Usage:
{{EJS120}}Common Commands:
- `update`: Update packages. - `install`: Install a package. - `remove`: Remove a package.Example:
bash sudo yum install httpdThis command installs the Apache HTTP server.
24. `systemctl` - Control the Systemd System and Service Manager
The `systemctl` command is used to examine and control the systemd system and service manager.
Usage:
{{EJS122}}Common Commands:
- `start`: Start a service. - `stop`: Stop a service. - `restart`: Restart a service. - `status`: Show the status of a service.Example:
bash sudo systemctl status sshdThis command shows the status of the SSH daemon.
25. `journalctl` - Query the Systemd Journal
The `journalctl` command is used to query and display messages from the systemd journal.
Usage:
{{EJS124}}Common Options:
- `-b`: Show messages from the current boot. - `-u`: Show messages for a specific unit.Example:
bash journalctl -u sshdThis command displays journal entries related to the SSH daemon.
26. `netstat` - Network Statistics
The `netstat` command displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
Usage:
{{EJS126}}Common Options:
- `-a`: Show all sockets. - `-t`: Show TCP connections. - `-u`: Show UDP connections. - `-n`: Show numerical addresses.Example:
bash netstat -tulnThis command shows all listening TCP and UDP ports with numerical addresses.
27. `ifconfig` - Configure a Network Interface
The `ifconfig` command is used to configure network interfaces.
Usage:
{{EJS128}}Example:
bash ifconfig eth0This command displays the configuration of the `eth0` network interface.
28. `ping` - Send ICMP ECHO_REQUEST to Network Hosts
The `ping` command checks the network connectivity between the host and a target.
Usage:
{{EJS130}}Example:
bash ping google.comThis command sends ICMP echo requests to `google.com` to check connectivity.
29. `traceroute` - Print the Route Packets Take to the Network Host
The `traceroute` command shows the path packets take to reach a network host.
Usage:
{{EJS132}}Example:
bash traceroute google.comThis command traces the route packets take to `google.com`.
30. `curl` - Transfer Data from or to a Server
The `curl` command is used to transfer data from or to a server using various protocols.
Usage:
{{EJS134}}Example:
bash curl -O http://example.com/file.txtThis command downloads `file.txt` from `example.com`.
31. `wget` - The Non-Interactive Network Downloader
The `wget` command downloads files from the web.
Usage:
{{EJS136}}Example:
bash wget http://example.com/file.txtThis command downloads `file.txt` from `example.com`.
32. `nano` - Simple Text Editor
The `nano` command opens the Nano text editor, which is user-friendly and suitable for beginners.
Usage:
{{EJS138}}Example:
bash nano /home/user/file.txtThis command opens `file.txt` in the Nano text editor.
33. `vim` - Vi Improved, a Highly Configurable Text Editor
The `vim` command opens the Vim text editor, which is powerful and highly configurable.
Usage:
{{EJS140}}Example:
bash vim /home/user/file.txtThis command opens `file.txt` in the Vim text editor.
34. `awk` - Pattern Scanning and Processing Language
The `awk` command is used for pattern scanning and processing.
Usage:
{{EJS142}}Example:
bash awk '{print $1}' /etc/passwdThis command prints the first field of each line in `/etc/passwd`.
35. `sed` - Stream Editor
The `sed` command is used to perform basic text transformations on an input stream.
Usage:
{{EJS144}}Example:
bash sed 's/old/new/g' file.txtThis command replaces all occurrences of `old` with `new` in `file.txt`.
36. `echo` - Display a Line of Text
The `echo` command displays a line of text.
Usage:
{{EJS146}}Example:
bash echo "Hello, World!"This command prints `Hello, World!` to the terminal.
37. `date` - Display or Set the System Date and Time
The `date` command displays or sets the system date and time.
Usage:
{{EJS148}}Example:
bash date "+%Y-%m-%d %H:%M:%S"This command displays the current date and time in the specified format.
38. `uptime` - Tell How Long the System Has Been Running
The `uptime` command shows how long the system has been running, along with the current time, number of users, and system load averages.
Usage:
{{EJS150}}Example:
bash uptimeThis command displays the system's uptime.
Other recent questions and answers regarding EITC/IS/LSA Linux System Administration:
- How to mount a disk in Linux?
- How important is Linux usage nowadays?
- How does the "conflicts" directive in systemd prevent two units from being active simultaneously?
- What is the purpose of the "requisite" directive in systemd and how is it different from "required by"?
- Why is it recommended to manage dependencies on units that you are creating or managing yourself, rather than editing system units?
- How does the "before" directive in systemd specify the execution order of units?
- What is the difference between weak dependencies and explicit ordering in systemd?
- What is the purpose of the "rescue.target" and how can it be used for troubleshooting without rebooting the system?
- What command can be used to switch between targets in systemd and how is it similar to switching between run levels in sysvinit?
- How can you ensure that necessary network configurations are completed before a specific network service starts?
View more questions and answers in EITC/IS/LSA Linux System Administration
More questions and answers:
- Field: Cybersecurity
- Programme: EITC/IS/LSA Linux System Administration (go to the certification programme)
- Lesson: Introduction (go to related lesson)
- Topic: Getting started (go to related topic)