Skip to main content

Linux Command Syntax

Introduction

Every Linux command follows a specific structure. General syntax:

command [options] [arguments]

Example:

ls -la /home

Breaking Down Commands

Example:

cp file.txt backup.txt

Components:

PartMeaning
cpCommand
file.txtSource argument
backup.txtDestination argument

Commands

Commands are executable programs. Examples:

ls
pwd
cp
mv
mkdir
grep

Arguments

Arguments provide information to commands. Example:

cd Documents

Argument:

Documents

Options / Flags

Flags modify command behavior. Example:

ls -l

Displays long listing.

Multiple Flags

ls -lah

Equivalent to:

ls -l -a -h

Long Options

Many commands support long options. Example:

ls --all

Command Examples


Example 1

mkdir Projects

Command:

mkdir

Argument:

Projects

Example 2

rm -rf test
PartMeaning
rmRemove command
-rRecursive
-fForce
testTarget

Command Chaining


;

Always run next command.

pwd ; ls

&&

Run next command only if previous succeeds.

mkdir test && cd test

||

Run next command if previous fails.

cd folder || echo "Folder not found"

Pipelines

Symbol:

|

Pass output from one command to another. Example:

cat file.txt | grep admin

Redirection


>

Overwrite file.

echo hello > file.txt

>>

Append output.

echo world >> file.txt

2>

Redirect errors.

command 2> errors.txt

&>

Redirect everything.

command &> output.txt

Exit Codes

Linux commands return exit status. Check:

echo $?

Example:

0 → Success
1 → Error

Real Examples

Search logs:

cat /var/log/syslog | grep ssh

Create server:

mkdir pocketmine && cd pocketmine

Summary

You learned: ✅ Commands ✅ Arguments ✅ Flags ✅ Pipelines ✅ Redirection ✅ Exit Codes These concepts are used in every Linux command.