Sitemap
devsecops-community

Follow for Cloud, Linux, Devops, GitOps, DevSecOps, Development, and IT Related content.

Linux Commands for DevOps Tasks

11 min readNov 16, 2025

--

Press enter or click to view image in full size

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 directories

mkdir -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/
└── linux

cd <dir>-Change Directory

Purpose: Move into a specific folder
Use Case: Navigate to the working directory
Example:

cd /home/user/projects

cd ..-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:

cd

pwd-To print the path of present working Directory

Purpose: Display current directory path
Use Case: Confirm current location before running file operations
Example:

pwd

rmdir <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 directories

rm -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 files

rm <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 files

touch 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.txt

cat <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 it

clear-Clear Terminal Screen

Purpose: Remove previous terminal output
Use Case: Work with a clean workspace
Example:

clear

echo “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:

history

FILE 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.txt

vi <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.txt

vim <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.txt

cat > 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 save

cat >> 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 save

FILE 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.txt

USER 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 passwd

cat/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/passwd

sudo su-Switch to Root User

Purpose: Gain full administrative privileges
Use Case: Perform admin-level tasks like installations or user management
Example:

sudo su

useradd <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 directory

passwd <username>-Set Password for Created User

Purpose: Assign or update login password
Use Case: Secure newly created accounts
Example:

passwd user1

su <username>- Switch to Existing User

Purpose: Log in as another user
Use Case: Test permissions or environment
Example:

su user1

su - <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 - user1

userdel <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 user1

userdel -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 user1

who-Show Logged-In User

Purpose: Display currently active users
Use Case: Monitor system session usage
Example:

who

whoami-Display Current Username

Purpose: Identify the logged-in user
Use Case: Confirm permissions after switching users
Example:

whoami

who-To exit from current user to previous user terminal

Purpose: Return to previous user session
Use Case: Leave root or switched user terminal
Example:

exit

finger <user_name>- Show User Details

Purpose: Display detailed info like login time, home dir, shell
Use Case: View extended user profile details
Example:

finger user1

getent passwd <user_name>-Get Specific User Info

Purpose: Retrieve details of a specific user
Use Case: Verify user existence and metadata
Example:

getent passwd user1

usermod -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 chandralekha

GROUP 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 aws

groupdel <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 group2

usermod -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 docker

gpasswd -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 linux

usermod -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 chandu

groupdel <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 aws

group <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 chandralekha

groupmod -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 devs

File 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 -l
  • chmod <permission> <file_name> → Change permissions
chmod 755 deploy.sh      #numeric mode
chmod u+rwx script.sh #symbolic
  • umask → 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.txt

chgrp <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.txt

chown <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.txt

Searching 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
localhost

hostid - shows the host id of the system assigned by the OS.

➜  ~ hostid
0a123456

date - 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 UTC

uptime - 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.18

uname - unix name.

➜  ~ uname
Linux

echo $? - shows the exit status of the last executed command (0 - success, 1-255 - error/failure).

➜  ~ echo $?
127

shutdown -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 running

systemctl — 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 -D

Network 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🖤

You can contact me on: LinkedIn Email

DevSecOps — Community 🚀

Thank you for being a part of the DevSecOps — Community community! Before you go:

--

devsecops-community
devsecops-community

Published in devsecops-community

Follow for Cloud, Linux, Devops, GitOps, DevSecOps, Development, and IT Related content.