Linux: The Thing Every Dev Should Know - Part 06

April 7, 2026

chmod command

chmod stands for change mode — used to set permissions (read, write, execute) on files and directories.

chmod 755 file.sh
  • Sets permissions using numeric mode

Permission Basics

  • r → read (4)
  • w → write (2)
  • x → execute (1)

Combined

  • 7 = rwx
  • 5 = r-x
  • 4 = r--

Examples

  1. Make file executable:
chmod 755 script.sh
  1. Read-only file:
chmod 444 file.txt
  1. Private file:
chmod 600 secret.txt

Symbolic Mode

  1. Add execute:
chmod +x script.sh
  1. Remove write:
chmod -w file.txt
  1. Set specific:
chmod u+x file.sh

Why

  • Controls who can access or modify files
  • Critical for security and scripts

Pro tip :)

  • chmod +x is the fastest way to make scripts runnable.
  • Permissions define power — use chmod wisely.

whoami command

whoami shows the current logged-in user.

whoami
  • Outputs your username

Why

  • Verify current user
  • Useful with sudo and permissions
  • Helps in scripts & debugging

Pro tip :)

  • After using sudo, whoami tells you if you're running as root.
  • Always know who you are in the system.

chown command

chown stands for change owner — used to change the owner and group of files or directories.

chown user file.txt
  • Changes owner of file.txt

Examples

  1. Change owner + group:
chown user:group file.txt
  1. Change recursively
chown -R user:group folder/
  1. Using sudo:
sudo chown user file.txt

Why

  • Controls who owns and manages files
  • Important for servers, permissions, deployments

Pro tip :)

  • Use chown -R carefully — it affects all files inside a directory.
  • Ownership defines control — chown lets you set it.

exec command

exec is used to replace the current shell process with another command.

  • No new process is created — it takes over the current one
exec bash
  • Replaces current shell with a new bash session

Examples

  1. Run script in same process:
exec ./script.sh
  1. Redirect output permanently:
exec > output.txt

Why

  • Avoids creating extra processes
  • Useful in scripts, containers, process management

Pro tip :)

  • After exec, there’s no going back — the original process is gone.
  • exec doesn’t run a command — it becomes it.

grep command

grep is used to search for patterns (text) inside files or command output.

grep "error" file.txt
  • Finds lines containing "error"

Uses

  1. Case-insensitive search:
grep -i "error" file.txt
  1. Search recursively:
grep -r "error" .
  1. Show line numbers:
grep -n "error" file.txt

Why

  • Core tool for logs, debugging, filtering data
  • Works perfectly with pipes

Pro tip :)

  • Combine with pipes for power:
ls | grep ".js"

history command

history shows a list of previously executed commands in your terminal.

history
  • Displays command history with line numbers

Uses

  1. Run a previous command:
!123
  1. Search history:
history | grep "git"
  1. Clear history:
history -c

Why

  • Saves time (reuse commands)
  • Helps debugging and tracking actions

Pro tip :)

  • Press Ctrl + R for instant reverse search — fastest way to find past commands.
  • Your past commands are assets — use history to leverage them.

regex

Regex (Regular Expression) is used to search, match, and manipulate text patterns.

Examples

  1. Match exact word:
grep "error" file.txt
  1. Match any digit:
grep "[0-9]" file.txt
  1. Match words starting with “a”:
grep "^a" file.txt

Most used/common

  • . → any character
  • ('*') → 0 or more
  • ('+') → 1 or more
  • ^ → start of line
  • $ → end of line
  • [] → character set

Why

  • Powerful text filtering
  • Used in:
    • grep
    • validation
    • parsing logs/data

Pro tip :)

  • Regex looks complex, but mastering a few patterns covers most real-world use cases.
  • Regex lets you search smarter, not harder.
GitHub
LinkedIn
X