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:
bash ls [options] [directory]
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/log
This 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:
bash cd [directory]
Example:
bash cd /etc
This 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:
bash pwd
Example:
bash pwd
If 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:
bash cp [options] source destination
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/docs
This 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:
bash mv [options] source destination
Example:
bash mv /home/user/file.txt /home/user/docs/file.txt
This 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:
bash rm [options] file
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/temp
This 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:
bash chmod [options] mode file
Example:
bash chmod 755 /home/user/script.sh
This 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:
bash chown [options] owner[:group] file
Example:
bash chown root:root /var/www/html
This 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:
bash ps [options]
Common Options:
– `-e`: Display all processes.– `-f`: Full-format listing.
Example:
bash ps -ef
This 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:
bash top
Example:
bash top
Running 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:
bash kill [options] pid
Example:
bash kill -9 1234
This 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:
bash df [options]
Common Options:
– `-h`: Human-readable format.– `-T`: Display file system type.
Example:
bash df -h
This command shows disk space usage in a human-readable format.
13. `du` – Estimate File Space Usage
The `du` command estimates file space usage.
Usage:
bash du [options] [directory]
Common Options:
– `-h`: Human-readable format.– `-s`: Summarize total size.
Example:
bash du -sh /home/user
This 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:
bash grep [options] pattern [file]
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/log
This 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:
bash find [path] [expression]
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:
bash tar [options] [archive-file] [file or directory]
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/docs
This 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:
bash ssh [options] user@hostname
Common Options:
– `-p`: Specify port.– `-i`: Specify identity file for key-based authentication.
Example:
bash ssh -i ~/.ssh/id_rsa [email protected]
This 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:
bash scp [options] source destination
Common Options:
– `-r`: Recursively copy directories.– `-P`: Specify port.
Example:
bash scp -P 2222 /home/user/file.txt user@remote:/home/user
This 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:
bash rsync [options] source destination
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/docs
This 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:
bash crontab [options] [file]
Common Options:
– `-e`: Edit the crontab file.– `-l`: List the crontab file.
– `-r`: Remove the crontab file.
Example:
bash crontab -e
This 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:
bash sudo [options] command
Example:
bash sudo apt-get update
This 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:
bash apt-get [options] command
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 vim
This command installs the `vim` text editor.
23. `yum` – Yellowdog Updater Modified
The `yum` command is used to manage packages in RPM-based distributions.
Usage:
bash yum [options] command
Common Commands:
– `update`: Update packages.– `install`: Install a package.
– `remove`: Remove a package.
Example:
bash sudo yum install httpd
This 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:
bash systemctl [command] [unit]
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 sshd
This 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:
bash journalctl [options]
Common Options:
– `-b`: Show messages from the current boot.– `-u`: Show messages for a specific unit.
Example:
bash journalctl -u sshd
This 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:
bash netstat [options]
Common Options:
– `-a`: Show all sockets.– `-t`: Show TCP connections.
– `-u`: Show UDP connections.
– `-n`: Show numerical addresses.
Example:
bash netstat -tuln
This 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:
bash ifconfig [interface] [options]
Example:
bash ifconfig eth0
This 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:
bash ping [options] destination
Example:
bash ping google.com
This 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:
bash traceroute [options] destination
Example:
bash traceroute google.com
This 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:
bash curl [options] [URL]
Example:
bash curl -O http://example.com/file.txt
This command downloads `file.txt` from `example.com`.
31. `wget` – The Non-Interactive Network Downloader
The `wget` command downloads files from the web.
Usage:
bash wget [options] [URL]
Example:
bash wget http://example.com/file.txt
This 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:
bash nano [file]
Example:
bash nano /home/user/file.txt
This 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:
bash vim [file]
Example:
bash vim /home/user/file.txt
This 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:
bash
awk [options] 'pattern {action}' [file]
Example:
bash
awk '{print $1}' /etc/passwd
This 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:
bash sed [options] 'script' [file]
Example:
bash sed 's/old/new/g' file.txt
This 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:
bash echo [options] [string]
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:
bash date [options] [format]
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:
bash uptime
Example:
bash uptime
This 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)

