Skip to content

Latest commit

 

History

History
186 lines (128 loc) · 3.3 KB

lecture_03.md

File metadata and controls

186 lines (128 loc) · 3.3 KB

Lecture 3

The command line


CLI

Command line interface


Terminals


We'll be using:

  • Windows: Git BASH
  • macOS: Terminal

Open it up.


Distributions


Examples

  • Darwin (macOS)
  • Debian
  • Ubuntu
  • Mint
  • Fedora
  • Red Hat Enterprise Linux (RHEL)

Paths

  • Separators:
    • Windows (outside of Git BASH): \
    • macOS/Linux: /
  • . - current directory
  • .. - parent directory
  • Absolute vs. relative

Navigation

  • pwd - path of working directory
  • ls - list files
    • ls -al - list all files (with dotfiles) with more details
  • cd - change directory
  • Mac:
    1. From Finder, right-click on folder
    2. Click Services
    3. Click New Terminal at Folder

Control-r allows you to search your command history


Working with files

  • Viewing
    • cat
    • less
  • mv
  • cp
  • mkdir
  • rmdir
  • find
  • Editing
    • nano
    • vim

If files have spaces or special characters, need to put quotes around them.

  • Best to avoid these when naming files, sticking to:
    • Letters
    • Numbers
    • Periods
    • Hyphens
    • Underscores
  • For Python files, snake case is most common.

Exiting/quitting

  • less: q
  • nano: control-x
  • vim: escape, then :q!
  • Other command line tools: control-c

Worst case, close your Terminal, and that will kill whatever process was running.


Other shell stuff

  • echo
    • echo abc | less
  • Exit codes
    • echo $?
  • Environment variables
  • which
    • which jupyter
    • which -a python3
  • $PATH
  • Pipes
    • ls | xargs cat
  • Redirecting output
  • grep
  • sudo
  • man

Example

Uses a "wildcard":

  1. find . -name 'lecture_*.md'
  2. find . -name 'lecture_*.md' | sed -E 's/([0-9]{2})/0\1/'

Shells

  • PowerShell
  • Bash
  • zsh

Dependency/package management

Done through package managers


Python


Operating system



Note to self: Send terminal commands+output.