Skip to content

Instantly share code, notes, and snippets.

@kevinnls
Last active August 22, 2021 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinnls/6005a31202eb9c10f7ec498271d10d85 to your computer and use it in GitHub Desktop.
Save kevinnls/6005a31202eb9c10f7ec498271d10d85 to your computer and use it in GitHub Desktop.
or at least the ones i am not too tired to note down. i'm lazy and forgetful. this is not the full list.

that's it for the basics

or at least the ones i am not too tired to note down. i'm lazy and forgetful. this is not the full list.

  • ssh login to a remote machine

    • password
    • ssh keys
      • generate: ssh-keygen -t ed25519 -C [meaningful comment]
      • connect: ssh -i [path/to/key] user@host
  • *nix

    • UNIX an operating system of old
      • has philosophy regarding how computer systems should function
    • various branches based on UNIX follow some or all of the philosophy
    • some philosophy followed on all branches (not verbatim)

      • everything is a file
      • make every program do one thing; and do it well
  • paths

    • indication of where a file or directory is on the filesystem
    • use command pwd to find path of current directory (aka working directory)
    • filesystem is tree-like hierarchy starting / - root
    • each level is separated by /
      • i.e /home/avengers = root » home » avengers
    • home dir

      • /home/<your username> = your home directory; holds personal files
      • ~ in a path is often synonymous to your home directory
    • path types

      • absolute paths

        • start at /
        • working dir doesn't matter while using paths of this type
      • relative paths

        • start at working directory
          • . means working directory; optional
          • .. means parent of .
        • working dir matters while using paths of this type
    • hidden files and directories

      • have names starting with . (not to be confused with working dir)
      • ./.secrets path to hidden file in .
    • bin dirs

      • hold applications; some common ones are
        • ~/.local/bin
        • ~/.bin
        • /usr/bin/
        • /usr/local/bin
    • src dirs

      • hold source package of apps installed from source; some options are
        • ~/.local/src
        • /usr/local/src
  • stdout

    • special file that shows text output
  • stderr

    • special file that shows text errors
  • /dev/null

    • special file that makes everything written to it disappear
  • shell is the interface

    • bash is common and has good features
    • the shell

      • treats everything as space-separated words
        • aka word-splitting
        • prevent using
          • " or ' around the entire phrase
            echo "hello world"
          • or escape () the spaces
            echo hello\ world
        • words with special meaning (variables, command substitution) in shell work inside "..." but not '...'
      • is mostly case-sensitive
        • date ≠ Date
      • supports variables
        • accessible using $var_name
        • set using var_name=value
        • echo $var_name to view; empty/unset var prints blank line
        • has special ones
          • $0 - current application
          • $_ - last arg of previous command
          • $? - exit code or previous command
          • $USER - username
          • $HOME - path to home directory of user
          • $1 - $9 - positional args of current command
            (useful in scripting using bash)
          • $PATH - list of paths to directories holding executable files expected as commands. each path is separated by :
      • expects valid command names
        • a command is
          • an executable file in $PATH
          • absolute or relative path to an exectuable file
          • something built into the shell
      • substitutes commands wrapped in `` with output
        • e.g. echo today's date is : `date`
          • `date` will be subtituted by its output and passed as argument to echo
      • redirects stdout and stderr using >
        • lhs of > is source
          • 1 is stdout and 2 is stderr of the current command
          • no space between source and >
            • i.e one unsplit unit 1>; not 1 >
          • lack of source implies 1
          • BASH only &> indicates both 1 and 2
        • rhs of > is the destination
          • usually path to a file
          • can also be &1 or &2 to refer to stdout and stderr respectively
            • thus shell way of writing to stderr is echo hello world 1>&2
        • behaviour
          • > overwrites destination
          • >> appends to destination
        • NB shell sees > in any part of command as redirection, not as command argument, unless escaped with one of " ' \
      • uses patterns
        • * can be used to match anything in a path
          • ls /home/user/D* = list items in ~ starting with capital D
      • executes login scripts
        • ~/.profile
          • set variables (incl PATH) for current user
        • (for bash) ~/.bashrc
          • configure other bash options for current user
        • /etc/profile
          • set variables (incl PATH) for all users
  • applications

    • types

      • compiled
        • are transformed to binary that can be executed directly
      • interpreted (scripts)
        • interpreted apps need to be called with the interpreter - python /path/to/script.py - instead the !#/path/to/interpreter shebang is used at the start of the script file
    • should have permission to execute
      • granted using chmod +x </path/to/app>
    • need to be in $PATH dirs to be executed directly from the shell
    • can also be executed using absolute or relative path
  • common applications

    • pwd
    • cd [path]
    • ls [path]
      • ls -1 - show in one column
      • ls -a - incl. hidden files
      • ls -l - show more info
    • echo
    • mkdir [path]
      • mkdir -p - create required non-existent directory along the way
    • touch [path]
    • `cp [src paths...] [dest path]
      • cp -r - copy a directory
    • mv [src paths...] [dest path]
    • chmod [options] [path] - change permission
      • chmod +x path - make executable
    • file - show filetype
    • date
    • man [name of command] - manual for command
    • nano - text editor
    • git
      • git init - make . a git repo
      • git clone [url]
        • git clone [url] [path] - clone to directory named [path] (should be empty)
      • git add [paths] - stage files; prepare for commit
      • git commit -m "[meaningful message]" - commit staged changes
      • git remote add [remote name] [remote url] - remote name is usually origin
      • git fetch
      • git pull
        • git pull --set-upstream origin main - first time pull
      • git push
        • git push --set-upstream origin branch - first time push
      • git branch [name] - create branch [name] based on last commit
      • `git checkout [branch name] - switch to branch
  • uncommon applications

    • finger - show logged in users
      • finger [username] - info on user
    • chsh - change login shell
    • bash
    • sh
    • gcc [C source file] - compile C code
      • gcc -o [name] - output name for compiled file (default: a.out)
@xeldrago
Copy link

Wow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment