Linux Commands for DevOps Tasks
This guide highlights working confidently with the Linux command line is not just helpful — it’s mandatory. Learning Linux commands is one of the most important steps.
This will include the most essential and widely used Linux commands. Each command is explained with purpose and practical usage.
These commands can be used on any Linux system, whether it’s a locally installed distribution, a virtual machine, WSL (Windows Subsystem for Linux), or an online Linux sandbox/terminal.
BASIC COMMANDS:
ls - List Files & Directories
Purpose: View directory contents
Use Case: Lists all the files and directories
Example:
ls mkdir -Create a Directory
mkdir dir1 dir2 …-Create Multiple Directories
Purpose: Make a new folder
Use Case: Create a project workspace folder
Example:
mkdir myproject #Here, "myproject" is a directory
mkdir app logs #Here, It creates multiples directoriesmkdir -p dir/sub-dir/…-Create Nested Directories
Purpose: Make multi-level directory structure
Use Case: Create a project structure in a single command
Example:
mkdir -p myproject/devops/linux
#Here, myproject is a directory, devops is sub-directory under myproject
#linux is sub-directory under devops
myproject/
└── devops/
└── linuxcd <dir>-Change Directory
Purpose: Move into a specific folder
Use Case: Navigate to the working directory
Example:
cd /home/user/projectscd ..-To exit from its current directory to previous directory
Purpose: Goes back to parent directory
Use Case: Quickly navigate backwards in folder hierarchy
Example:
cd ..cd-To exit from current directory to Home Directory
Purpose: Return to default home path
Use Case: Reset location when unsure where you are
Example:
cdpwd-To print the path of present working Directory
Purpose: Display current directory path
Use Case: Confirm current location before running file operations
Example:
pwdrmdir <dir>-To delete an empty Directory
rmdir dir1, dir2…-Remove multiple empty directories
Purpose: Delete a directory that contains no files / no contents.
Use Case: Clean unused folder
Example:
rmdir temp #Here, it removes temp, which is a directory
rmdir temp1 temp2 temp3 #removes multiple directoriesrm -r<dir>- Delete Directory with Contents
Purpose: Remove directory and everything inside
Use Case: Delete a project folder completely
Example:
rm -r old_project
#Here, old_project is a directory contatining content.touch <file>-Create a File
touch file1 file2…-Create Multiple Files
Purpose: Make a new empty file
Use Case: Create readme, script, or config files
Example:
touch index.html #Here index.html is a file
touch home.html style.css app.js #Here, creates multiple filesrm <file_name>- Remove a File.
rm file1 file2…-Remove Multiple Files
Purpose: Delete file/files.
Use Case: Remove unwanted or temporary files
Example:
rm file1.txt #Here, removes single file.txt
rm file1.txt file2.txt file3.txt #Here, removes multiple filestouch file{1..n}.extension-Create Numbered Files
Purpose: Generate sequential files
Use Case: Sample or test file creation
Example:
touch sample{1..3}.txt
#Here, it creates 3 files with same name and number sequence
.
├── sample1.txt
├── sample2.txt
└── sample3.txtcat <file>-View File Content
Purpose: Read file data in terminal
Use Case: Check configuration or stored text
Example:
cat sample.java #It displays the content inside itclear-Clear Terminal Screen
Purpose: Remove previous terminal output
Use Case: Work with a clean workspace
Example:
clearecho “word/statement”-Print Text to Terminal
Purpose: Display text output
Use Case: Test or display command results
Example:
echo "Welcome to Linux"history-show Past Commands
Purpose: Display previously executed commands
Use Case: Reuse or re-run old commands without typing again
Example:
historyFILE EDITOR COMMANDS:
nano <file>-Open & Edit Files Using Nano Editor
Purpose: Create or edit text files in a simple terminal editor
Use Case: Edit config, notes, scripts, or documentation
Example:
nano file1.txtvi <file>-Open & Edit Files Using vi Editor
Purpose: Edit files with a lightweight modal editor
Use Case: Modify configuration files on Linux servers
Example:
vi file1.txtvim <file>-Open & Edit Files Using Vim (Enhanced vi)
Purpose: Edit files using advanced, faster, command-based editor
Use Case: Edit large or complex configuration files efficiently
Example:
vim file1.txtcat > file-Create & Write Content (Overwrite Mode)
Purpose: Create a file and write content, replacing existing data
Use Case: Quickly create small text files
Example:
cat > notes.txt
# type your text
# press CTRL + D to savecat >> file-Append Content
Purpose: Add new text to an existing file
Use Case: Add new logs, notes, or commands without deleting old content
Example:
cat >> notes.txt
# type new text
# press CTRL + D to saveFILE MANAGEMENT COMMANDS:
cp <source_path> <destination_path>-Copy Files
Purpose: Create a duplicate of a file
Use Case: Make a backup before editing
Example:
cp notes.txt /home/user/docs/mv <source_path> <destination_path>- Move Files.
Purpose: Transfer file location.
Use Case: Organize files into correct folders
Example:
mv notes.txt /home/user/docs/mv <old_name> <new_name>-Rename File or Directory
Purpose: Change file or folder name
Use Case: Correct naming mistakes or versioning
Example:
mv report.txt report_v2.txtUSER MANAGEMENT COMMANDS:
getnet passwd-List All System Users
Purpose: View registered users on the system
Use Case: Confirm whether a user already exists before creating or deleting
Example:
getent passwdcat/etc/passwd-View Full System User List
Purpose: Display all system users and account info from passwd file
Use Case: Check basic details like username, home directory, and shell
Example:
cat /etc/passwdsudo su-Switch to Root User
Purpose: Gain full administrative privileges
Use Case: Perform admin-level tasks like installations or user management
Example:
sudo suuseradd <username> Or adduser <username>-Create a New User
Purpose: Add a new user account
Use Case: Setup separate login for developers or services
Example:
useradd user1 #Creates user
adduser user2 #Creates user along with user's home directorypasswd <username>-Set Password for Created User
Purpose: Assign or update login password
Use Case: Secure newly created accounts
Example:
passwd user1su <username>- Switch to Existing User
Purpose: Log in as another user
Use Case: Test permissions or environment
Example:
su user1su - <username>-Switch With User’s Home Directory & Environment
Purpose: Switch user and load full environment
Use Case: Work inside user’s actual home directory setup
Example:
su - user1userdel <username> Or deluser <username>-Delete a User
Purpose: Remove a user from the system
Use Case: Revoke access of ex-employees or unused accounts
Example:
userdel user1
deluser user1userdel -r <username> Or deluser --remove -home <username>
-Deletes User + Home Directory
Purpose: Remove user and delete their data
Use Case: Completely remove unwanted local accounts
Example:
userdel -r user1
deluser --remove -home user1who-Show Logged-In User
Purpose: Display currently active users
Use Case: Monitor system session usage
Example:
whowhoami-Display Current Username
Purpose: Identify the logged-in user
Use Case: Confirm permissions after switching users
Example:
whoamiwho-To exit from current user to previous user terminal
Purpose: Return to previous user session
Use Case: Leave root or switched user terminal
Example:
exitfinger <user_name>- Show User Details
Purpose: Display detailed info like login time, home dir, shell
Use Case: View extended user profile details
Example:
finger user1getent passwd <user_name>-Get Specific User Info
Purpose: Retrieve details of a specific user
Use Case: Verify user existence and metadata
Example:
getent passwd user1usermod -l <new_name> <old_name>-Rename User Account
Purpose: Change existing username
Use Case: Update user identity without creating a new account
Example:
usermod -l chandu chandralekhaGROUP MANAGEMENT COMMANDS:
getent group Or cat /etc/group-To list all groups
Get Chandra Lekha KV’s stories in your inbox
Join Medium for free to get updates from this writer.
Purpose: Display all groups available on the system
Use Case: Verify existing groups before creating new ones
Example:
getent group
cat /etc/group groupadd <group_name> Or addgroup <group_name>-Create a New Group
Purpose: Add a new group to the system
Use Case: Assign multiple users under same permission level
Example:
groupadd linux
groaddgroup awsgroupdel <group_name> Or delgroup <group_name>-Delete Group
Purpose: Remove an existing group
Use Case: Delete old or unused groups to maintain security
Example:
groupdel group1
delgroup group2usermod -aG <group_name> <user_name>Orgpasswd -a <user_name> <group_name>
-Add User to Group
Purpose: Assign a user to an additional group
Use Case: Grant access to shared directories or resources
Example:
usermod -aG linux chandralekha
gpasswd -a karthik dockergpasswd -M <user1>,<user2>... <group_name>-Add Multiple Users to Group
Purpose: Assign multiple users to the same group in one command
Use Case: Quickly set up team access
Example:
gpasswd -M user1 user2 linuxusermod -G <group1>,<group2>...<user>-Add Multiple Groups to One User
Purpose: Assign several group permissions to a single user
Use Case: Give a user combined access such as admin privileges, development tools, and deployment resources
Example:
usermod -G linux aws docker chandugroupdel <group_name> Ordelgroup <group_name>-Delete Group
Purpose: Remove an existing group
Use Case: Delete old or unused groups to maintain security
Example:
groupdel testers gpasswd -d <user_name> <group>-Remove User from Group
Purpose: Detach a user from a specific group
Use Case: Revoke access after role change
Example:
gpasswd -d deepika awsgroup <user_name>-List Groups a User Belongs To
Purpose: Display the groups associated with a specific user
Use Case: Verify whether the user has corrected permissions before assigning or removing access
Example:
groups chandralekhagroupmod -n <new_group_name> <old_group_name>-Rename Group
Purpose: Change an existing group’s name
Use Case: Align group naming with new standards or project structure
Example:
groupmod -n devops devsFile Permissions:
user — u, group — g, others — o
read (r) — 4, write (w)- 2, execute (x) — 1
Add permission(+), Remove permission(-)
- Sum the numbers to generate an octal number for setting permissions on a file or directory.
ls -l→ View file & directory permissions
Example:ls -lchmod <permission> <file_name>→ Change permissions
chmod 755 deploy.sh #numeric mode
chmod u+rwx script.sh #symbolicumask→ View or set default permission mask
Example:umask
Group Permissions:
chown <new_user_name> <file/dir_name>-Change File Owner
Purpose: Assign a new owner to a file or directory
Use Case: When a file needs to be managed by a different user
Example:
chown chandu file.txtchgrp <new_group_name> <file/dir_name> Orchown : <new_group_name> <file/dir_name>
-Change Group
Purpose: Change the group ownership of a file or directory
Use Case: When multiple users in the same group need access
Example:
chgrp developers report.txt
chown : developers report.txtchown <new_user_name> <file/dir_name>-Change Owner and Group Together
Purpose: Update both owner and group in one command
Use Case: When transferring project ownership to a new user and team
Example:
chown chandu : developers index.txtSearching Commands:
find — real-time search
Used to search files or directories based on name, permissions, size, type, etc.
find . -name <fileName>
Searches for the given file inside the current directory (.).find <dirName> -name <fileName>
Searches inside the specified directory.find <dirName> -perm 754
Finds files in that directory with permission 754.
locate — database-based faster search
Uses a pre-built index database (updatedb), so results appear faster but may not include very recent changes.
locate <fileName/dirName>
Shows full path if present in database.
Example:locate sample.txt
System Info Commands
hostname - shows the name of the system host.
➜ ~ hostname
localhosthostid - shows the host id of the system assigned by the OS.
➜ ~ hostid
0a123456date - By default, the date command displays the system’s current date and time based on the configured local time zone (either defined by the TZ environment variable or the system’s time zone settings).
date --utc Or date -u- To view the date and time in Coordinated Universal Time (UTC)
➜ date
Thursday 20 November 2025 07:27:31 PM IST➜ date --utc
Thursday 20 November 2025 01:57:50 PM UTCuptime - shows the elapsed time duration since the machine logged in.
➜ ~ uptime
12:34:56 up 1 day, 3:45, 2 users, load average: 0.25, 0.20, 0.18uname - unix name.
➜ ~ uname
Linuxecho $? - shows the exit status of the last executed command (0 - success, 1-255 - error/failure).
➜ ~ echo $?
127shutdown -r now - restart the machine immediately (-r restart).
➜ ~ sudo shutdown -r now
Broadcast message from user@hostname
(/dev/pts/0) at 12:34 ...The system is going down for reboot NOW!printenv - displays all the environment variables of the Linux system.
➜ ~ printenv
TERM=xterm-256color
SHELL=/bin/bash
USER=your_username
...last - shows previous logins in the Linux system.
➜ ~ last
root pts/0 Sat Nov 16 12:34 still logged in
reboot system boot 5.4.0-96-generic Sat Nov 16 12:33 still runningsystemctl — System Control: Manage system services using systemd.
➜ ~ systemctl status sshd
● sshd.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2025-11-16 12:34:56 UTC; 1 day 3h ago
Docs: man:sshd(8)
man:sshd_config(5)
Process: 1234 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 5678 (sshd)
Tasks: 1 (limit: 1234)
Memory: 2.3M
CPU: 12ms
CGroup: /system.slice/sshd.service
└─5678 /usr/sbin/sshd -DNetwork Commands:
nc — Simple tcp proxy, network daemon testing
Example: nc -vz google.com 443
ping <hostName> - tests the reachability & responsiveness of the remote host.
Example: ping google.com -c 2 (-c pings 2 times)
dig <domainName> - Shows DNS information of the domain.
Example: dig medium.com
wget <url>- Used to retrieve/download files from the internet.
curl - client URL.
curl <url> - Used to retrieve/download files from the internet.
ifconfig - Display available network interfaces.
ip addr - Display and manipulate network interface info.
ip route — To show or manipulate the IP routing table. Shows clear ip tables rules.
curl ifconfig.me - Shows the public ip address of the machine.
netstat -antp- shows all tcp open ports (-a all, t-tcp, n-active, p protocol).
traceroute <url> - traces the route using packets from source to destination host.
Misc Commands:
man- Displays the manual page for a specific command. Provides detailed information and usage instructions.sed- Edits a stream of text by substituting occurrences of a pattern with another.awk- A powerful programming language for text processing.wc-(Word Count)ln-(Create Links):stat <fileName/dirName>- shows detailed information about the file or directory.cron- system daemon for managing scheduled tasks.crontab-Used to create, edit, and manage cron jobs.tree- Representation of files and directories of a specific directory.echo "sample text" | grep text- The output of the first command is passed as an input to the second command using the pipe (|) symbol.ls -l | tee file.txt- Redirects the list to the file.txt and simultaneously displays it in the terminal.echo "sample text" > <fileName>- Write the content to the file mentioned by overwriting the existing content (> redirection operator).echo "new sample text" >> <fileName>- Appends the contents to the file mentioned without overwriting the existing content (>> redirection operation).
Ubuntu Package related Commands:
apt - Package Manager for Debian-based Linux distributions Eg: Ubuntu.
apt - A newer version of the package manager with colorized output, progress bar and additional functions.
apt-get - Older version and basic package manager.
apt update - Updates the package list.
apt list --installed - Lists all the installed packages.
apt list --installed <packageName> - shows the package name if it's installed.
apt show <packageName> - shows information about a package mentioned.
apt search <packageName> - searches and shows the list of packages.
apt install <packageName> - installs the required package.
apt remove <packageName> - removes the required package.
apt purge <packageName> - removes the required package along with its config files.
Note: For other package manager just replace “apt” with other package manager
Conclusion:
Linux commands are core tools for DevOps engineers, enabling efficient system management, task automation, troubleshooting, and deployment operations. Mastering these commands strengthens control over environments and improves operational efficiency across development and production systems.
If this insight resonated with you, please consider hitting the Follow and Clap buttons, it motivates me to create more helpful content.
Thank you🖤
DevSecOps — Community 🚀
Thank you for being a part of the DevSecOps — Community community! Before you go:
- Be sure to clap and follow ️ the Author👏️️
- Follow: Newsletter | LinkedIn Groups |
- More content at DevSecOps — Community










