Show Menu
Cheatography

White Hat Commands in Linux Cheat Sheet by

Some basic commands used in Linux for white hat/ethical hacking purposes, as well as just some good general knowledge in linux with networking.

General Navigation and Bash Commands

pwd
Show current directory
mkdir directory
Make directory directory
rmdir directory
Remove directory
cd directory
Change to directory directory
cd ..
Go up a directory (the parent directory)
cd
Change to home directory
ls
list files (in current directory)
cat file
Display contents of file
ls directory
list files in specified directory
whoami
Show your username
uname -a
Show system and kernel
head -n1 /etc/issue
Show distro­bution
man command
Show manual­/in­for­mation for specified command
uptime
Show uptime
date
Show system date
mount
Show mounted file systems

ls Options

-a
Show all plus hidden files
-R
Recursive list
-r
Reverse order
-t
Sort by last modified
-S
Sort by file size
-l
Long listing format
-1
One file per line
-m
Comma-­sep­arated output
-Q
Quoted output

grep

grep option string files
Search for string in files
-i
Case insens­itive search
-r
Recursive search
-v
Inverted search
-c
Print count of matching lines
-o
Show matched part of file only

More Search Commands

find /dir/ -name name
Find files starting with name in dir
find /dir/ -user name
Find files owned by name in dir
whereis command
Find binary source manual for command
locate file
Find file with quick search of system index
which file
Shows path to file
Add 2>/­dev­/null at the end to discard error messages
 

File Manipu­lation

touch
Create, change, modify timestamps of a file
echo
Print specified text
mv
Move source to directory; Rename Old to New
rm
Remove files or direct­ories
rm -f
Ignore nonexi­stent files
rm -i
Prompt before every removal
rm -I
Prompt once before removing more than 3 files
rm -r
Remove direct­ories and their contents recurs­ively
cp file1 file2
Copy file1 to file2
cp -b
Backup (doesn't support argument)
cp -f
If file cannot be opened remove and try again
cp -l
Hard link files instead of copying
cp -n
Do not overwrite existing file
cp -s
Make symbolic link instead of copying
cp -r
Copy direct­ories recurs­ively
cp -u
Copy only when SOURCE file is newer than destin­ation file or when destin­ation file is missing

Permis­sions (chmod)

chmod u file
Change owner permission of file
chmod g file
Change group permission of file
chmod o file
Change all others' permission of file
chmod a file
Change everyone's permission of file
r
permission to read symbol
w
permission to write symbol
x
permission to execute symbol
chmod o+r file
Adds the "­rea­d" ability to "­oth­er" users
chmod o-r file
Removes the "­rea­d" ability from "­oth­er" users
chmod 777 file
Adds rwx permis­sions to all users using octal notations
I advise looking up an octal notations table/­exp­lai­nation for any help unders­tanding the numbers and their placement, this is just for a quick reference.

Ownership (chown)

chown newowner file
Change user owner of file to newowner
chown :groupname file.txt
Change group owner of file.txt to groupname
chown newowner:groupname file.txt
Change user owner and group owner of file
-f
Suppress most error messages
-R
Make changes recurs­ively
-H
If cmd argument is symbolic link, traverse it
-L
Traverse every symbolic link to a directory encoun­tered
-h
Affect each symbolic link instead of any referenced file
Make note of the :

Processes

ps
Show snapshot of current processes
top
Show realtime processes
kill pid
Kill process with ID pid
pkill name
Kill process with name name
killall name
Kill all process with names beginning with name
 

Basic Networking Commands

ifconfig
Show details of Network settings (IP, version, etc)
whois
Shows site owner and DNS name server
nslookup
Shows namese­rvers and IP Addresses
traceroute
Shows routing inform­ation to host
nmap
Port scanning (TCP, UDP)
ping/ping6
Send ICMP pings; Also checks latency
route
Show/m­ani­pulate IP routing table
arp
Show/m­ani­pulate ARP cache
ip
See ARP cache, neighbor table, add routes
nc
Show various network info
tcpdump
Capture network traffic
dig website
Show various IP inform­ation

Netcat (nc)

nc host port
Connect to remote server(s)
nc -l IPaddress port
Listen mode; listen for incoming connec­tions
-p
Specify port number
-v
Verbose mode
-z
Scan for open ports
-q
Specify delay before closing connection
-g
Source­-ro­uting hop point(s) up to 8
-n
Numeri­c-only IP addresses
-s address
local source address
-c string
specify shell cmds to execute after connect
-e filename
Specify filename to execute after connect (if no working /bin/sh)

tcpdump

-A
Print in ASCII
-c count
Exit after capturing count packets
-D
Show available interfaces
-e
Print link-level header on each line
-F file
Use file as filter expression
-L
List data link types for interface
-n
Don't convert addresses to names
-p
Don't capture in promis­cuous mode
-q
Quick Output
-r file
Read packets from file
-s len
Capture up to len bytes per packet
-S
Print absolute TCP seq numbers
-t
Don't print timestamps
-w file
Write captured packets to file
-y type
Specify data-link type
-Z user
Drop privileges from root to user
                                   
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Linux Every Day Commands Cheat Sheet