linux for devops

kishore kumarkishore kumar
9 min read

sudo : means similar to root user but not have full access

sudo su - completely changes into root user

ls list all

ls The ls command is used to list the files and folders in a directory (folder).

Think of it like opening a folder to see what’s inside.

ls -l → Long listing format (shows permissions, owner, size, date, etc.)

ls -a → Includes hidden files (those starting with a dot .)

ls -lh → Human-readable file sizes (e.g., KB, MB

ls -la → Combines long listing and shows hidden files

ls -lah /home/user/ (This lists all files (including hidden ones) in /home/user/ with detailed, human-readable info )

ls -lrth List all files in the current directory (not including hidden files) in long format, sorted by modification time, oldest first, with human-readable sizes.

cat The cat command is used to view, create, or add text in files on Linux.

cat -n The command cat -n filename shows the contents of a file with line numbers.

cat > file.txt The command cat > file.txt is used to create a new file or overwrite an existing file, and then you can type content into it manually.

cat >> file.txt The command cat >> file.txt is used to add content to the end of a file without overwriting it.

cp The cp command is used to copy files or folders in Linux.

It's like "copy and paste" in the terminal.

cp *.txt bittu/ This command copies all .txt files from the current folder into a folder named bittu.

mv The mv command is used to move or rename files and folders.

Think of it like cut and paste in the terminal.

head The head command shows you the first few lines of a file. It’s useful when you want to quickly see the start of a file without opening the whole thing. example: head -n 10 will show you the first 10 lines of the file named <filename>.

tail The tail command shows you the last few lines of a file. example: tail -n 10 <file.txt> Shows you the last 10 lines of the file named <file.txt>.

sort It arranges lines in a file or text in order. example: banana apple cherry.. by using sort command

sort filename.txt —> apple banana cherry 10 2 30—> 2 10 30

grep it searches for exact word. example: grep it filename.txt it will find lines containing "it" anywhere — even inside other words like "bit", "item", or "waiting".

find To find empty files in Linux, you can use the find command with the -empty option. example: find . -type f -empty

sed sed is a tool to find and change text inside files or input.It’s like a search and replace helper that works right from the terminal. Example: apple banana mango command sed 's/apple/orange/' fruits.txt —> orange banana orange pie

You can use sed to see specific lines from a file, like a simpler version of head or tail. to see a single line with sed: sed -n '5p' filename.txt To see a range of lines: sed -n '3,7p' filename.txt Shows lines 3 to 7 only.

sed command is used for deleting also : sed '3d' filename.txt Deletes line 3

who It shows who is currently logged in on the system. You can see the list of users logged in and their login details.

uptime It tells you how long your Linux system has been running since it was last started. It also shows how many users are logged in and the system load (how busy the system is).

whereis It tells you where a command’s files are located on your system. Useful if you want to know where the program or its documentation lives.

users It shows the usernames of people currently logged in to the system. but by using this we can see user in single line example: alice bob charlie

df df shows how much disk space is used and available on your filesystems (like your hard drives or partitions).

du -h du means disk usage — it tells you how much space files and folders are using on your disk.

hostname It shows the name of your computer (the hostname) on the network. Useful to know what your machine is called. eg ubuntu,redhat

systemctl It’s a tool to manage system services on Linux systems using systemd. You can start, stop, restart, enable, or check the status of services (like web servers, databases, etc.).

last It shows a list of the most recent user logins and logouts on your system. Useful to see who logged in, when, and from where.

ps ps shows a snapshot of the running processes (programs) on your system. It tells you which programs are running right now.

ps -a It shows programs started by users from the terminal (like editors, scripts, etc.), but it does not show system processes running in the background. It only displays what the user runs. )

ps -aux This command shows all the processes running on the system.

ps -ef It displays a complete list of all running processes on your Linux system, with detailed information.

pipe command | pipe command uses to connects two commands example: ps -ef | grep apache ( ps -ef shows all running processes.), (grep apache searches for lines with "apache".)

kill The kill command is used to stop (end) a running process using its PID (Process ID). example: kill 12345(this is process id)

top It shows a real-time view of all the processes running on your system. It updates every few seconds, allowing you to see what's using your CPU, memory, etc.

scp (Secure Copy.)It's used to copy files between two computers over a network safely (using SSH).This means copying files from a local computer to a Linux terminal and from a Linux terminal to a local computer. eg: scp source destination—> scp file.txt ubuntu@<ip address>:/home/username/ Example: Copy a file from a remote server to your computer eg: scp ubuntu@remote_ip:/home/username/file.txt .

zip The zip command compresses files or folders into a .zip file. This makes them smaller and easier to share or store.

zcat zcat lets you see what's inside a .gz compressed file without having to extract it first.

useradd The useradd command is used to create a new user account on a Linux system.

adduser adduser is an easier, interactive way to create a new user on Linux. It usually asks you questions like password and full name, and it automatically creates a home directory.

  • | Feature | useradd | adduser | | --- | --- | --- | | Type | Low-level system command | High-level friendly script | | User interaction | No prompts (non-interactive) | Interactive — asks questions | | Default behavior | Creates user but no home directory by default (unless -m is used) | Automatically creates home directory and sets defaults | | Ease of use | Requires more options and knowledge | Easy for beginners | | Availability | Available on all Linux systems | Usually a Perl/Python script, not on all distros (common on Debian/Ubuntu) | | Customization | More manual control | Uses system defaults for most settings |

    sudo cat /etc/passwd It's a file that keeps basic information about all users on the system. Each line shows one user's details, like their username, user ID, home directory, and default shell.

  • sudo cat /etc/shadow here is the place where passwords of user will store in background

  • To delete user userdel <username>

  • To Addpasswd for user sudo passwd username

  • chage The chage command updates user password expiration details. It handles:

    • When the password will expire

    • When the user needs to change their password

    • When the account will expire

    • NOTE : But the limitation of chage command was it will work one user at a time

  • Groupadd The groupadd command is used to create a new user group on a Linux system.

  • Groups are useful for managing permissions and access control for multiple users.

  • lid -g It is used to list users and group memberships.

  • visudo it is used to give sudoers permission to the users

  • sudo su - it switches completely to root user

  • more command The more command is used to view large text files one page at a time. to see another page we use space

  • uniq The uniq command is used to remove duplicate lines from a file or output.

  • NOTE: It only works on consecutive duplicate lines, so the file or input should usually be sorted first. For example: Alice Alice Bob Charlie David (this will work) but (Alice Bob Charlie Alice David) will not work.

  • To do this, we use the sort command, which recognizes duplicates anywhere in the line. eg sort names.txt | uniq

  • free -h : The free command displays memory usage on your system, including RAM and swap.

  • free -hm \=Show memory in a human-readable format and in megabytes.

  • free -hg Show memory in a human-readable format and in gigabytes

  • free -s The -s option in free is used to update the memory output at regular time intervals (in seconds).

  • awk command It reads a file line by line, splits each line into fields (columns), and then performs actions.

    • NOTE : To use awk effectively, the file should have rows and columns. but it is not necessary for it to be in rows and columns

    • example: $1 = first column

    • $2 = second column

    • $0 = whole line

    • awk '{ print $1 }' file.txt Print the first column of a file:

    • awk '{ print $1, $3 }' file.txt Print the first and third column:

    • 2)The awk command is used for log analysis also

    • 192.168.1.5 - - [05/Jul/2025:10:00:01] "GET /index.html HTTP/1.1" 200 512 192.168.1.7 - - [05/Jul/2025:10:00:05] "POST /login HTTP/1.1" 401 128 192.168.1.5 - - [05/Jul/2025:10:00:10] "GET /home HTTP/1.1" 200 1024

    • awk '{ print $1 }' access.log | sort | uniq -c | sort -nr

    • $1 extracts the first column (IP address).

    • sort sorts IPs.

    • uniq -c counts occurrences.

    • sort -nr sorts counts in descending order.

    • wget wget is a command-line tool used to download files from the internet.

    • It works with HTTP, HTTPS, and FTP protocols.

    • /var/log/secure It's a system log file on many Linux systems (especially Red Hat, CentOS, Fedora).

    • It keeps track of security-related messages, such as:

      • Attempts to log in (successful or failed)

      • Use of sudo

      • SSH login attempts

      • Other security events

    • uptime The uptime command tells you how long your system has been running since the last restart. It also shows the current time, the number of users logged in, and the system load averages.

du -sh du stands for Disk Usage.

  • It shows how much disk space a file or directory uses.

  • The options:

    • -s means summary — shows only the total size, not every file inside.

    • -h means human-readable — shows sizes in KB, MB, or GB instead of bytes.

/proc/cpuinfo /proc/cpuinfo is a virtual file in Linux that has detailed information about the CPU(s) on your system.

  • You can read it to find out about your processor(s), such as model, cores, speed, cache, flags, and more.
0
Subscribe to my newsletter

Read articles from kishore kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

kishore kumar
kishore kumar