- References: Much of the content of these sessions is summarized at our Command line quick reference page.
- Credit: Our materials are based on the Software Carpentry Unix Shell course
- Etherpad: We’ll create an Etherpad where participants who wish to do so can take notes collaboratively. For a quick overview of Etherpad functionality see http://write.flossmanuals.net/etherpad/introduction/.
- Something to play with: Follow the instructions at http://swcarpentry.github.io/shell-novice/setup.html to copy some practice files.
- 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 $SHELLat the command prompt. - Learn the shell on a need-to-know basis.
- 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/.zprofilenow. You'll thank me later.
Change to your home directory, look at it with pwd.
cd ~cd ..cd -cd; cd Desktopcd data-shell/data/s...(tab completion)cd /Users/djb/Desktop/data-shell/data(absolute path)
Change to Desktop/data-shell
ls -Fls -j(unsuppored)man lsls data
Dragging a file from your filesystem Finder/Explorer window to the terminal
ls -a: include hidden files (filenames starting with.)ls -l: show enhanced file information, including date and time stamps, owner and group, permissionsls -t: list in timestamp orderls -G: colored outputls -lh: human readable file sizels -F: decorate filenames according to filetypels -d: don’t recurse into directoriesls -1: single-columnls -d */: list only directories
- Command and filename completion with the
Tabkey - Command history with the arrow keys
- 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 pathchanges the current working directory.ls pathprints a listing of a specific file or directory;lson its own lists the current working directory.pwdprints the user’s current working directory.whoamishows 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
-.