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:
| Part | Meaning |
|---|---|
| cp | Command |
| file.txt | Source argument |
| backup.txt | Destination 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
| Part | Meaning |
|---|---|
| rm | Remove command |
| -r | Recursive |
| -f | Force |
| test | Target |
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.