Fundamentals 11 min read

Essential Linux Commands Every Developer Should Master

This guide walks through a collection of frequently used Linux shell commands—grep, custom alias shortcuts, pwd, find, history, od, and for loops—explaining their common scenarios, key options, example usages, and handy tricks to boost productivity in everyday development and scripting tasks.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Essential Linux Commands Every Developer Should Master

grep

The grep command is a core text‑processing tool in Linux. Its basic syntax is grep [OPTIONS] PATTERN [FILE...]. Two typical use‑cases are demonstrated:

Search recursively for a string, e.g., grep -rni "pthread" * (options: -r recursive, -n line numbers, -i case‑insensitive).

Find a process ID by piping ps -aux through grep and filtering out the grep process itself with -v, then extracting the PID using awk '{print $2}'.

These patterns are common in scripts for checking whether an instance is already running.

Custom alias q to show exit status

Linux stores the exit status of the last command in $? (0 means success). To avoid typing the long expression repeatedly, an alias can be added to .bashrc:

alias ll='ls -lF'
alias la='ls -A'
alias l='ls -CF'
alias q='echo $?'

After reloading the shell ( source .bashrc or . .bashrc), typing q instantly reports whether the previous command succeeded.

pwd

The pwd command prints the current working directory. When the path is deep, the prompt can become unwieldy. Changing the prompt definition in .bashrc from \w (full path) to \W (basename only) shortens the displayed path, freeing space while still allowing pwd to show the full path when needed.

find

find

locates files matching given criteria. Common examples:

Find a header file: find ./ -name xxx.h Find all text files: find ./ -name "*.txt" This is especially handy when a Makefile fails to locate a header.

history

The history command lists previously executed commands. It can be filtered, e.g., history | grep gcc, to show only commands containing a keyword. Additionally, pressing Ctrl+R initiates a reverse incremental search, allowing you to type the beginning of a past command (e.g., gcc -m) and quickly retrieve the full command.

od

The od (octal dump) utility displays the raw contents of a file, useful for inspecting binary data. Example to view the first 52 bytes of an ELF executable in hexadecimal: od -Ax -t x1 -N 52 main Options explained:

-Ax: show addresses in hexadecimal (use -Ad for decimal). -t x1: display one byte per column in hex. -N 52: limit output to 52 bytes.

The output reveals the ELF magic number 7f 45 4c 46 (“ELF”).

for loops

The for construct iterates over items in shell scripts. A typical use‑case is batch renaming files with sequential numbers:

i=0
for x in *.mp4; do
  n=$(printf "%02d" "$i")
  mv "$x" "$n.mp4"
  i=$((i+1))
done

If filenames contain spaces, setting IFS='\n' before the loop prevents errors. The script can be packaged into a reusable file_rename.sh that accepts an optional file‑type argument:

#!/bin/bash
if [ $# -eq 0 ]; then
  suffix=mp4
else
  suffix=$1
fi
IFS='
'
i=0
for x in *.$suffix; do
  n=$(printf "%02d" "$i")
  mv "$x" "$n.$suffix"
  i=$((i+1))
done

Running ./file_rename.sh renames all mp4 files; providing another extension (e.g., png) processes that type instead.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxcommand-lineScriptingBashGrep
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.