Skip to content

Linux Basics#







  • which: display executable's location
  • type: describe a command
  • rm: delete directory

    rm -rf

  • find: find file/directory recursively

    find . -iname _gsdata_ -exec rm {} +
    find . -type d -name _gsdata_ -print -exec rm -rfv {} +
    find . -type f \( -name .DS_Store -o -name Thumbs.db \) -print -exec rm {} +

  • tree: show directory structure as tree

    tree -d [dir]   # list directories only
    tree -ah        # include hidden, human readable
    tree -fp -L <n> # include paths, permissions, limit up to N levels

  • df: display free disk space

    df -lhT # show usage of all mounted filesystems

  • du: disk usage/size of directory

    du -sh fooDir/

Package Management#

Command Description
apt list --installed list installed pkgs
sudo apt policy list installed `repositories'
apt show <pkg> show dependencies of pkgs
sudo apt install <pkg> install <pkg>
sudo apt remove <pkg> uninstall <pkg>
sudo apt autoremove uninstall unused dependencies e.g. <pkg> leftover deps that were auto installed but longer required
sudo apt purge <pkg> uninstall <pkg> configuration files e.g. located under /etc

Console Management#

  • env: print the environment variables

  • tail: displays the last part of a file

tail -f [file]      # outputs last lines in realtime
tail -n 100 [file]  # outputs last n lines
  • bind: configure keybinds for terminal

  • bind: query keybinds

    bind -l      # List all bindable readline functions
    bind -v      # List variables and values
    bind -psX    # List keys bound to readline functions, macros, and shell executions
    bind -q <fn> # Query about which keys invoke the named function

  • bind: change keybinds

    bind -u <fn>                 # Unbind all keys which are bound to the named function
    bind -r <keys>               # Remove the binding for <keys>
    bind -f <filename>           # Read key bindings from <filename>
    bind -x '"<keys>": "<cmds>"' # Execute <cmds> when <keys> is entered

  • less: console pager
    | Navigation Key | Action |
    | --------------------- | ------------------------------------- |
    | down/up,j/k | move down/up one line |
    | space bar/b | move down/up one page |
    | left/right | scroll left/right horizontally |
    | g/G,Home/End | go to start/end line |
    | /pattern/?pattern | search forward/backward for pattern |
    | n/N | go to next/previous occurrence |
    | q | Quit less |


  • list connections
netstat --all | head -n 15
sudo netstat --tcp --udp --listening --program --numeric --extend
  • query interaces
ip a
netstat -ie


  • stat: pretty print stats about file
stat [file]
  • permission attributes
Text Only
.rwxrwxrwx  path/to/file
└│││││││││─ file type attribute
 │││││││││   -: file
 │││││││││   d: directory
 │││││││││   l: symbolic link
 │││││││││   c: character special file representing byte stream device e.g. /dev/null
 │││││││││   b: block special file representing block stream device e.g. hard drive
 ├││││││││─ u: user owner
 └││││││││─  r: read
  └│││││││─  w: write
   └││││││─  x: execute
    ├│││││─ g: group owner
    └│││││─  r: read
     └││││─  w: write
      └│││─  x: execute
       ├││─ o: other
       └││─  r: read
        └│─  w: write
         └─  x: execute
  • id: display user identity

  • umask: set the default file permissions

  • chmod: change permissions to folders and files

find . -type d -exec chmod 755 {} +
find . -type f -exec chmod 644 {} +
  • chmod recursively to 775/664
chmod -R a=,a+rX,u+w,g+w /some/path/here
          ^  ^    ^   ^ adds write to group
          |  |    | adds write to user
          |  | adds read to all and execute to all folders (which controls access)
          | sets all to `000`
  • chown: change ownership to user/group recursively
chown -R user:group /some/path/here

Process Management#

  • id: find UID/GID for user

    id [username]

  • ps: list running processes

    ps aux

  • pkill: kill process by name

    pkill chrome


  • systemd: initialization system and service manager

  • systemd quickstart guide

  • systemctl: manage services/daemons

  • systemctl quickstart guide

    • systemctl start [name.service]
    • systemctl stop [name.service]
    • systemctl restart [name.service]
    • systemctl reload [name.service]
    • systemctl status [name.service]
    • systemctl is-active [name.service]
    • systemctl list-units --type service --all
    • unit types
    $systemctl list-unit --type=help
    service   # service
    target    # group of units
    mount     # filesystem mountpoint
    automount # filesystem auto-mountpoint
    device    # kernel device names, which you can see in sysfs and udev
    path      # file or directory
    scope     # external processes not started by systemd
    slice     # a management unit of processes
    snapshot  # systemd saved state
    socket    # IPC (inter-process communication) socket
    swap      # swap file
    timer     # systemd timer
  • list services

    systemctl | grep running                                       # Loaded+Active
    systemctl --no-pager | grep running | column -t                # For more readable output
    systemctl list-units --no-pager --all                          # Loaded services: Active+Pending+Failed+Inactive+Dependents
    systemctl list-units --no-pager --all --state=inactive         # Loaded services: Inactive
    systemctl list-units --no-pager --type=service                 # Loaded services: Active+Pending+Failed
    systemctl list-units --no-pager --type=service --state=running # Loaded services: Running
    systemctl list-unit-files --no-pager --type=service            # Installed services: Loaded+Unloaded
  • start/stop/restart the specified service

    systemctl start [service]
    systemctl stop [service]
    systemctl restart [service]
  • enable/disable service to auto start at boot time

    systemctl enable [service]
    systemctl disable [service]
  • show/check service current status/runtime information

    systemctl status [service]
    systemctl is-active [service]
    systemctl is-enabled [service]
    systemctl is-failed [service]
    systemctl list-dependencies [service]


  • syslog: a protocol for transferring log messages
  • dmesg: command that prints kernel logs

    dmesg -H         # command that prints kernel logs

  • journalctl: service that collects logs from systemd

    journalctl                              # all boot log entries
    journalctl -k                           # all boot kernel entries
    journalctl -b                           # current boot entries
    journalctl -b -k                        # current boot kernel entries
    journalctl -b --priority=err            # all error or higher logs since last boot
    journalctl -b --priority=err..warning   # all warning to notice since last boot
    # Log Levels
    #  emerg (0): system is unusable
    #  alert (1): action must be taken immediately
    #   crit (2): critical conditions
    #    err (3): error conditions
    #   warn (4): warning conditions
    # notice (5): normal but significant condition
    #   info (6): informational
    #  debug (7): debug-level messages