Basic Linux Commands: Difference between revisions

From HackOps
Jump to navigation Jump to search
No edit summary
Line 24: Line 24:
|-
|-
| [[#ex-rm|<code>rm</code>]] || Delete files or directories || <code>rm [OPTIONS] FILE...</code>
| [[#ex-rm|<code>rm</code>]] || Delete files or directories || <code>rm [OPTIONS] FILE...</code>
|-
| [[#ex-touch|<code>touch</code>]] || Create empty file or update timestamp || <code>touch FILENAME</code>
|-
[[#ex-ln|<code>ln</code>]] || Create hard or symbolic links || <code>ln [OPTIONS] TARGET LINK_NAME</code>
|-
[[#ex-find|<code>find</code>]] || Search for files and directories || <code>find [PATH] [OPTIONS] [EXPRESSION]</code>
|-
[[#ex-chmod|<code>chmod</code>]] || Change file permissions || <code>chmod [OPTIONS] MODE FILE</code>
|-
[[#ex-chown|<code>chown</code>]] || Change file ownership (user) || <code>chown [OPTIONS] USER FILE</code>
|-
[[#ex-chgrp|<code>chgrp</code>]] || Change group ownership || <code>chgrp [OPTIONS] GROUP FILE</code>
|-
[[#ex-umask|<code>umask</code>]] || Set default file permission mask || <code>umask [MASK]</code>
|-
[[#ex-tar|<code>tar</code>]] || Archive files into tarball || <code>tar -czf ARCHIVE.tar.gz FILES</code>
|-
[[#ex-gzip|<code>gzip</code>]] || Compress files using Gzip || <code>gzip FILE</code>
|-
[[#ex-zip|<code>zip</code>]] || Compress files into ZIP archive || <code>zip ARCHIVE.zip FILES</code>
|}
|}


Line 52: Line 72:
|-
|-
| [[#ex-history|<code>history</code>]] || List previously executed commands || <code>history</code>
| [[#ex-history|<code>history</code>]] || List previously executed commands || <code>history</code>
|-
| [[#ex-ps|<code>ps</code>]] || Display running processes || <code>ps aux</code>
|-
| [[#ex-top|<code>top</code>]] || Real-time system process monitor || <code>top</code>
|-
| [[#ex-kill|<code>kill</code>]] || Terminate process by PID || <code>kill [-9] PID</code>
|-
| [[#ex-pkill|<code>pkill</code>]] || Kill processes by name || <code>pkill PROCESS_NAME</code>
|-
| [[#ex-pgrep|<code>pgrep</code>]] || Search for processes by name || <code>pgrep PROCESS_NAME</code>
|}
|}



Revision as of 08:56, 13 May 2025

Linux Commands

Linux command‑line tools are the backbone of reconnaissance, exploitation, and post‑exploitation on Unix‑like systems.

Common Commands

Navigation & File Management

ln || Create hard or symbolic links || ln [OPTIONS] TARGET LINK_NAMEfind || Search for files and directories || find [PATH] [OPTIONS] [EXPRESSION]chmod || Change file permissions || chmod [OPTIONS] MODE FILEchown || Change file ownership (user) || chown [OPTIONS] USER FILEchgrp || Change group ownership || chgrp [OPTIONS] GROUP FILEumask || Set default file permission mask || umask [MASK]tar || Archive files into tarball || tar -czf ARCHIVE.tar.gz FILESgzip || Compress files using Gzip || gzip FILEzip || Compress files into ZIP archive || zip ARCHIVE.zip FILES
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...
touch Create empty file or update timestamp touch FILENAME

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
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

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

↑ Commands

Change Directory

cd /var/www

↑ Commands

List All Files (long + hidden)

ls -la

↑ Commands

Create Directory

mkdir backups

↑ Commands

Remove Empty Directory

rmdir backups

↑ Commands

Copy File

cp secrets.txt /tmp/secrets.bak

↑ Commands

Move & Rename

mv old.log archive/old.log

↑ Commands

Force‑Delete Directory

rm -rf /tmp/testdir

↑ Commands

Show File Contents

cat /etc/passwd | grep ":/bin/bash"

↑ Commands

View Large Log

less /var/log/auth.log

↑ Commands

First 10 Lines

head -n 10 notes.txt

↑ Commands

Follow File Growth

tail -f /var/log/nginx/access.log

↑ Commands

Search Pattern

grep -R \"passwd\" /etc

↑ Commands

Current User

whoami

↑ Commands

User & Group IDs

id

↑ Commands

Human‑Readable Disk Usage

df -h

↑ Commands

Show Last 20 Commands

history | tail -n 20

↑ Commands

Ping Host 4 Times

ping -c 4 example.com

↑ Commands

Download Web Page

curl -o index.html http://example.com

↑ Commands

SSH on Custom Port

ssh -p 2222 user@target

↑ Commands

Read Manual Page

man ssh

↑ Commands

Write to File

echo \"hacked\" > /tmp/proof.txt

↑ Commands

See Also