Briljant video of NetwerkChuck turned into a cheat sheet. I have added links to pages where flags are explained.

General

  • ssh {username@ipaddress} - login to server
  • clear
  • apt update - update all repositories. requires sudo
  • apt install {packagename} - install package
  • man {command name} - info about command
  • whatis {command name} - very brief info about command
  • which {command name} - location of command
  • whereis {command name} - location of command, provides all locations
  • uname -a - info on operating system
  • free - amount of free memory
  • df -H - disk space info
  • history - list of previous commands

Users, groups, permissions

  • whoami
  • useradd {username} - add user. requires sudo
  • adduser {username) - add user and set all params
  • su {username} - switch user
  • exit - back to previous user
  • passwd {username} - change password. requires sudo
  • passwd - change own password
  • finger {username} - inspect user. finger must be installed
  • usermod {flag} {value} {user} - modify user properties. link
  • usermod -aG sudo {username} - add user to sudo group. requires sudo permissions

Processes

  • ps -aux - list of processes
  • ps -aux grep {nameofprocess} _- list specific process
  • top - live list of processes
  • htop - same as top, looks nicer
  • kill -9 {PID} - kill process with specified ID
  • pkill -f {processname} - kill process with specified name
  • systemctl start {processname} - starts process
  • systemctl stop {processname} - stops process
  • systemctl status {processname} - status of process
  • systemctl restart {processname} - restart process
  • systemctl enable {processname} - process will start automatically on startup
  • systemctl disable {processname} - process won’t start automatically on startup
  • systemctl daemon-reload - soft reloading, required for changes in service files to take effect after restart
  • nohup {command} - chosen command will keep running after logout/closing terminal
  • {command} & _- command will run in background

Internet

  • wget {url} - get contents of url and stores it in current dir under url last element name
  • curl {url} > {filename} - same
  • ifconfig - find ip address
  • ip address - find ip address
  • ip address grep eth0 - only see eth0 address (sort of)
  • ip address grep eth0 grep inet awk ‘{print $2}’ - really only the ip address
  • cat /etc/resolv.conf - find DNS info
  • resolvectl status - find current DNS server
  • ping {url} - see if website is up. use ctrl c to stop it
  • ping {url} {integer n} - ping url n times
  • traceroute {url} - displays the route taken by the response, all hubs
  • netstat - list of all ports on machine. link
  • netstat -tulpn - more relevant list. only listening tcp and udp with info about process involved
  • ss - socket statistics, similar to netstat, can use -tulpn as well
  • ufw allow {port number} - requires sudo. allows traffic on specified port
  • ufw enable - port from previous command now works

Files

  • ls (-l, -al) - list files
  • pwd - print working directory
  • cd - change directory
  • touch {filename} - create file
  • echo {text} {> filename} - print to console or add text to file
  • nano {filename} - create/open and edit file. exit by ctrl x, type y for save
  • vim {filename} - create/open and edit file. i to start edit, escape :wq to save and exit
  • cat {filename} - read file
  • cat {filename} sort - read file and sort output lines
  • less {filename} - read file page by page
  • head { filename} - read begin of file
  • tail {filename} _- read end of file}
  • stat {filename} file metadata
  • cmp {file1} {file2} - compare two files
  • diff {file1} {file2} - precise descriptions of differences between two files
  • shred {filename} - overwrite file so it becomes unrecoverable
  • mkdir {directory name} - create directory
  • cp {source} {destination} - copy file
  • mv {source} {destination} - move file
  • rm {file} - remove file
  • rmdir (-r) {directory} - remove directory. -r removes recursively
  • ln (-s) {file} {link} - create link to a file
  • source {filename} executes commands in file
  • zip {filename zipfile} {filename original} - zip
  • unzip {filename zipfile} - unzip, you get options if file exists
  • find {directory} (-name, -type, -perm etc) {expression} - link and another link
  • chmod {change formula} {filename} - “change mode”, change file permissions. link
  • chown {options} {user/group} {file} - change ownership of file. link

<
Previous Post
Linux in-depth 1
>
Next Post
Systemd Units