Linux Command Structure

πŸ”Ή Overview

  • A Linux command typically consists of:

    • Command name

    • Options (also called flags or switches)

    • Arguments

  • Basic syntax:

    command [options] [arguments]


Example Command

ping -c 1 8.8.8.8
  • ping β†’ Command name

  • -c β†’ Option (sends a specified number of packets)

  • 1 β†’ Option value (only 1 packet)

  • 8.8.8.8 β†’ Argument (Google's public DNS server)

βœ… Used to test network connectivity.
πŸ’‘ If you don’t have internet access, try ping 127.0.0.1 (loopback interface).

Command Structure Breakdown

Component

Description

Command Name

Starts the line; ends at first whitespace

Options

Begin with a hyphen - or double hyphen --

Option Values

Immediately follow the option

Arguments

Come after options; provide input to the command

  • Whitespace matters: Components are separated by one or more spaces.

  • Positioning: Options usually come between the command and its arguments.

⚠️ While some commands allow flexible placement of options, the course follows the standard convention:

  • β€œCommand β†’ Options β†’ Arguments”

Optional vs Required Options/Arguments

  • Some commands require arguments:

  • ping         # ❌ Error: "destination address required"
    ping 8.8.8.8 # βœ…
    
  • Others can run without arguments:

  • ls       # βœ… Lists current directory contents
    ls -l    # βœ… Long listing format
    ls -l /etc # βœ… Lists `/etc` in long format
    

Option Formats

Format

Example

Description

Short

-l, -a

Single-character options with single -

Long

--all

Word-based options with double --

Combined

-la

Multiple short options grouped

Mixed

-la --human

Short and long options together

πŸ“ ls -a and ls --all are equivalent (show hidden files).


df Command Example

  • Displays filesystem and disk usage:
df              # Basic output
df -h           # Human-readable format
df -hT          # Combined short options
df -hT --total  # Adds total disk usage (long option)

βœ… Summary

  • Mastering command structure is essential for Linux beginners.

  • Components:

    • Command

    • Options (short -x, long --xyz)

    • Arguments

  • Stick to the standard format:

command [options] [arguments]

Not all commands behave the same; experiment and read help pages (man or --help) to understand specific command behaviour

Updated on