Linux, a powerful and flexible operating system, is known for its command line interface (CLI). For both beginners and advanced users, having a cheat sheet for Linux commands can significantly enhance productivity and ease of use. This guide compiles essential Linux commands, covering various categories to create a comprehensive Linux commands cheat sheet.
Introduction to Linux Commands
Linux commands are used to interact with the operating system, perform tasks, and manage files. This cheat sheet will provide a quick reference to the most commonly used commands, especially helpful for those using Kali Linux or any other Linux distribution. Whether you are looking for basic commands or specific tasks like file permissions and privilege escalation, this guide has you covered.
Basic Linux Commands Cheat Sheet
- pwd - Print Working Directory
- Usage: pwd
- Description: Displays the current directory path.
- ls - List Directory Contents
- Usage: ls [options] [directory]
- Description: Lists files and directories within the specified directory.
- Example: ls -l /home/user
- cd - Change Directory
- Usage: cd [directory]
- Description: Changes the current directory to the specified directory.
- Example: cd /home/user/Documents
- mkdir - Make Directory
- Usage: mkdir [directory]
- Description: Creates a new directory.
- Example: mkdir new_folder
- rmdir - Remove Directory
- Usage: rmdir [directory]
- Description: Removes an empty directory.
- Example: rmdir old_folder
- touch - Create Empty File
- Usage: touch [filename]
- Description: Creates a new, empty file.
- Example: touch newfile.txt
- cp - Copy Files and Directories
- Usage: cp [source] [destination]
- Description: Copies files or directories from the source to the destination.
- Example: cp file1.txt /home/user/backup/
- mv - Move/Rename Files and Directories
- Usage: mv [source] [destination]
- Description: Moves or renames files or directories.
- Example: mv file1.txt /home/user/Documents/
- rm - Remove Files and Directories
- Usage: rm [options] [file/directory]
- Description: Removes files or directories.
- Example: rm -r /home/user/old_folder
- cd.. - Move up one directory level.
File Viewing and Editing
- cat - Concatenate and Display Files
- Usage: cat [file]
- Description: Displays the contents of a file.
- Example: cat file1.txt
- more - View File Contents One Screen at a Time
- Usage: more [file]
- Description: Displays the contents of a file, one screen at a time.
- Example: more file1.txt
- less - View File Contents with Backward Navigation
- Usage: less [file]
- Description: Displays the contents of a file with the ability to navigate backward.
- Example: less file1.txt
- head - Display the First Lines of a File
- Usage: head [options] [file]
- Description: Displays the first 10 lines of a file by default.
- Example: head -n 5 file1.txt
- tail - Display the Last Lines of a File
- Usage: tail [options] [file]
- Description: Displays the last 10 lines of a file by default.
- Example: tail -n 5 file1.txt
- touch [filename]: Create an empty file.
- Example: touch newfile.txt creates an empty file named newfile.txt.
- cp [source] [destination]: Copy files or directories.
- mv [source] [destination]: Move or rename files or directories.
- rm [filename]: Remove a file.
- rm -r [directory]: Remove a directory and its contents
- nano [filename]: Edit files with nano editor.
- less [filename]: View file content page by page.
- grep [pattern] [file]: Search for a pattern in a file.
- find [directory] -name [filename]: Find files by name.
- locate [filename]: Find the location of files.
- uname - Print System Information
- Usage: uname [options]
- Description: Displays system information.
- Example: uname -a
- df - Disk Space Usage
- Usage: df [options]
- Description: Displays the amount of disk space used and available on file systems.
- Example: df -h
- du - Disk Usage
- Usage: du [options] [directory/file]
- Description: Estimates file space usage.
- Example: du -sh /home/user/
- top - Display Linux Tasks
- Usage: top
- Description: Displays the tasks running on the system, along with system resource usage.
- Example: top
- ps - Report a Snapshot of Current Processes
- Usage: ps [options]
- Description: Displays a snapshot of current processes.
- Example: ps aux
Networking
- ping - Send ICMP ECHO_REQUEST to Network Hosts
- Usage: ping [host]
- Description: Tests the reachability of a host on an IP network.
- Example: ping google.com
- ifconfig - Configure a Network Interface
- Usage: ifconfig [interface] [options]
- Description: Displays or configures network interfaces.
- Example: ifconfig eth0
- netstat - Network Statistics
- Usage: netstat [options]
- Description: Displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
- Example: netstat -tuln
- scp - Secure Copy
- Usage: scp [source] [destination]
- Description: Securely copies files between hosts on a network.
- Example: scp file1.txt user@remote_host:/home/user/
- ssh - Secure Shell
- Usage: ssh [user]@[host]
- Description: Connects to a remote host securely over an encrypted network.
- Example: ssh user@remote_host
Linux File Permissions Cheat Sheet
Understanding and managing file permissions is crucial in Linux for security and proper file management.
Basic File Permissions
- r: Read permission.
- w: Write permission.
- x: Execute permission.
Changing File Permissions
- chmod [permissions] [filename]: Change file permissions.
- Example: chmod 755 [filename] sets the file permissions to read, write, and execute for the owner, and read and execute for others.
Viewing File Permissions
- ls -l: View file permissions in the long format.
Ownership Commands
- chown - Change File Owner and Group
- Usage: chown [owner][:group] [file]
- Description: Changes the owner and group of a file or directory.
- Example: chown user:group file1.txt
- chgrp [group] [filename]: Change file group ownership.
Linux Privilege Escalation Cheat Sheet
Privilege escalation involves gaining higher privileges than those initially granted. It’s essential for system administrators and security professionals.
Common Commands for Privilege Escalation
- sudo [command]: Execute a command with superuser privileges.
- sudo su: Switch to the root user.
- su [user]: Switch to another user.
- visudo: Edit the sudoers file to manage user privileges.
Finding SUID/SGID Files
- find / -perm -4000 2>/dev/null: Find SUID files.
- find / -perm -2000 2>/dev/null: Find SGID files.
Kali Linux Commands Cheat Sheet
Kali Linux is a Debian-based distribution used for penetration testing and security auditing. Below are some essential commands specific to Kali Linux.
Network Commands
- ifconfig: Display network configuration.
- iwconfig: Display wireless network configuration.
- nmap [options] [target]: Network exploration tool and security scanner.
- netstat: Display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
Package Management
- apt-get update: Update package index.
- apt-get upgrade: Upgrade all installed packages.
- apt-get install [package]: Install a new package.
- dpkg -i [package.deb]: Install a package from a .deb file.
Other Advanced Linux Commands
- top: Display tasks and system performance.
- kill [PID]: Kill a process by its process ID.
- pkill [name]: Kill processes by name.
- du: Estimate file space usage.
- mount: Mount a filesystem.
- umount: Unmount a filesystem.
- hostname: Show or set the system’s hostname.
- dmesg: Print or control the kernel ring buffer.
Conclusion
This Linux cheat sheet covers some of the essential Linux commands that every user should know. Whether you're navigating the file system, managing files, or configuring network settings, these commands provide a foundation for efficient and effective Linux system administration. Keep this guide handy as a quick reference to enhance your productivity and command-line prowess.