Straight to the point:
1. man – Understanding Linux Commands
One thing you will quickly discover when working with Linux is that there are many commands, and each command comes with different options and ways of using it.
You don't have to memorise everything. Linux provides manual pages (man pages) that explain how commands work, their available options, and their usage.
For example:
man ls
This opens the manual page for the ls command.
You can navigate through the manual using the arrow keys or Page Up and Page Down. When you are done, press q to quit.
This is particularly useful when working on servers where you may not have access to a browser or when you need to understand an option before using it.
2. sudo – Running Commands with Elevated Privileges
In Linux, not every user has permission to perform every operation.
For example, installing software, modifying certain system files, and managing system services usually require administrative privileges.
This is where sudo comes in.
sudo apt install nginx
The command runs with elevated privileges, allowing you to install Nginx on your system.
You may also come across:
sudo su
This opens a root shell, allowing you to run multiple commands with administrative privileges.
However, I would recommend using sudo for individual commands rather than staying logged in as root for prolonged periods. Running everything as root increases the risk of accidentally modifying or deleting important system files.
To leave a root shell, run:
exit
3. pwd – Knowing Your Current Location
Have you ever navigated through several directories and suddenly forgotten where you are?
The pwd command solves that problem.
It stands for Print Working Directory and displays the full path of your current location.
pwd
Example output:
/home/michael/DevOps
When managing servers, you will often move between application directories, configuration folders, log directories, and other system locations.
Knowing your current directory helps you avoid running commands against the wrong files or folders.
4. ls – Listing Files and Directories
The ls command allows you to see the files and directories in your current location.
ls
However, there are a few options that make it more useful.
ls -l
Displays files in a detailed format, including permissions, ownership, file size, and modification dates.
ls -a
Displays hidden files and directories, including files such as .bashrc and .ssh.
ls -lah
Combines the options to show hidden files, detailed information, and human-readable file sizes.
This is one of the commands you will use regularly when inspecting application directories, checking configuration files, and investigating file permissions.
5. cd – Navigating Between Directories
The cd command allows you to change your current directory.
For example:
cd /var/www
This moves you into the /var/www directory.
To move one directory backwards:
cd ..
To move up two levels:
cd ../..
You can also return to your home directory by running:
cd ~
One small habit worth developing is using the Tab key for autocomplete. Instead of typing an entire directory name, start typing the first few characters and press Tab.
It saves time and reduces mistakes, especially when working with long directory paths.
6. mkdir – Creating Directories
The mkdir command allows you to create directories.
For example:
mkdir DevOps
This creates a directory called DevOps in your current location.
You can also create multiple directories at once:
mkdir logs backups scripts
Another useful option is -p, which allows you to create nested directories even when the parent directories do not exist.
mkdir -p /var/www/myapp/logs
You will find this useful when preparing server environments and organising application files.
7. touch – Creating Files
While mkdir creates directories, touch can create empty files.
touch app.py
This creates an empty file called app.py.
You can also create several files at once:
touch Dockerfile requirements.txt .env
An important detail is that touch does not overwrite the contents of an existing file. It updates its timestamps instead.
You will often use it when creating configuration files, scripts, and other application files.
8. cp – Copying Files and Directories
The cp command allows you to copy files from one location to another.
For example:
cp app.py backups/
This creates a copy of app.py inside the backups directory while leaving the original file in place.
To copy an entire directory and its contents, use the recursive option:
cp -r myapp backups/
This can be useful when creating backups of configuration files or application directories before making changes.
9. mv – Moving and Renaming Files
The mv command is used to move files and directories from one location to another.
For example:
mv app.py /var/www/myapp/
This moves the file into the specified directory.
You can also use mv to rename files:
mv old_config.conf new_config.conf
Unlike cp, mv does not leave a second copy behind.
When working with Linux servers, you may use it to organise application files, move configuration files, or rename files during deployment.
Be careful when moving files into directories where another file has the same name, as it may replace the existing file.
10. rm – Removing Files and Directories
The rm command allows you to delete files.
rm app.py
To remove a directory and everything inside it, you can use:
rm -r myapp
You may also encounter:
rm -rf myapp
Here, -r means recursive, while -f forces removal without prompting for confirmation in many situations.
Be very careful with this command.
A wrong path can result in deleting important application files, configuration files, or even critical system data.
Always check your current directory using pwd and inspect the target using ls before running destructive commands. Avoid running recursive deletion commands with sudo unless you fully understand what you are removing.
11. cat – Reading File Contents
The cat command allows you to display the contents of a file directly in the terminal.
cat config.txt
This is particularly useful when checking configuration files or reading application settings.
For example:
cat /etc/hosts
Displays the contents of the system's hosts file.
You can also combine cat with other commands using a pipe.
cat config.txt | grep "DATABASE"
This displays only the lines containing the word DATABASE.
For very large files, commands such as less are often more convenient because they allow you to navigate through the contents without printing everything at once.
12. echo – Printing and Writing Text
The echo command prints text to the terminal.
echo "Hello DevOps"
However, it is also useful when writing information into files and working with environment variables.
For example:
echo "Hello DevOps" > message.txt
The > operator writes the text into the file. If the file already exists, its previous contents will be replaced.
To append instead of replacing the contents, use >>.
echo "Learning Linux commands" >> message.txt
You can also use echo to check environment variables.
echo $HOME
echo $PATH
This becomes useful when troubleshooting application environments, checking configuration values, and working with deployment scripts.
One important thing: avoid using echo to write secrets into shell commands or scripts that may end up in shell history or logs.
13. grep – Searching Through Files
Imagine you are working on a server and have a configuration file containing hundreds of lines. You want to find a particular setting without reading everything.
This is where grep becomes useful.
For example:
grep "DATABASE" .env
This searches for lines containing DATABASE in the .env file.
You can also search recursively through directories:
grep -r "DEBUG" /var/www/myapp/
Some useful options include:
-
-iignores uppercase and lowercase differences. -
-ndisplays line numbers. -
-rsearches recursively through directories. -
-vdisplays lines that do not match the search.
For example:
grep -in "error" application.log
This searches for the word error, regardless of case, and displays the matching line numbers.
For DevOps engineers, grep is particularly useful when investigating application logs, checking configuration files, and troubleshooting deployment issues.
14. find – Finding Files and Directories
The find command allows you to search for files and directories based on their names, types, sizes, modification times, and other conditions.
For example:
find /var/www -name "Dockerfile"
This searches the /var/www directory and its subdirectories for files named Dockerfile.
To find all files ending in .log:
find /var/log -type f -name "*.log"
To find directories:
find /var/www -type d
Unlike locate, which searches an indexed database, find searches the specified directory tree directly.
This is useful when investigating where application files are stored, locating configuration files, and identifying old files that may need attention.
You may also encounter locate, which can quickly search for files by name using a pre-built index. Its database may need updating before newly created files appear.
15. history – Viewing Previously Executed Commands
The history command displays commands you have previously executed in your terminal.
history
This can be particularly useful when you have forgotten a command you ran earlier or want to repeat a previous operation.
You can search through your command history using:
history | grep "docker"
You may also execute a previous command using its history number:
!25
This executes command number 25 from your history.
You can configure Bash to display timestamps alongside your command history:
export HISTTIMEFORMAT="%d-%m-%Y %T "
This makes it easier to see when commands were executed, provided the shell has recorded the relevant timestamps.
However, remember that shell history is not a complete audit log. Commands may not be recorded, and it should not be treated as a reliable security record.
16. chmod – Managing File Permissions
Linux uses permissions to control who can read, write, and execute files and directories.
There are three main permission types:
- Read (r): Allows a user to read a file.
- Write (w): Allows a user to modify a file.
- Execute (x): Allows a user to execute a file or access a directory.
These permissions are assigned to three categories:
- Owner: The user who owns the file.
- Group: Users belonging to the assigned group.
- Others: Everyone else.
The chmod command allows us to modify these permissions.
For example:
chmod 755 deploy.sh
This gives the owner read, write, and execute permissions, while the group and others receive read and execute permissions.
Another example:
chmod 644 config.txt
This gives the owner read and write permissions, while the group and others can only read the file.
You can also use:
chmod +x deploy.sh
This adds execute permission without replacing the other existing permissions.
This is particularly useful when working with deployment scripts, application files, and server configuration.
A common mistake is using chmod 777 on everything because an application is having permission issues. This gives everyone read, write, and execute permissions, which can create serious security problems. It is better to understand the actual permission requirement and assign only what is necessary.
17. chown – Changing File Ownership
While chmod manages permissions, chown allows you to change the ownership of files and directories.
For example:
sudo chown michael app.py
This changes the owner of app.py to michael.
You can also change both the owner and group:
sudo chown michael:developers app.py
To apply the change recursively to a directory and its contents:
sudo chown -R michael:developers /var/www/myapp
This is especially useful when deploying applications.
For example, if an application runs under a particular Linux user, the application files may need to be owned by that user or a suitable group.
Understanding the difference between ownership and permissions is important when troubleshooting issues such as applications being unable to read configuration files or write to log directories.
18. useradd – Creating Linux Users
Linux allows you to create different user accounts with different permissions and access levels.
The useradd command is used to create new users.
For example:
sudo useradd michael
This creates a user account called michael.
If you want to create a user with a home directory and an interactive Bash shell, you can use:
sudo useradd -m -s /bin/bash michael
You can then set the user's password using:
sudo passwd michael
Another useful command is groupadd, which creates a new group.
sudo groupadd developers
You can add an existing user to that group using usermod:
sudo usermod -aG developers michael
The -aG options append the user to the specified supplementary group without removing their existing supplementary group memberships.
These commands are useful when managing server access, separating responsibilities, and ensuring that different users have only the permissions they need.
19. apt – Installing and Managing Software
Most Linux distributions have a package manager that helps you install, update, and remove software.
On Ubuntu and other Debian-based distributions, one of the package managers you will frequently encounter is APT.
To update the package information from configured repositories, run:
sudo apt update
To upgrade installed packages:
sudo apt upgrade
To install a package:
sudo apt install nginx
To remove a package:
sudo apt remove nginx
You can also install multiple packages in one command:
sudo apt install nginx docker.io git curl
As a DevOps engineer, you will regularly install and configure software such as Nginx, Docker, Git, Python, and other server dependencies.
Understanding package management is important because keeping software updated is part of maintaining a secure and reliable server.
Note that APT is used on Debian-based distributions. Other Linux distributions use different package managers, such as dnf on Fedora and many RHEL-based systems.
20. systemctl – Managing Linux Services
This is one of the commands I consider particularly important for anyone working with Linux servers.
Linux runs several background services that perform different tasks. These may include web servers, databases, SSH, monitoring agents, and other application services.
On most modern Linux distributions using systemd, systemctl is used to manage these services.
For example, to check the status of Nginx:
sudo systemctl status nginx
To start a service:
sudo systemctl start nginx
To stop it:
sudo systemctl stop nginx
To restart it:
sudo systemctl restart nginx
To make a service start automatically when the server boots:
sudo systemctl enable nginx
You can also check whether a service is enabled:
sudo systemctl is-enabled nginx
Imagine you have deployed a Django application behind Nginx and Gunicorn. If your website suddenly stops responding, checking the status of these services is one of the first things you may want to do.
For example:
sudo systemctl status nginx
sudo systemctl status gunicorn
Understanding how to manage services is an important part of server administration and application troubleshooting.
Other Commands Worth Learning
The 20 commands above provide a good starting point, but there are several others from the book that I would recommend adding to your learning list.
For processing command output:
awk
cut
xargs
-
awkhelps extract specific columns or process structured text. -
cutextracts specific characters or fields from lines of text. -
xargstakes input from one command and passes it as arguments to another.
For example:
who | awk '{print $1}'
This extracts the usernames from the output of who.
cut -d: -f1 /etc/passwd
This extracts the first field from each line of the Linux user account file.
For monitoring and troubleshooting:
ps aux
top
df -h
du -sh /var/log
free -h
ss -tulpn
These are particularly important for DevOps work.
-
ps auxdisplays running processes. -
topprovides a live view of system processes and resource usage. -
df -hshows available and used disk space across mounted filesystems. -
du -shshows the size of a directory or file. -
free -hdisplays memory usage. -
ss -tulpnhelps inspect listening network sockets and associated processes (some process details require elevated privileges).
For example, if an application stops responding, you may need to investigate whether the server has run out of memory, whether a process has stopped, or whether the required network port is listening.
For reading logs:
journalctl -u nginx
This displays logs for the Nginx service managed by systemd.
To follow new log entries as they appear:
journalctl -u nginx -f
This is useful when investigating why a service failed or monitoring what happens after restarting an application.
Final Thoughts
Learning Linux commands is not about memorising hundreds of commands or trying to become an expert in every available option. It is about understanding what you are trying to achieve and knowing which tools can help you get there.
As a DevOps engineer, you will spend a considerable amount of time working with servers, deploying applications, managing services, checking logs, configuring permissions, and troubleshooting problems.
You may not use every command every day, but you should be comfortable navigating the terminal and knowing where to look when something goes wrong. My advice is to practise these commands on an Ubuntu virtual machine or a Linux environment using WSL. Create files, move them around, install packages, create users, change permissions, and inspect running services.
Don't just read the commands. Use them.
The more comfortable you become with the Linux terminal, the easier it becomes to work with Docker, CI/CD pipelines, cloud infrastructure, and other DevOps tools.
Top comments (0)