Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Essential Linux Commands and System Fundamentals

Tech May 10 3

Program Components

A typical program consists of:

  • Binary executables
  • Shared libraries (non-executable on their own, only loaded when called)
  • Configuration files
  • Documentation or help files

Command Structure

The general syntax is: COMMAND [OPTIONS] [ARGUMENTS]

Command Execution

Commands are executable binaries that may depend on shared libraries. Common locations include:

  • User commands: /bin, /usr/bin, /usr/local/bin
  • Administrative commands: /sbin, /usr/sbin, /usr/local/sbin
  • Libraries (32-bit): /lib, /usr/lib, /usr/local/lib
  • Libraries (64-bit): /lib64, /usr/lib64, /usr/local/lib64

Not all commands correspond to a file in these directories—some are shell built-ins.

The PATH environment variable defines the search order for command resolution (left to right). View it with:

echo $PATH

Options

  • Short form: -l, -d; combinable as -ld
  • Long form: --help, --human-readable; not combinable
  • Some options accept parameters (e.g., -t 1909131212)

Arguments

Specify targets of the command (e.g., files or directories). Multiple arguments are space-separated:

ls -ld /var /etc

Accessing Help

  • Built-in commands: help COMMAND
  • External commands:
    • COMMAND --help
    • Manual pages: man COMMAND

Manual sections:

  1. User commands
  2. System calls
  3. Library functions
  4. Special files
  5. File formats
  6. Administration tools

Within man, navigation includes:

  • Space: next page
  • b: previous page
  • /keyword: search forward
  • ?keyword: search backward
  • q: quit

Core Commands

Directory Navigation

  • cd: home directory
  • cd ~user: user’s home
  • cd -: toggle between last and current directory

Relevant variables:

  • $PWD: current directory
  • $OLDPWD: previous directory

Listing Files (ls)

Common flags:

  • -a: show hidden files
  • -l: detailed listing
  • -h: human-readable sizes
  • -d: list directory itself
  • -R: recursive listing

Example output:

-rw-r--r--. 1 root root 8957 Oct 14 19:34 boot.log

Breakdown:

  • -: regular file (d = directory, l = symlink, etc.)
  • rw-r--r--: permissions for owner/group/others
  • 1: hard link count
  • root root: owner and group
  • 8957: size in bytes
  • Timestamp and filename

File Viewing

  • cat file: output entire file
    • -n: line numbers
    • -E: show $ at line ends
  • tac file: reverse line order
  • head -n 10 file: first 10 lines
  • tail -n 10 file: last 10 lines
  • less file: interactive paging (preferred over more)

Echo and Quoting

echo -e "line1\nline2"
  • -e: interpret escape sequences
  • Single quotes '...': literal (no variable expansion)
  • Double quotes "...": allow variable substitution
  • ${VAR}: explicit variable reference

System Control

  • Shutdown: shutdown -h now
  • Reboot: shutdown -r +5 "Update"
  • Cancel: shutdown -c

Time Management

  • Hardware clock ↔ system clock:
    • hwclock --hctosys (sync system from hardware)
    • hwclock --systohc (sync hardware from system)

Command Location and Aliasing

  • which ls: shows full path of executable
  • whereis bash: locates binary, source, and manual
  • Aliases (session-only):
    alias ll='ls -l'
    unalias ll
    

Filesystem Hierarchy Standard (FHS)

Key directories:

  • /bin, /sbin: essential binaries
  • /boot: kernel and bootloader files
  • /dev: device files (block/character)
  • /etc: static configuration
  • /home: user home directories
  • /root: admin home
  • /lib, /lib64: shared libraries
  • /media, /mnt: mount points
  • /opt: optional software
  • /tmp: temporary files (world-writable)
  • /usr: read-only shared data (bin, lib, share, local, etc.)
  • /var: variable data (logs, spools, caches)
  • /proc, /sys: virtual filesystems exposing kernel/process info

File Types

  • -: regular file
  • d: directory
  • b: block device
  • c: character device
  • l: symbolic link
  • p: named pipe
  • s: socket

Devices use major/minor numbers to identify type and instance.

Bash Features

Command History

  • history: list recent commands
  • !5: re-run command #5
  • !ssh: re-run last command starting with "ssh"
  • Esc + .: insert last argument of previous command

Brace Expansion

  • mkdir -p /tmp/x/{y1/{a,b},y2} → creates nested dirs
  • touch {a,b}_{x,y}.txta_x.txt, a_y.txt, b_x.txt, b_y.txt

Exit Status

  • Success: 0
  • Failure: 1–255
  • Check with: echo $?

Keyboard Shortcuts

  • Ctrl+a: beginning of line
  • Ctrl+e: end of line
  • Ctrl+u: delete to start
  • Ctrl+k: delete to end
  • Ctrl+l: clear screen

File Operations

Metadata Inspection

  • stat file: shows access (atime), modify (mtime), and change (ctime) timestamps

Timestamp Modification

  • touch -a file: update access time
  • touch -m file: update modify time
  • touch -t [[CC]YY]MMDDhhmm[.ss] file

Copying (cp)

  • Single file: cp src dest
  • Recursive: cp -r dir1 dir2
  • Archive mode (preserves all attributes): cp -a src dest
  • Interactive: cp -i src dest

Moving/Renaming (mv)

  • mv old new
  • Supports -i (prompt) and -f (force)

Deletion (rm)

  • Files: rm file
  • Directories: rm -r dir
  • Forceful removal: rm -rf dir

⚠️ Caution: rm -rf /* is catastrophic. Prefer moving files to a trash directory instead of immediate deletion.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.