דלג לתוכן הראשי

Linux Cheat Sheet

Basic Commands

  • pwd: Print the current working directory.
    pwd
  • ls: List files and directories.
    ls -la
  • cd: Change directory.
    cd /path/to/directory
  • mkdir: Create a new directory.
    mkdir myfolder
  • rmdir: Remove an empty directory.
    rmdir myfolder
  • cp: Copy files or directories.
    cp file.txt /path/to/destination/
    cp -r folder /path/to/destination/
  • mv: Move or rename files or directories.
    mv file.txt /path/to/destination/
    mv oldname.txt newname.txt
  • rm: Remove files or directories.
    rm file.txt
    rm -r folder
  • touch: Create a new, empty file.
    touch newfile.txt
  • cat: Display the content of a file.
    cat file.txt
  • nano/vim: Edit files with text editors.
    nano file.txt
    vim file.txt

System Information

  • uname -a: Display system information.
    uname -a
  • top: Display running processes and system resource usage.
    top
  • df -h: Display disk space usage.
    df -h
  • free -h: Display memory usage.
    free -h
  • uptime: Show how long the system has been running.
    uptime
  • whoami: Display the current user.
    whoami

File Permissions

  • chmod: Change file permissions.
    chmod 755 file.txt
    chmod u+x script.sh
  • chown: Change file owner and group.
    sudo chown user:group file.txt

Process Management

  • ps aux: List all running processes.
    ps aux
  • kill: Terminate a process by PID.
    kill 1234
  • killall: Terminate all processes by name.
    killall firefox
  • bg: Resume a suspended job in the background.
    bg
  • fg: Bring a background job to the foreground.
    fg

Networking

  • ifconfig: Display network interfaces and IP addresses.
    ifconfig
  • ping: Check connectivity to a host.
    ping google.com
  • curl: Fetch content from a URL.
    curl http://example.com
  • wget: Download files from the web.
    wget http://example.com/file.zip

Package Management (Debian/Ubuntu)

  • apt-get update: Update package lists.
    sudo apt-get update
  • apt-get upgrade: Upgrade all installed packages.
    sudo apt-get upgrade
  • apt-get install: Install a package.
    sudo apt-get install package_name
  • apt-get remove: Remove a package.
    sudo apt-get remove package_name
  • apt-get autoremove: Remove unnecessary packages.
    sudo apt-get autoremove

User Management

  • adduser: Add a new user.
    sudo adduser username
  • passwd: Change a user's password.
    passwd username
  • deluser: Delete a user.
    sudo deluser username
  • usermod: Modify a user's account.
    sudo usermod -aG groupname username

Disk Management

  • fdisk -l: List all partitions.
    sudo fdisk -l
  • mount: Mount a filesystem.
    sudo mount /dev/sdX /mnt
  • umount: Unmount a filesystem.
    sudo umount /mnt
  • fsck: Check and repair a filesystem.
    sudo fsck /dev/sdX

Searching and Finding Files

  • find: Search for files in a directory hierarchy.
    find /path -name filename
  • grep: Search for a pattern within files.
    grep "pattern" file.txt
    grep -r "pattern" /path
  • locate: Find files by name quickly.
    locate filename

Archiving and Compression

  • tar: Create and extract tar archives.
    tar -czvf archive.tar.gz /path/to/directory
    tar -xzvf archive.tar.gz
  • zip/unzip: Compress and decompress files.
    zip archive.zip file1 file2
    unzip archive.zip