Basic Linux Commands: Difference between revisions

From HackOps
Jump to navigation Jump to search
Created page with "= Linux Commands = '''Linux command-line tools''' are the building blocks of interaction, enumeration, file manipulation, and system control during any hacking operation. This page breaks down commonly used Linux commands, their usage, categories, and real-world hacking relevance. == <span id="basics"></span>Essential Commands == === Navigation === {| class="wikitable" ! Command !! Description !! Example |- | <code>pwd</code> || Show current working directory || <code..."
 
No edit summary
Line 1: Line 1:
= Linux Commands =
= Linux Commands =


'''Linux command-line tools''' are the building blocks of interaction, enumeration, file manipulation, and system control during any hacking operation. This page breaks down commonly used Linux commands, their usage, categories, and real-world hacking relevance.
'''Linux command‑line tools''' are the backbone of reconnaissance, exploitation, and post‑exploitation on Unix‑like systems. This page mirrors the *Nmap* layout so each command in the tables links to a live example, and every example links back to the command list for quick navigation.


== <span id="basics"></span>Essential Commands ==
== <span id="commands"></span>Common Commands ==


=== Navigation ===
=== Navigation & File Management ===
{| class="wikitable"
{| class="wikitable"
! Command !! Description !! Example
! Command !! Description
|-
|-
| <code>pwd</code> || Show current working directory || <code>pwd</code>
| [[#ex-pwd|<code>pwd</code>]] || Print working directory
|-
|-
| <code>cd</code> || Change directory || <code>cd /etc</code>
| [[#ex-cd|<code>cd</code>]] || Change directory
|-
|-
| <code>mkdir</code> || Create directory || <code>mkdir testdir</code>
| [[#ex-ls|<code>ls</code>]] || List directory contents
|-
|-
| <code>rmdir</code> || Remove empty directory || <code>rmdir testdir</code>
| [[#ex-mkdir|<code>mkdir</code>]] || Create directory
|-
| [[#ex-rmdir|<code>rmdir</code>]] || Remove empty directory
|-
| [[#ex-cp|<code>cp</code>]] || Copy files or directories
|-
| [[#ex-mv|<code>mv</code>]] || Move or rename files/directories
|-
| [[#ex-rm|<code>rm</code>]] || Delete files or directories
|}
|}


=== File Operations ===
=== Viewing & Text Processing ===
{| class="wikitable"
{| class="wikitable"
! Command !! Description !! Example
! Command !! Description
|-
| [[#ex-cat|<code>cat</code>]] || Concatenate & display files
|-
|-
| <code>ls</code> || List contents || <code>ls -la</code>
| [[#ex-less|<code>less</code>]] || Paginate large files
|-
|-
| <code>cat</code> || View file contents || <code>cat /etc/passwd</code>
| [[#ex-head|<code>head</code>]] || Show first lines of a file
|-
|-
| <code>less</code> || Scrollable file viewer || <code>less file.txt</code>
| [[#ex-tail|<code>tail</code>]] || Show last lines / follow file
|-
|-
| <code>head</code> || Show first lines || <code>head -n 10 log.txt</code>
| [[#ex-grep|<code>grep</code>]] || Search for patterns
|}
 
=== System & User Info ===
{| class="wikitable"
! Command !! Description
|-
|-
| <code>tail</code> || Show last lines || <code>tail -f log.txt</code>
| [[#ex-whoami|<code>whoami</code>]] || Show current user
|-
|-
| <code>cp</code> || Copy file || <code>cp file.txt /tmp/</code>
| [[#ex-id|<code>id</code>]] || Display user/group IDs
|-
|-
| <code>mv</code> || Move or rename file || <code>mv old.txt new.txt</code>
| [[#ex-df|<code>df</code>]] || Disk usage overview
|-
|-
| <code>rm</code> || Delete file || <code>rm secrets.txt</code>
| [[#ex-history|<code>history</code>]] || List previously executed commands
|}
|}


=== User Management ===
=== Networking ===
{| class="wikitable"
{| class="wikitable"
! Command !! Description !! Example
! Command !! Description
|-
|-
| <code>whoami</code> || Print current user || <code>whoami</code>
| [[#ex-ping|<code>ping</code>]] || Test network connectivity (ICMP)
|-
|-
| <code>id</code> || Show user/group ID || <code>id</code>
| [[#ex-curl|<code>curl</code>]] || Retrieve data from URLs / APIs
|-
| [[#ex-ssh|<code>ssh</code>]] || Secure remote shell & tunnelling
|}
|}


=== Permissions ===
=== Help & Documentation ===
{| class="wikitable"
{| class="wikitable"
! Command !! Description !! Example
! Command !! Description
|-
| [[#ex-man|<code>man</code>]] || Read manual pages
|-
|-
| <code>chmod</code> || Change file permissions || <code>chmod 755 script.sh</code>
| [[#ex-echo|<code>echo</code>]] || Display text / variables
|}
|}


=== System Info ===
== Examples ==
{| class="wikitable"
 
! Command !! Description !! Example
=== <span id="ex-pwd"></span>Print Working Directory ===
|-
<syntaxhighlight lang="bash">
| <code>df -h</code> || Disk usage || <code>df -h</code>
pwd
|}
</syntaxhighlight>
''[[#commands|↑ Commands]]''
 
=== <span id="ex-cd"></span>Change Directory ===
<syntaxhighlight lang="bash">
cd /var/www
</syntaxhighlight>
''[[#commands|↑ Commands]]''
 
=== <span id="ex-ls"></span>List All Files (long + hidden) ===
<syntaxhighlight lang="bash">
ls -la
</syntaxhighlight>
''[[#commands|↑ Commands]]''
 
=== <span id="ex-mkdir"></span>Create Directory ===
<syntaxhighlight lang="bash">
mkdir backups
</syntaxhighlight>
''[[#commands|↑ Commands]]''
 
=== <span id="ex-rmdir"></span>Remove Empty Directory ===
<syntaxhighlight lang="bash">
rmdir backups
</syntaxhighlight>
''[[#commands|↑ Commands]]''
 
=== <span id="ex-cp"></span>Copy File ===
<syntaxhighlight lang="bash">
cp secrets.txt /tmp/secrets.bak
</syntaxhighlight>
''[[#commands|↑ Commands]]''
 
=== <span id="ex-mv"></span>Move & Rename ===
<syntaxhighlight lang="bash">
mv old.log archive/old.log
</syntaxhighlight>
''[[#commands|↑ Commands]]''
 
=== <span id="ex-rm"></span>Force‑Delete Directory ===
<syntaxhighlight lang="bash">
rm -rf /tmp/testdir
</syntaxhighlight>
''[[#commands|↑ Commands]]''
 
=== <span id="ex-cat"></span>Show File Contents ===
<syntaxhighlight lang="bash">
cat /etc/passwd | grep ":/bin/bash"
</syntaxhighlight>
''[[#commands|↑ Commands]]''
 
=== <span id="ex-less"></span>View Large Log ===
<syntaxhighlight lang="bash">
less /var/log/auth.log
</syntaxhighlight>
''[[#commands|↑ Commands]]''
 
=== <span id="ex-head"></span>First 10 Lines ===
<syntaxhighlight lang="bash">
head -n 10 notes.txt
</syntaxhighlight>
''[[#commands|↑ Commands]]''


== <span id="networking"></span>Networking ==
=== <span id="ex-tail"></span>Follow File Growth ===
<syntaxhighlight lang="bash">
tail -f /var/log/nginx/access.log
</syntaxhighlight>
''[[#commands|↑ Commands]]''


=== Connectivity Tools ===
=== <span id="ex-grep"></span>Search Pattern ===
{| class="wikitable"
<syntaxhighlight lang="bash">
! Command !! Description !! Example
grep -R \"passwd\" /etc
|-
</syntaxhighlight>
| <code>ping</code> || Send ICMP packets || <code>ping -c 4 google.com</code>
''[[#commands|↑ Commands]]''
|-
| <code>curl</code> || Fetch URL/API data || <code>curl http://example.com</code>
|-
| <code>ssh</code> || Remote shell access || <code>ssh user@host</code>
|}


== <span id="searching"></span>Search & Output Manipulation ==
=== <span id="ex-whoami"></span>Current User ===
<syntaxhighlight lang="bash">
whoami
</syntaxhighlight>
''[[#commands|↑ Commands]]''


=== Text Processing ===
=== <span id="ex-id"></span>User & Group IDs ===
{| class="wikitable"
<syntaxhighlight lang="bash">
! Command !! Description !! Example
id
|-
</syntaxhighlight>
| <code>grep</code> || Search for patterns || <code>grep root /etc/passwd</code>
''[[#commands|↑ Commands]]''
|}


== <span id="help"></span>Help & Documentation ==
=== <span id="ex-df"></span>Human‑Readable Disk Usage ===
<syntaxhighlight lang="bash">
df -h
</syntaxhighlight>
''[[#commands|↑ Commands]]''


=== Learning a Command ===
=== <span id="ex-history"></span>Show Last 20 Commands ===
{| class="wikitable"
<syntaxhighlight lang="bash">
! Command !! Description !! Example
history | tail -n 20
|-
</syntaxhighlight>
| <code>man</code> || Show manual page || <code>man nmap</code>
''[[#commands|↑ Commands]]''
|-
| <code>echo</code> || Output text || <code>echo "Hello" > out.txt</code>
|-
| <code>history</code> || Show command history || <code>history</code>
|}


== Examples ==
=== <span id="ex-ping"></span>Ping Host 4 Times ===
<syntaxhighlight lang="bash">
ping -c 4 example.com
</syntaxhighlight>
''[[#commands|↑ Commands]]''


=== <span id="ex-ssh"></span>SSH with Custom Port ===
=== <span id="ex-curl"></span>Download Web Page ===
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
ssh -p 2222 user@target
curl -o index.html http://example.com
</syntaxhighlight>
</syntaxhighlight>
''[[#commands|↑ Commands]]''


=== <span id="ex-curl"></span>Fetch a Remote Web Page ===
=== <span id="ex-ssh"></span>SSH on Custom Port ===
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
curl http://example.com
ssh -p 2222 user@target
</syntaxhighlight>
</syntaxhighlight>
''[[#commands|↑ Commands]]''


=== <span id="ex-chmod"></span>Make Script Executable ===
=== <span id="ex-man"></span>Read Manual Page ===
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
chmod +x exploit.sh
man ssh
</syntaxhighlight>
</syntaxhighlight>
''[[#commands|↑ Commands]]''


=== <span id="ex-grep"></span>Search for Usernames ===
=== <span id="ex-echo"></span>Write to File ===
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
grep /bin/bash /etc/passwd
echo \"hacked\" > /tmp/proof.txt
</syntaxhighlight>
</syntaxhighlight>
''[[#commands|↑ Commands]]''


== See Also ==
== See Also ==
* [[Basic Windows Commands]]
* [[Bash Scripting Basics]]
* [[Privilege Escalation]]
* [[Netcat]]

Revision as of 15:38, 12 May 2025

Linux Commands

Linux command‑line tools are the backbone of reconnaissance, exploitation, and post‑exploitation on Unix‑like systems. This page mirrors the *Nmap* layout so each command in the tables links to a live example, and every example links back to the command list for quick navigation.

Common Commands

Navigation & File Management

Command Description
pwd Print working directory
cd Change directory
ls List directory contents
mkdir Create directory
rmdir Remove empty directory
cp Copy files or directories
mv Move or rename files/directories
rm Delete files or directories

Viewing & Text Processing

Command Description
cat Concatenate & display files
less Paginate large files
head Show first lines of a file
tail Show last lines / follow file
grep Search for patterns

System & User Info

Command Description
whoami Show current user
id Display user/group IDs
df Disk usage overview
history List previously executed commands

Networking

Command Description
ping Test network connectivity (ICMP)
curl Retrieve data from URLs / APIs
ssh Secure remote shell & tunnelling

Help & Documentation

Command Description
man Read manual pages
echo Display text / variables

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