Skip to content

Latest commit

 

History

History
80 lines (61 loc) · 3.71 KB

File metadata and controls

80 lines (61 loc) · 3.71 KB

Command line 1 for Mac


General

Why and how do we use the shell?

  • The shell is a program that runs other programs.
  • We use the shell to interact with the computer on the command line (CLI ~ GUI).
  • The Unix philosophy is that you can pipe (chain) together small commands, each of which does one thing well, to do something complex. You can’t do this in a GUI.
  • MacOS 10.14 and earlier default: bash = ‘Bourne again shell’ (the original Bourne shell is sh, which you will still run into sometimes!)
  • MacOS 10.15 and later default: zsh = 'Z shell', an "extended Bourne shell". Works almost but not entirely like bash.
  • Not sure which shell you're using? Type echo $SHELL at the command prompt.
  • Learn the shell on a need-to-know basis.

Launching the shell

  • The Terminal.app that you will find in the Applications → Utilities folder. (Many Mac users prefer the free third-party https://www.iterm2.com/, but in this class we will use Terminal.)
  • IF YOU ARE USING ZSH: Run the command echo setopt interactivecomments >> $HOME/.zprofile now. You'll thank me later.

Looking around

Change to your home directory, look at it with pwd.

  • cd ~
  • cd ..
  • cd -
  • cd; cd Desktop
  • cd data-shell/data/s... (tab completion)
  • cd /Users/djb/Desktop/data-shell/data (absolute path)

Change to Desktop/data-shell

  • ls -F
  • ls -j (unsuppored)
  • man ls
  • ls data

Dragging a file from your filesystem Finder/Explorer window to the terminal

ls switches

  • ls -a: include hidden files (filenames starting with .)
  • ls -l: show enhanced file information, including date and time stamps, owner and group, permissions
  • ls -t: list in timestamp order
  • ls -G: colored output
  • ls -lh: human readable file size
  • ls -F: decorate filenames according to filetype
  • ls -d: don’t recurse into directories
  • ls -1: single-column
  • ls -d */: list only directories

History and completion

  • Command and filename completion with the Tab key
  • Command history with the arrow keys

Summary

  • The file system is responsible for managing information on the disk.
  • Information is stored in files, which are stored in directories (folders).
  • Directories can also store other directories, which forms a directory tree.
  • cd path changes the current working directory.
  • ls path prints a listing of a specific file or directory; ls on its own lists the current working directory.
  • pwd prints the user’s current working directory.
  • whoami shows the user’s current identity.
  • / on its own is the root directory of the whole file system.
  • A relative path specifies a location starting from the current location.
  • An absolute path specifies a location from the root of the file system.
  • Directory names in a path are separated with ‘/’ on Unix (including Mac OS)
  • .. means ‘the parent directory = the directory above the current one’
  • . on its own means ‘the current directory’. Why would we need this?
  • Most filenames have conventional extensions: .txt, .xml, etc.
  • Most commands take options (flags) which begin with a -.