FahamLah

Linux & Networking commands

One page per command. What it does, when to use it, how risky it is.

Move around and read files

  • pwdPrints the path of the room (folder) you stand in.Risk: Safe
  • cdWalks you into another folder.Risk: Safe
  • lsLists what is in a folder.Risk: Safe
  • catPrints a whole file at once.Risk: Safe
  • lessShows a long file one screen at a time. q quits.Risk: Safe
  • headShows the first lines of a file (10 unless you say -n).Risk: Safe
  • tailShows the last lines of a file: the newest ones in a log.Risk: Safe
  • mkdirMakes a new folder.Risk: Safe
  • cpCopies a file. The first one stays. It replaces a file with the same name without asking.Risk: Careful
  • mvMoves or renames a file or folder. It replaces a file with the same name without asking.Risk: Careful
  • rmDeletes files for good. There is no bin and no undo.Risk: Can lose work
  • touchMakes an empty file (or updates a file's time).Risk: Safe

Find and search

  • findSearches a folder and every folder inside it for matching names.Risk: Safe
  • grepPrints only the lines that contain a word.Risk: Safe
  • wcCounts lines (-l), words or bytes.Risk: Safe
  • sortPuts lines in order: A to Z, or by number with -n.Risk: Safe
  • uniqJoins repeated lines that sit together. -c counts them.Risk: Safe
  • cutKeeps only some columns of each line.Risk: Safe
  • sedChanges text on its way through. With -i it edits the file itself.Risk: Careful

Users and permissions

  • idShows a user's number and every group (team) they belong to.Risk: Safe
  • sudoRuns one command as root, the user with every key. The server writes it down.Risk: Careful
  • sudo useraddAdds a new user to the server.Risk: Careful
  • sudo usermodChanges a user, for example adds them to a group.Risk: Careful
  • chmodChanges the keys on a file: who may read, write or run it.Risk: Careful
  • sudo chownHands a file or folder to another owner (and group). Needs root.Risk: Careful

Processes, services and logs

  • psLists processes: programs at work, with their PID.Risk: Safe
  • topA live list of processes, busiest first. q quits.Risk: Safe
  • pgrepPrints the PIDs of processes that match a name.Risk: Safe
  • killSends a signal to a process: TERM (please stop) by default, KILL with -9.Risk: Careful
  • jobsLists the programs this terminal started in the background.Risk: Safe
  • exportPins a variable on the wall, so programs you start can read it.Risk: Safe
  • whichShows which file runs when you type a command name.Risk: Safe
  • sudo systemctlTalks to systemd, the shift manager: start, stop and check services.Risk: Careful
  • sudo journalctlReads the journal, systemd's diary of what services said.Risk: Safe

Packages

  • sudo aptFinds, installs and removes programs from Debian's own store.Risk: Careful

Network checks

  • ipShows this machine's addresses and the way out (its routes).Risk: Safe
  • ssLists the ports that programs listen on.Risk: Safe
  • getent hostsTurns a name into a number the way programs do: /etc/hosts first, then DNS.Risk: Safe
  • digAsks DNS, the phone book, for a name. It skips /etc/hosts.Risk: Safe
  • curlSpeaks HTTP with a web counter and prints its reply.Risk: Safe
  • openssl s_clientOpens a sealed line like a browser and shows the server's certificate.Risk: Safe
  • sudo ufwDebian's easy firewall: the guard's list of who may come in.Risk: Careful
  • pingSays hello to a machine and times the echo.Risk: Safe
  • tracerouteLists every exchange (hop) on the road to a machine.Risk: Safe

Remote servers and disks

  • sshOpens a sealed line to another machine, so you can type there.Risk: Safe
  • ssh-keygenMakes a key pair: a padlock (.pub) and its one key.Risk: Safe
  • ssh-copy-idHangs your padlock on a server: adds your public key to its authorized_keys.Risk: Safe
  • scpCopies files over SSH. It overwrites a file with the same name there.Risk: Careful
  • rsyncMakes a folder there match a folder here, sending only the changes.Risk: Careful
  • dfShows how full each disk is.Risk: Safe
  • duShows how much space folders and files take.Risk: Safe

Scripts and schedules

  • crontabInstalls or shows your roster of scheduled jobs.Risk: Careful
  • systemctl list-timersShows systemd timers: when each runs next and what it starts.Risk: Safe
  • setStrict mode: a script stops at the first failure, unknown jar or broken pipe.Risk: Safe