Here are some Linux commands you might want to know.
Basics
whoami: a philosophical question, also prints current usernameid: prints current user information (e.g., username, UID, GIDs)pwd: print working directory (or useecho $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.
- Only users and groups in the sudoers file can run sudo. Check if you have sudo permissions with
sudoedit FILE: edit file as root with your favoriteEDITOR(make sure toexport EDITOR=insert-your-favorite-editorfirst)apt: package management system on Debian-based distros (or usedpkgif 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, runman abs. Don’t look up “man abs” like my teammate did. curl URLorwget URL: download stuff from the interwebs without a browserssh USER@HOST: remotely access a computer running an SSH serversystemctl: Chances are your distro runs systemd. You might want to learn what it does.ps&top(&htop/btop): show processesopen/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 filerm -r DIR: remove a directorysudo 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 thatofis 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 devicesrmdir DIR: remove an empty directorygrep: search for something (string or regex) in a file or directory. Usegrep PATTERN FILEand notcat FILE | grep PATTERN.find: find files on the filesystemlocate: find files on the filesystem quickly using an index (useupdatedbto refresh the index; you can do it in a systemd timer)
File Editing
nano FILE: editFILEin a user-friendly terminal editorvim FILE: editFILEin a user-unfriendly terminal editor that you don’t know how to exitemacs -nw FILE: editFILEin 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)