Linux commands - eitan-j/tech-journal GitHub Wiki

Networking

  • ip addr gives network info
  • ifconfig gives network info (old)
  • ping [host] test connectivity to [host]
    • add -c1 to ping once
  • arp -a shows ARP cache

Users & Permissions

  • whoami shows current user
  • sudo -i to become root
  • sudo [executable] to run [executable] as root
  • passwd [user] to change password of [user]
    • leave blank for current user
  • useradd [user] to create new [user]
  • userdel [user] to delete [user]
    • add -r to delete user dir also
  • groupadd [group] to create [group]
  • groupdel [group] to delete [group]
  • usermod -aG [group] [user] to add [user] to group]
    • -aG for append Group
  • chgrp [group] [file] to change [file] to [group]
  • chown [user]:[group] [file] to change [file] ownership to [user]
    • [group] is optional
  • chmod [who][what][which] [dir]
    • The [who][what][which] can be repeated with a comma in between
    • [who] is who you will apply this to
      • Options are u for user (owner), g for group, o for other, and a for all
        • Multiple can be used at once
    • [what] is what to do
      • - to remove, + to add, = to overwrite
    • [which] is which permissions to change
      • r for read, w for write, x for execute
        • Multiple can be used at once
    • [who][what][which] can be replaced with [owner][group][other]
      • Each of these is a single digit base 10 representation of a three digit base 2 number
        • The first bit is for read, second is for write, third is for execute

Installing

  • apt install [program] installs [program] (Debian based)
    • adding -y to the end auto accepts any prompt

DHCP

  • dhclient -r releases DHCP IP address
  • dhclient get new DHCP IP

FTP

  • ftp addr
  • option -i "Turns off interactive prompting during multiple file transfers."
    • Not sure if this is relevant
  • put [file] to put [file]
  • ls lists files and folders
  • get [file] to get [file]
  • passive to enter passive mode
    • passive mode makes all inbound traffic to port 21

Directories

  • cd to change directory
    • cd by itself will go to home directory
    • cd [file] will go to [file]
      • [file] is a absolute directory
    • cd -- to go to last directory
    • cd .. to go up a directory
  • ls to list files
    • ls -a to list hidden files
  • pwd for current directory

Files

  • cat [file] to view [file]
  • cp [file1] [file2] to copy [file1] to [file2]
  • rm [file] to remove [file]
    • rm -r [dir] to remove [dir] and all in it
  • touch [file] to create [file]

General/Meta

  • !! is your last command
    • sudo !! to run last command as root
  • exit to exit
  • fuck to fix last command
  • man [command] to show manual for [command]
  • history to show bash history
    • history -c to clear history
  • [command] | grep [query] to search for [query] in the output of [command]

Fun

  • cbonsai
  • cowsay [string] to make cow say [string]
  • cmatrix
  • fortune for fortune
  • lolcat [file] to view [file] with rainbows
  • asciiquarium