0% found this document useful (0 votes)
117 views

Kali Linux Commands

Uploaded by

masterkenobi000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

Kali Linux Commands

Uploaded by

masterkenobi000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Chapter 1: Getting Started with the Basics

pwd – Print the current directory.


1. pwd → Outputs /home/kali
2. cd /etc && pwd → Outputs /etc
3. cd ~/Documents && pwd → Outputs /home/kali/Documents
ls – List files and directories.
1. ls -l → Detailed list with permissions and sizes.
2. ls -a → Lists hidden files (like .bashrc).
3. ls -lh /var → Lists with human-readable file sizes.
cd – Change directory.
1. cd /home/kali → Moves to the user directory.
2. cd .. → Moves up one directory level.
3. cd ~/Downloads → Moves to Downloads directory.
whoami – Show current user.
1. whoami → Outputs kali
2. sudo whoami → Outputs root
3. ssh user@remote && whoami → Outputs the remote user.
uname -a – Show system information.
1. uname -a → Displays kernel version and system architecture.
2. uname -r → Displays kernel version only.
3. uname -m → Displays the machine architecture (e.g., x86_64).
man / --help – Show manual or help.
1. man ls → Shows the manual for the ls command.
2. ls --help → Shows help and usage options for ls.
3. man grep → Displays the manual for grep.
Chapter 2: Text Manipulation
cat – Display file content.
1. cat file.txt → Prints entire content of file.txt.
2. cat /etc/passwd → Shows user account information.
3. cat file1.txt file2.txt → Concatenates and prints both files.
head / tail – View the beginning or end of a file.
1. head -n 10 file.txt → Displays the first 10 lines.
2. tail -n 5 file.txt → Displays the last 5 lines.
3. tail -f /var/log/syslog → Continuously shows new log entries.
grep – Search patterns in text files.
1. grep 'root' /etc/passwd → Finds lines with "root".
2. grep -i 'error' /var/log/syslog → Case-insensitive search for
"error".
3. grep -r 'main' ./src → Recursively searches in the src directory.
sed – Stream editor for replacing text.
1. sed 's/foo/bar/' file.txt → Replaces the first occurrence of "foo"
with "bar".
2. sed -i 's/hello/Hi/g' file.txt → Edits the file, replacing all
occurrences of "hello" with "Hi".
3. echo 'test' | sed 's/test/TEST/' → Outputs TEST.
awk – Pattern scanning and processing.
1. awk '{print $1}' file.txt → Prints the first column of each line.
2. awk '/error/ {print $2}' /var/log/syslog → Prints the second
column of lines containing "error".
3. echo "1 2 3" | awk '{print $2}' → Outputs 2.
Chapter 3: Analyzing and Managing Networks
ifconfig / ip – Display network interfaces.
1. ifconfig eth0 → Shows details of the eth0 interface.
2. ip addr → Displays all network interfaces.
3. ifconfig wlan0 down && ifconfig wlan0 up → Restarts the
wireless interface.
ping – Check connectivity.
1. ping google.com → Pings Google's server.
2. ping -c 4 8.8.8.8 → Sends 4 pings to Google DNS.
3. ping -i 0.5 localhost → Pings the local machine with 0.5-second
intervals.
nmap – Network scanner.
1. nmap 192.168.1.1 → Scans the IP for open ports.
2. nmap -sV 192.168.1.1 → Detects services running on ports.
3. nmap -A 192.168.1.0/24 → Scans the whole subnet.
netstat / ss – Display network connections.
1. ss -tuln → Lists open TCP and UDP ports.
2. netstat -ant → Displays active TCP connections.
3. ss -i → Shows detailed socket information.
traceroute – Trace network path.
1. traceroute google.com → Traces the route to Google.
2. traceroute -m 5 8.8.8.8 → Limits hops to 5.
3. traceroute -T github.com → Uses TCP instead of ICMP.
Chapter 4: Adding and Removing Software
apt update – Refresh package lists.
1. sudo apt update → Updates the package list.
2. apt update && apt upgrade → Updates and
upgrades packages.
3. apt update -y → Auto-answers "yes" to prompts.
apt install – Install software.
1. apt install nmap → Installs the nmap package.
2. apt install python3 → Installs Python 3.
3. apt install -y curl → Installs curl with auto-
confirmation.
apt remove – Uninstall a package.
1. apt remove apache2 → Removes Apache server.
2. apt remove --purge nmap → Completely removes
nmap.
3. apt remove python3 -y → Auto-confirms removal.
dpkg – Install or query .deb packages.
1. dpkg -i package.deb → Installs a local .deb
package.
2. dpkg -l | grep nmap → Lists installed nmap version.
3. dpkg --remove apache2 → Removes Apache2
packag
Chapter 5: Controlling File and Directory Permissions
chmod – Change file permissions.
1. chmod 755 script.sh → Sets read, write, execute
permissions for owner, and read, execute for others.
2. chmod u+w file.txt → Adds write permission for the
owner.
3. chmod -R 644 /var/www/html → Recursively sets
read-write permissions for owner and read-only for
others.
chown – Change file ownership.
1. chown user1 file.txt → Changes ownership of
file.txt to user1.
2. chown user2:group2 /var/www/html → Changes
owner to user2 and group to group2.
3. sudo chown -R root:root /etc → Recursively
changes ownership of /etc to root.
umask – Set default permissions.
1. umask 022 → Sets default permissions (files will be
755).
2. umask → Displays the current umask value.
3. umask 077 → Ensures new files are accessible only
by the owner.
Chapter 6: Process Management
ps – View active processes.
1. ps aux → Shows all running processes.
2. ps -ef | grep apache → Filters Apache
processes.
3. ps -u kali → Shows processes owned by the user
kali.
top / htop – Interactive process monitoring.
1. top → Displays active processes dynamically.
2. htop → Similar to top but more user-friendly (if
installed).
3. top -o %MEM → Sorts processes by memory
usage.
kill / pkill – Terminate processes.
1. kill 1234 → Kills process with PID 1234.
2. pkill apache2 → Kills all Apache processes.
3. kill -9 5678 → Forces termination of process
5678.
Chapter 7: Managing User Environment Variables
env – Display environment variables.
1. env → Lists all environment variables.
2. env | grep PATH → Shows the PATH variable.
3. env VAR=value ./script.sh → Runs a script with
a temporary variable.
export – Set an environment variable.
1. export PATH=$PATH:/usr/local/bin → Adds a
path to the PATH variable.
2. export EDITOR=vim → Sets vim as the default
editor.
3. export LANG=en_US.UTF-8 → Sets the system
language.
unset – Remove a variable.
1. unset VAR_NAME → Removes the variable
VAR_NAME.
2. unset PATH → Clears the PATH variable (not
recommended).
3. unset USER → Deletes the USER environment
variable.
Chapter 8: Bash Scripting
bash – Execute a script.
1. bash hello.sh → Runs the script hello.sh.
2. bash -x script.sh → Runs a script with
debugging output.
3. bash --version → Displays the Bash version.
if, for, while – Control structures.
1. if [ $USER == "root" ]; then echo "You are
root"; fi
2. for i in {1..5}; do echo $i; done → Prints
numbers 1 to 5.
3. while true; do echo "Running"; sleep 1; done
→ Infinite loop printing "Running".
Chapter 9: Compressing and Archiving
tar – Archive files.
1. tar -czf archive.tar.gz /folder → Archives and
compresses /folder.
2. tar -xzf archive.tar.gz → Extracts the archive.
3. tar -cf archive.tar file1 file2 → Archives
without compression.
gzip – Compress files.
1. gzip file.txt → Compresses file.txt to
file.txt.gz.
2. gzip -d file.txt.gz → Decompresses the file.
3. gzip -k file.txt → Keeps the original file after
compression.
zip – Create ZIP archives.
1. zip archive.zip file1 file2 → Creates a ZIP with
two files.
2. unzip archive.zip → Extracts the ZIP file.
3. zip -r archive.zip /folder → Zips the entire
folder.
Chapter 10: Filesystem and Storage Device
Management
df – Display disk space usage.
1. df -h → Displays disk usage in human-readable
format.
2. df -T → Shows filesystem type.
3. df -i → Displays inode usage.
mount / umount – Mount/Unmount devices.
1. mount /dev/sda1 /mnt → Mounts sda1 to
/mnt.
2. umount /mnt → Unmounts the device from
/mnt.
3. mount -o ro /dev/sda1 /mnt → Mounts as
read-only.
fsck – Check and repair filesystems.
1. fsck /dev/sda1 → Checks and repairs
/dev/sda1.
2. fsck -y /dev/sda1 → Auto-confirms repairs.
3. fsck -n /dev/sda1 → Checks without making
changes.
Chapter 11: The Logging System
journalctl – Query system logs.
1. journalctl -u ssh → Shows logs for SSH service.
2. journalctl --since "1 hour ago" → Logs from the
last hour.
3. journalctl -k → Displays kernel logs.
dmesg – Display kernel messages.
1. dmesg | tail → Shows the latest kernel
messages.
2. dmesg | grep usb → Filters USB-related
messages.
3. dmesg -T → Converts timestamps to human-
readable format.
Chapter 12: Using and Abusing Services
systemctl – Manage services.
1. systemctl start apache2 → Starts the Apache
service.
2. systemctl stop ssh → Stops the SSH service.
3. systemctl restart nginx → Restarts the Nginx
service.
service – Legacy service management.
1. service apache2 status → Checks Apache
status.
2. service ssh restart → Restarts SSH service.
3. service --status-all → Lists all services and their
status.
Chapter 13: Becoming Secure and Anonymous
iptables – Firewall management.
1. iptables -L → Lists firewall rules.
2. iptables -A INPUT -p tcp --dport 22 -j ACCEPT →
Allows SSH connections.
3. iptables -D INPUT 1 → Deletes the first rule in the
INPUT chain.
tor – Anonymous network browsing.
1. tor → Starts the Tor network.
2. proxychains firefox → Opens Firefox through Tor.
3. tor --version → Displays the Tor version.
Chapter 14: Understanding and Inspecting
Wireless Networks
iwconfig – Configure wireless interfaces.
1. iwconfig wlan0 essid "network" → Connects to a
wireless network.
2. iwconfig wlan0 mode monitor → Sets monitor
mode.
3. iwconfig wlan0 channel 6 → Sets the wireless
channel.
airmon-ng – Enable monitor mode.
1. airmon-ng start wlan0 → Enables monitor mode
on wlan0.
2. airmon-ng stop wlan0 → Stops monitor mode.
3. airmon-ng check kill → Stops interfering
processes.
Chapter 15: Managing the Linux Kernel and
Loadable Kernel Modules
lsmod – List loaded modules.
1. lsmod | grep usb → Lists USB-related modules.
2. lsmod | wc -l → Counts loaded modules.
3. lsmod | grep nvidia → Checks if NVIDIA driver is
loaded.
modprobe / rmmod – Load/Unload modules.
1. **`modprobe vmmon
modprobe / rmmod – Load/Unload modules.
1. modprobe vmmon → Loads the vmmon kernel
module (used by VMware).
2. modprobe -r vmmon → Unloads the vmmon
module.
3. modprobe loop → Loads the loopback device
module.

You might also like