Here are some Linux commands you might want to know.

Basics

  • whoami: a philosophical question, also prints current username
  • id: prints current user information (e.g., username, UID, GIDs)
  • pwd: print working directory (or use echo $PWD)
  • sudo COMMAND: run command as root
    • Only users and groups in the sudoers file can run sudo. Check if you have sudo permissions with sudo -l.
  • sudoedit FILE: edit file as root with your favorite EDITOR (make sure to export EDITOR=insert-your-favorite-editor first)
  • apt: package management system on Debian-based distros (or use dpkg if you ever need to)
  • bash: The de facto default shell. You might want to learn Bash script.
  • passwd: change your user password
  • man: manual. For example, if you need to look up what abs() is, run man abs. Don’t look up “man abs” like my teammate did.
  • curl URL or wget URL: download stuff from the interwebs without a browser
  • ssh USER@HOST: remotely access a computer running an SSH server
  • systemctl: Chances are your distro runs systemd. You might want to learn what it does.
  • ps & top (& htop / btop): show processes
  • open / xdg-open: open stuff (e.g., files) with the right program

Filesystem

  • ls [ DIR ]: list files in a directory (defaults to current directory)
  • cd [ DIR ]: change working directory (defaults to home)
  • mv A B
    • if B doesn’t exist, rename A to B
    • if B exists and is a file, delete B and rename A to B
  • mv A... B: move files to B (B must be a directory)
  • rm FILE: remove a file
  • rm -r DIR: remove a directory
  • sudo rm -rf --no-preserve-root /: fries your system (please don’t actually run it)
  • sudo dd if=random-linux-distro.iso of=/dev/sdX: makes a bootable USB using ISO (be very certain that of is set to the right device file)
  • for d in /dev/nvme0n1p*; do sudo dd if=/dev/zero of=$d; done: fries your system with SPEED (please don’t actually run it)
  • lsblk: show block devices
  • rmdir DIR: remove an empty directory
  • grep: search for something (string or regex) in a file or directory. Use grep PATTERN FILE and not cat FILE | grep PATTERN.
  • find: find files on the filesystem
  • locate: find files on the filesystem quickly using an index (use updatedb to refresh the index; you can do it in a systemd timer)

File Editing

  • nano FILE: edit FILE in a user-friendly terminal editor
  • vim FILE: edit FILE in a user-unfriendly terminal editor that you don’t know how to exit
  • emacs -nw FILE: edit FILE in a user-unfriendly terminal editor that gives you pinky cancer (evil mode FTW). See Emacs.
  • ed: Yes, this is a text editor. Hope you never have to use it.
  • code [ FILE | DIR ]: edit file / open directory with Visual Studio Code (not necessarily a Linux command per se)

Networking

  • ip / ifconfig: show networking device information (e.g., private IP addresses)
  • ss / netstat: show socket statistics (e.g., open ports)
  • nmap: enumerate ports on a host, or hosts on a network
  • nmcli: Network Manager CLI
  • sudo systemctl restart NetworkManager for when NM decides to give up