Top 60 Linux Commands You Need to Know

Jul 9, 2024

Top 60 Linux Commands You Need to Know

SSH (Secure Shell)

  • Connect to a Linux machine remotely.
  • Syntax: ssh [user]@[server].

File and Directory Commands

Listing and Moving Around Directories

  • ls: List files in the current directory.
    • ls -l: Detailed list.
    • ls -a: Include hidden files.
  • pwd: Print working directory.
  • cd [directory]: Change directory.
    • cd ..: Go back one directory level.
    • cd: Go back to home directory.

Creating, Moving, and Deleting Files

  • touch [filename]: Create a new file or update the timestamp of an existing file.
  • cp [file] [destination]: Copy a file.
  • mv [file] [destination]: Move (or rename) a file.
  • rm [file]: Delete a file.
  • mkdir [directory]: Create a new directory.
  • rmdir [directory]: Remove an empty directory.
    • rm -r [directory]: Remove a directory recursively with files.

Viewing and Editing Files

  • cat [file]: Display the contents of a file.
  • nano [file]: Edit a file with the Nano text editor.
  • vim [file]: Edit a file with the Vim text editor.
    • Insert mode: Press i
    • Save and quit: Press Esc, type :wq
  • echo [text] > [file]: Write text to a file (overwrites).
  • echo [text] >> [file]: Append text to a file.
  • shred [file]: Securely delete a file.

Links and Permissions

  • ln -s [target] [link]: Create a symbolic link.
  • chmod +x [file]: Make a file executable.
  • chown [user] [file]: Change the ownership of a file.

Additional Commands

  • clear: Clear the terminal screen.
  • whoami: Display the current user.
  • exit: Exit the terminal or a user session.

User Management

  • sudo [command]: Run command with superuser privileges.
  • adduser [username]: Create a new user (Debian-based).
  • useradd [username]: Add a new user (generic).
  • passwd [username]: Change a user's password.
  • su [username]: Switch user.
  • finger [username]: Display information about a user (requires installation).

Package Management

Installing Software

  • Update package list: sudo apt update (Debian-based)
  • Install a package: sudo apt install [package] (Debian-based)
  • Red Hat-based: yum [command]
  • Arch-based: Use corresponding package manager

System Information and Manual Pages

  • man [command]: Open the manual for a command.
  • what [command]: Brief description of a command.
  • which [command]: Locate a command.
  • whereis [command]: Locate the binary, source, and manual-page files for a command.
  • df -h: Display free space on mounted filesystems.
  • uname -a: Print system information.
  • neofetch: Display system information in a neat format (requires installation).
  • cal: Display a calendar.
  • free: Display memory usage.

Downloading Files

  • wget [URL]: Download files from the web.
  • curl [URL] > [file]: Download files using cURL.

Compression and Decompression

  • zip [zipfile] [file(s)]: Create a zip archive.
  • unzip [zipfile]: Extract a zip archive.

Viewing File Content

  • less [file]: View file content one page at a time.
  • head [file]: View the first lines of a file.
  • tail [file]: View the last lines of a file.
  • cmp [file1] [file2]: Compare two files.
  • diff [file1] [file2]: Show differences between two files.
  • sort [file]: Sort the lines of a file.
  • find [location] -name [filename]: Search for files.

Network Commands

  • ipconfig: Display all network interfaces and their IP addresses.
  • ping [address]: Check connectivity to a host.
    • ping -c [count] [address]: Limit the number of ping requests.
  • traceroute [address]: Display the route packets take to a network host.
  • netstat: Display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
    • netstat -tuln: Show listening ports.
  • ss -tuln: Another way to check for listening ports.
  • sudo ufw: Manage the uncomplicated firewall.

Process Management

  • ps aux: Display a snapshot of current processes.
  • top: Display running system processes and their resource usage.
  • htop: An improved version of top (requires installation).
  • kill [PID]: Kill a process by its process ID.
    • kill -9 [PID]: Force kill a process.
  • pkill [name]: Kill processes by name instead of PID.

System Controls

  • sudo systemctl [command] [service]: Control system services.
    • Commands include start, stop, restart, status.
  • history: Show command history.
  • sudo reboot: Reboot the system.
  • sudo shutdown: Shut down the system.