Bytes
Data Science

Linux Commands Cheat Sheet (Basics to Advanced)

Last Updated: 30th July, 2024
icon

Arunav Goswami

Data Science Consultant at almaBetter

Explore our Linux commands cheat sheet for beginners and advanced users. Learn navigation, file manipulation, permissions, and more to enhance your Linux skills

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

  1. pwd - Print Working Directory
    • Usage: pwd
    • Description: Displays the current directory path.
  2. ls - List Directory Contents
    • Usage: ls [options] [directory]
    • Description: Lists files and directories within the specified directory.
    • Example: ls -l /home/user
  3. cd - Change Directory
    • Usage: cd [directory]
    • Description: Changes the current directory to the specified directory.
    • Example: cd /home/user/Documents
  4. mkdir - Make Directory
    • Usage: mkdir [directory]
    • Description: Creates a new directory.
    • Example: mkdir new_folder
  5. rmdir - Remove Directory
    • Usage: rmdir [directory]
    • Description: Removes an empty directory.
    • Example: rmdir old_folder
  6. touch - Create Empty File
    • Usage: touch [filename]
    • Description: Creates a new, empty file.
    • Example: touch newfile.txt
  7. 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/
  8. mv - Move/Rename Files and Directories
    • Usage: mv [source] [destination]
    • Description: Moves or renames files or directories.
    • Example: mv file1.txt /home/user/Documents/
  9. rm - Remove Files and Directories
    • Usage: rm [options] [file/directory]
    • Description: Removes files or directories.
    • Example: rm -r /home/user/old_folder
  10. cd..  - Move up one directory level.

File Viewing and Editing

  1. cat - Concatenate and Display Files
    1. Usage: cat [file]
    2. Description: Displays the contents of a file.
    3. Example: cat file1.txt
  2. more - View File Contents One Screen at a Time
    1. Usage: more [file]
    2. Description: Displays the contents of a file, one screen at a time.
    3. Example: more file1.txt
  3. less - View File Contents with Backward Navigation
    1. Usage: less [file]
    2. Description: Displays the contents of a file with the ability to navigate backward.
    3. Example: less file1.txt
  4. head - Display the First Lines of a File
    1. Usage: head [options] [file]
    2. Description: Displays the first 10 lines of a file by default.
    3. Example: head -n 5 file1.txt
  5. tail - Display the Last Lines of a File
    1. Usage: tail [options] [file]
    2. Description: Displays the last 10 lines of a file by default.
    3. Example: tail -n 5 file1.txt
  6. touch [filename]: Create an empty file.
    1. Example: touch newfile.txt creates an empty file named newfile.txt.
  7. cp [source] [destination]: Copy files or directories.
  8. mv [source] [destination]: Move or rename files or directories.
  9. rm [filename]: Remove a file.
  10. rm -r [directory]: Remove a directory and its contents
  11. nano [filename]: Edit files with nano editor.
  12. less [filename]: View file content page by page.
  13. grep [pattern] [file]: Search for a pattern in a file.
  14. find [directory] -name [filename]: Find files by name.
  15. locate [filename]: Find the location of files.

System Information

  1. uname - Print System Information
    • Usage: uname [options]
    • Description: Displays system information.
    • Example: uname -a
  2. df - Disk Space Usage
    • Usage: df [options]
    • Description: Displays the amount of disk space used and available on file systems.
    • Example: df -h
  3. du - Disk Usage
    • Usage: du [options] [directory/file]
    • Description: Estimates file space usage.
    • Example: du -sh /home/user/
  4. top - Display Linux Tasks
    • Usage: top
    • Description: Displays the tasks running on the system, along with system resource usage.
    • Example: top
  5. ps - Report a Snapshot of Current Processes
    • Usage: ps [options]
    • Description: Displays a snapshot of current processes.
    • Example: ps aux

Networking

  1. 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
  2. ifconfig - Configure a Network Interface
    • Usage: ifconfig [interface] [options]
    • Description: Displays or configures network interfaces.
    • Example: ifconfig eth0
  3. netstat - Network Statistics
    • Usage: netstat [options]
    • Description: Displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
    • Example: netstat -tuln
  4. 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/
  5. 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

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

  1. ls -l: View file permissions in the long format.

Ownership Commands

  1. 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
  2. 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

  1. sudo [command]: Execute a command with superuser privileges.
  2. sudo su: Switch to the root user.
  3. su [user]: Switch to another user.
  4. visudo: Edit the sudoers file to manage user privileges.

Finding SUID/SGID Files

  1. find / -perm -4000 2>/dev/null: Find SUID files.
  2. 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

  1. ifconfig: Display network configuration.
  2. iwconfig: Display wireless network configuration.
  3. nmap [options] [target]: Network exploration tool and security scanner.
  4. netstat: Display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

Package Management

  1. apt-get update: Update package index.
  2. apt-get upgrade: Upgrade all installed packages.
  3. apt-get install [package]: Install a new package.
  4. dpkg -i [package.deb]: Install a package from a .deb file.

Other Advanced Linux Commands

  1. top: Display tasks and system performance.
  2. kill [PID]: Kill a process by its process ID.
  3. pkill [name]: Kill processes by name.
  4. du: Estimate file space usage.
  5. mount: Mount a filesystem.
  6. umount: Unmount a filesystem.
  7. hostname: Show or set the system’s hostname.
  8. 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.

  • Official Address
  • 4th floor, 133/2, Janardhan Towers, Residency Road, Bengaluru, Karnataka, 560025
  • Communication Address
  • Follow Us
  • facebookinstagramlinkedintwitteryoutubetelegram

© 2024 AlmaBetter