Basic Linux Commands: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 9: | Line 9: | ||
! Command !! Description !! Usage | ! Command !! Description !! Usage | ||
|- | |- | ||
| [[#ex-pwd|<code>pwd</code>]] || Print working directory || pwd [OPTIONS] | | [[#ex-pwd|<code>pwd</code>]] || Print working directory || <code>pwd [OPTIONS]</code> | ||
|- | |- | ||
| [[#ex-cd|<code>cd</code>]] || Change directory || cd [DIRECTORY] | | [[#ex-cd|<code>cd</code>]] || Change directory || <code>cd [DIRECTORY]</code> | ||
|- | |- | ||
| [[#ex-ls|<code>ls</code>]] || List directory contents || ls [OPTIONS] [FILE...] | | [[#ex-ls|<code>ls</code>]] || List directory contents || <code>ls [OPTIONS] [FILE...]</code> | ||
|- | |- | ||
| [[#ex-mkdir|<code>mkdir</code>]] || Create directory || mkdir [OPTIONS] DIRECTORY | | [[#ex-mkdir|<code>mkdir</code>]] || Create directory || <code>mkdir [OPTIONS] DIRECTORY</code> | ||
|- | |- | ||
| [[#ex-rmdir|<code>rmdir</code>]] || Remove empty directory || rmdir DIRECTORY | | [[#ex-rmdir|<code>rmdir</code>]] || Remove empty directory || <code>rmdir DIRECTORY</code> | ||
|- | |- | ||
| [[#ex-cp|<code>cp</code>]] || Copy files or directories || cp SOURCE DEST | | [[#ex-cp|<code>cp</code>]] || Copy files or directories || <code>cp SOURCE DEST</code> | ||
|- | |- | ||
| [[#ex-mv|<code>mv</code>]] || Move or rename files/directories || mv SOURCE DEST | | [[#ex-mv|<code>mv</code>]] || Move or rename files/directories || <code>mv SOURCE DEST</code> | ||
|- | |- | ||
| [[#ex-rm|<code>rm</code>]] || Delete files or directories || rm [OPTIONS] FILE... | | [[#ex-rm|<code>rm</code>]] || Delete files or directories || <code>rm [OPTIONS] FILE...</code> | ||
|} | |} | ||
Line 30: | Line 30: | ||
! Command !! Description !! Usage | ! Command !! Description !! Usage | ||
|- | |- | ||
| [[#ex-cat|<code>cat</code>]] || Concatenate & display files || cat [OPTIONS] FILE... | | [[#ex-cat|<code>cat</code>]] || Concatenate & display files || <code>cat [OPTIONS] FILE...</code> | ||
|- | |- | ||
| [[#ex-less|<code>less</code>]] || Paginate large files || less FILE | | [[#ex-less|<code>less</code>]] || Paginate large files || <code>less FILE</code> | ||
|- | |- | ||
| [[#ex-head|<code>head</code>]] || Show first lines of a file || head [OPTIONS] FILE | | [[#ex-head|<code>head</code>]] || Show first lines of a file || <code>head [OPTIONS] FILE</code> | ||
|- | |- | ||
| [[#ex-tail|<code>tail</code>]] || Show last lines / follow file || tail [OPTIONS] FILE | | [[#ex-tail|<code>tail</code>]] || Show last lines / follow file || <code>tail [OPTIONS] FILE</code> | ||
|- | |- | ||
| [[#ex-grep|<code>grep</code>]] || Search for patterns || grep [OPTIONS] PATTERN FILE | | [[#ex-grep|<code>grep</code>]] || Search for patterns || <code>grep [OPTIONS] PATTERN FILE</code> | ||
|} | |} | ||
Line 45: | Line 45: | ||
! Command !! Description !! Usage | ! Command !! Description !! Usage | ||
|- | |- | ||
| [[#ex-whoami|<code>whoami</code>]] || Show current user || whoami | | [[#ex-whoami|<code>whoami</code>]] || Show current user || <code>whoami</code> | ||
|- | |- | ||
| [[#ex-id|<code>id</code>]] || Display user/group IDs || id [USERNAME] | | [[#ex-id|<code>id</code>]] || Display user/group IDs || <code>id [USERNAME]</code> | ||
|- | |- | ||
| [[#ex-df|<code>df</code>]] || Disk usage overview || df [OPTIONS] | | [[#ex-df|<code>df</code>]] || Disk usage overview || <code>df [OPTIONS]</code> | ||
|- | |- | ||
| [[#ex-history|<code>history</code>]] || List previously executed commands || history | | [[#ex-history|<code>history</code>]] || List previously executed commands || <code>history</code> | ||
|} | |} | ||
Line 58: | Line 58: | ||
! Command !! Description !! Usage | ! Command !! Description !! Usage | ||
|- | |- | ||
| [[#ex-ping|<code>ping</code>]] || Test network connectivity (ICMP) || ping [OPTIONS] DESTINATION | | [[#ex-ping|<code>ping</code>]] || Test network connectivity (ICMP) || <code>ping [OPTIONS] DESTINATION</code> | ||
|- | |- | ||
| [[#ex-curl|<code>curl</code>]] || Retrieve data from URLs / APIs || curl [OPTIONS] URL | | [[#ex-curl|<code>curl</code>]] || Retrieve data from URLs / APIs || <code>curl [OPTIONS] URL</code> | ||
|- | |- | ||
| [[#ex-ssh|<code>ssh</code>]] || Secure remote shell & tunnelling || ssh [OPTIONS] USER@HOST | | [[#ex-ssh|<code>ssh</code>]] || Secure remote shell & tunnelling || <code>ssh [OPTIONS] USER@HOST</code> | ||
|} | |} | ||
Line 69: | Line 69: | ||
! Command !! Description !! Usage | ! Command !! Description !! Usage | ||
|- | |- | ||
| [[#ex-man|<code>man</code>]] || Read manual pages || man COMMAND | | [[#ex-man|<code>man</code>]] || Read manual pages || <code>man COMMAND</code> | ||
|- | |- | ||
| [[#ex-echo|<code>echo</code>]] || Display text / variables || echo [STRING] | | [[#ex-echo|<code>echo</code>]] || Display text / variables || <code>echo [STRING]</code> | ||
|} | |||
|} | |} | ||
Revision as of 18:51, 12 May 2025
Linux Commands
Linux command‑line tools are the backbone of reconnaissance, exploitation, and post‑exploitation on Unix‑like systems.
Common Commands
Command | Description | Usage |
---|---|---|
pwd |
Print working directory | pwd [OPTIONS]
|
cd |
Change directory | cd [DIRECTORY]
|
ls |
List directory contents | ls [OPTIONS] [FILE...]
|
mkdir |
Create directory | mkdir [OPTIONS] DIRECTORY
|
rmdir |
Remove empty directory | rmdir DIRECTORY
|
cp |
Copy files or directories | cp SOURCE DEST
|
mv |
Move or rename files/directories | mv SOURCE DEST
|
rm |
Delete files or directories | rm [OPTIONS] FILE...
|
Viewing & Text Processing
Command | Description | Usage |
---|---|---|
cat |
Concatenate & display files | cat [OPTIONS] FILE...
|
less |
Paginate large files | less FILE
|
head |
Show first lines of a file | head [OPTIONS] FILE
|
tail |
Show last lines / follow file | tail [OPTIONS] FILE
|
grep |
Search for patterns | grep [OPTIONS] PATTERN FILE
|
System & User Info
Command | Description | Usage |
---|---|---|
whoami |
Show current user | whoami
|
id |
Display user/group IDs | id [USERNAME]
|
df |
Disk usage overview | df [OPTIONS]
|
history |
List previously executed commands | history
|
Networking
Command | Description | Usage |
---|---|---|
ping |
Test network connectivity (ICMP) | ping [OPTIONS] DESTINATION
|
curl |
Retrieve data from URLs / APIs | curl [OPTIONS] URL
|
ssh |
Secure remote shell & tunnelling | ssh [OPTIONS] USER@HOST
|
Help & Documentation
Command | Description | Usage |
---|---|---|
man |
Read manual pages | man COMMAND
|
echo |
Display text / variables | echo [STRING]
|
|}
Examples
Print Working Directory
pwd
Change Directory
cd /var/www
ls -la
Create Directory
mkdir backups
Remove Empty Directory
rmdir backups
Copy File
cp secrets.txt /tmp/secrets.bak
Move & Rename
mv old.log archive/old.log
Force‑Delete Directory
rm -rf /tmp/testdir
Show File Contents
cat /etc/passwd | grep ":/bin/bash"
View Large Log
less /var/log/auth.log
First 10 Lines
head -n 10 notes.txt
Follow File Growth
tail -f /var/log/nginx/access.log
Search Pattern
grep -R \"passwd\" /etc
Current User
whoami
User & Group IDs
id
Human‑Readable Disk Usage
df -h
Show Last 20 Commands
history | tail -n 20
Ping Host 4 Times
ping -c 4 example.com
Download Web Page
curl -o index.html http://example.com
SSH on Custom Port
ssh -p 2222 user@target
Read Manual Page
man ssh
Write to File
echo \"hacked\" > /tmp/proof.txt