Basic Linux Commands: Difference between revisions
Jump to navigation
Jump to search
Line 9: | Line 9: | ||
! Command !! Description !! Usage | ! Command !! Description !! Usage | ||
|- | |- | ||
| [[#ex-pwd|<code>pwd</code>]] || Print working directory || <code>pwd | | [[#ex-pwd|<code>pwd</code>]] || Print working directory || <code>pwd</code> | ||
|- | |- | ||
| [[#ex-cd|<code>cd</code>]] || Change directory || <code>cd [DIRECTORY]</code> | | [[#ex-cd|<code>cd</code>]] || Change directory || <code>cd [DIRECTORY]</code> | ||
|- | |- | ||
| [[#ex-ls|<code>ls</code>]] || List directory contents || <code>ls [OPTIONS] [FILE...]</code> | | [[#ex-ls|<code>ls</code>]] || List directory contents || <code>ls [OPTIONS] [FILE...]</code> | ||
|- | |||
| [[#ex-tree|<code>tree</code>]] || Recursively list directories as tree || <code>tree [DIRECTORY]</code> | |||
|- | |- | ||
| [[#ex-mkdir|<code>mkdir</code>]] || Create directory || <code>mkdir [OPTIONS] DIRECTORY</code> | | [[#ex-mkdir|<code>mkdir</code>]] || Create directory || <code>mkdir [OPTIONS] DIRECTORY</code> | ||
Line 28: | Line 30: | ||
|- | |- | ||
| [[#ex-ln|<code>ln</code>]] || Create hard or symbolic links || <code>ln [OPTIONS] TARGET LINK_NAME</code> | | [[#ex-ln|<code>ln</code>]] || Create hard or symbolic links || <code>ln [OPTIONS] TARGET LINK_NAME</code> | ||
|- | |||
| [[#ex-stat|<code>stat</code>]] || Display detailed file information || <code>stat FILE</code> | |||
|- | |||
| [[#ex-file|<code>file</code>]] || Detect file type || <code>file FILE</code> | |||
|- | |||
| [[#ex-basename|<code>basename</code>]] || Strip directory and suffix from filename || <code>basename PATH</code> | |||
|- | |||
| [[#ex-dirname|<code>dirname</code>]] || Extract directory part of file path || <code>dirname PATH</code> | |||
|- | |- | ||
| [[#ex-find|<code>find</code>]] || Search for files and directories || <code>find [PATH] [OPTIONS] [EXPRESSION]</code> | | [[#ex-find|<code>find</code>]] || Search for files and directories || <code>find [PATH] [OPTIONS] [EXPRESSION]</code> | ||
|- | |||
| [[#ex-locate|<code>locate</code>]] || Find files using database (faster than find) || <code>locate FILENAME</code> | |||
|- | |- | ||
| [[#ex-chmod|<code>chmod</code>]] || Change file permissions || <code>chmod [OPTIONS] MODE FILE</code> | | [[#ex-chmod|<code>chmod</code>]] || Change file permissions || <code>chmod [OPTIONS] MODE FILE</code> | ||
Line 42: | Line 54: | ||
|- | |- | ||
| [[#ex-gzip|<code>gzip</code>]] || Compress files using Gzip || <code>gzip FILE</code> | | [[#ex-gzip|<code>gzip</code>]] || Compress files using Gzip || <code>gzip FILE</code> | ||
|- | |||
| [[#ex-gunzip|<code>gunzip</code>]] || Decompress Gzip files || <code>gunzip FILE.gz</code> | |||
|- | |- | ||
| [[#ex-zip|<code>zip</code>]] || Compress files into ZIP archive || <code>zip ARCHIVE.zip FILES</code> | | [[#ex-zip|<code>zip</code>]] || Compress files into ZIP archive || <code>zip ARCHIVE.zip FILES</code> | ||
|- | |||
| [[#ex-unzip|<code>unzip</code>]] || Extract ZIP archive || <code>unzip ARCHIVE.zip</code> | |||
|- | |||
| [[#ex-dd|<code>dd</code>]] || Copy and convert data (low-level) || <code>dd if=SOURCE of=DEST bs=BLOCKSIZE</code> | |||
|- | |||
| [[#ex-mount|<code>mount</code>]] || Mount a filesystem || <code>mount [DEVICE] [MOUNTPOINT]</code> | |||
|- | |||
| [[#ex-umount|<code>umount</code>]] || Unmount a filesystem || <code>umount [MOUNTPOINT]</code> | |||
|} | |} | ||
=== Viewing & Text Processing === | === Viewing & Text Processing === |
Revision as of 09:04, 13 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
|
cd |
Change directory | cd [DIRECTORY]
|
ls |
List directory contents | ls [OPTIONS] [FILE...]
|
tree |
Recursively list directories as tree | tree [DIRECTORY]
|
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...
|
touch |
Create empty file or update timestamp | touch FILENAME
|
ln |
Create hard or symbolic links | ln [OPTIONS] TARGET LINK_NAME
|
stat |
Display detailed file information | stat FILE
|
file |
Detect file type | file FILE
|
basename |
Strip directory and suffix from filename | basename PATH
|
dirname |
Extract directory part of file path | dirname PATH
|
find |
Search for files and directories | find [PATH] [OPTIONS] [EXPRESSION]
|
locate |
Find files using database (faster than find) | locate FILENAME
|
chmod |
Change file permissions | chmod [OPTIONS] MODE FILE
|
chown |
Change file ownership (user) | chown [OPTIONS] USER FILE
|
chgrp |
Change group ownership | chgrp [OPTIONS] GROUP FILE
|
umask |
Set default file permission mask | umask [MASK]
|
tar |
Archive files into tarball | tar -czf ARCHIVE.tar.gz FILES
|
gzip |
Compress files using Gzip | gzip FILE
|
gunzip |
Decompress Gzip files | gunzip FILE.gz
|
zip |
Compress files into ZIP archive | zip ARCHIVE.zip FILES
|
unzip |
Extract ZIP archive | unzip ARCHIVE.zip
|
dd |
Copy and convert data (low-level) | dd if=SOURCE of=DEST bs=BLOCKSIZE
|
mount |
Mount a filesystem | mount [DEVICE] [MOUNTPOINT]
|
umount |
Unmount a filesystem | umount [MOUNTPOINT]
|
Viewing & Text Processing
Command | Description | Usage |
---|---|---|
cat |
Concatenate & display files | cat [OPTIONS] FILE...
|
less |
Paginate large files | less FILE
|
more |
View file one page at a time | more 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
|
awk |
Pattern scanning & processing language | awk 'pattern { action }' FILE
|
sed |
Stream editor for filtering & transforming text | sed [OPTIONS] 'SCRIPT' FILE
|
cut |
Remove sections from each line | cut [OPTIONS] FILE
|
tr |
Translate or delete characters | tr SET1 SET2
|
sort |
Sort lines of text files | sort [OPTIONS] FILE
|
uniq |
Filter out repeated lines | uniq [OPTIONS] FILE
|
wc |
Count lines, words, bytes | wc [OPTIONS] FILE
|
nl |
Number lines of a file | nl FILE
|
diff |
Show differences between files | diff FILE1 FILE2
|
tee |
Read from stdin and write to file and stdout | tee 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]
|
du |
Show disk usage for files/directories | du [OPTIONS] [PATH]
|
uptime |
Show how long the system has been running | uptime
|
uname |
System information (kernel, OS, architecture) | uname -a
|
hostname |
Show or set system hostname | hostname
|
date |
Display or set system date/time | date
|
cal |
Display a calendar | cal
|
env |
Show environment variables | env
|
set |
Display shell variables and functions | set
|
history |
List previously executed commands | history
|
ps |
Display running processes | ps aux
|
top |
Real-time system process monitor | top
|
kill |
Terminate process by PID | kill [-9] PID
|
pkill |
Kill processes by name | pkill PROCESS_NAME
|
pgrep |
Search for processes by name | pgrep PROCESS_NAME
|
w |
Show who is logged in and what they are doing | w
|
who |
Show who is logged in | who
|
last |
Show login history | last
|
free |
Show memory usage | free -h
|
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