{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# What is the command line?\n", "\n", "Perhaps the first step toward really empowering you to command your computer to do whatever you will is to learn how to use the command line. This lesson provides a brief introduction to command line skills." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What is a shell?\n", "\n", "A **shell** is a program that takes commands from files or entered interactively through the keyboard and passes them on to the operating system to be executed. A shell is accessed through a **terminal (emulator)**. \n", "Where you would normally execute a command by clicking on a button (e.g. open the Downloads folder by double-clicking on it), a shell lets you perform the same operations by typing commands (e.g. `cd Downloads`).\n", "\n", "We will use JupyterLab's terminal in this tutorial. However, you need not limit yourself to using this. If you are using macOS, you can use the Terminal application. For a Mac, you can fire up the Terminal application. It is typically in the `/Applications/Utilities` folder. Otherwise, hit ⌘-space bar and type `terminal` in the search box, and select the Terminal Application. For Windows, you can use PowerShell, which you can launch through the `Start` menu. If you are using Linux, it's a good bet you already know how to navigate a terminal, but, in most cases, hit the Super-key and type `terminal`. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A very brief historical overview \n", "\n", "Ken Thompson of Bell Labs developed the predecessor to the modern shell for the first release of UNIX in 1971. In 1977, Stephen Bourne introduced the Bourne shell (`sh`) which added the ability to invoke scripts (small reusable programs) from within the shell. The Bourne shell remains relevant. In some cases it is still the default root shell. Shortly afterwards, the C shell (`csh`) was developed which made use of a C-like scripting language. `tcsh` is built on `csh` and is still very common. `bash`, the Bourne again shell was developed by Brian Fox to replace the Bourne shell. It adds many useful features to sh and is the default for several Linux distributions. It used to be the default for macOS until Catalina (2019), when it was replaced by `zsh`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Windows vs. macOS/Linux\n", "Windows 10 enables you to also use `bash`, but you need to activate the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/about). We will not use `bash` for Windows users (unless you want to), but will instead use [PowerShell](https://en.wikipedia.org/wiki/PowerShell), which is also the default shell in JupyterLab's terminal for Windows users. For the simple command line operations we will do in here, PowerShell is almost always sufficient and the syntax is the same. [This cheatsheet](http://cecs.wright.edu/~pmateti/Courses/233/Top/233-CheatSheet.html#Bash_and_PowerShell_Quick_Reference) is a useful reference for comparing `bash` and PowerShell commands.\n", "\n", "In what follows below, we will show the `bash` commands and sometimes provide commentary for Windows users. Here is a brief table comparing `bash` to PowerShell commands.\n", "\n", "| Bash | PowerShell|\n", "|:---:|:---:|\n", "|`cd` | `cd`|\n", "|`mv` | `mv`|\n", "|`pwd` | `pwd`|\n", "|`ls -al` | `ls -Hidden`|\n", "|`rm -rf` | `del -Force -Recurse .\\mydirectory`|\n", "|`cp` | `cp`|\n", "|`mkdir` | `mkdir`|\n", "|`more` | `more`|\n", "|`less` | Does not exist|\n", "|`head -5 myfile.txt` | `gc myfile.txt -head 5`|\n", "|`tail -5 myfile.txt` | `gc myfile.txt -tail 5`|\n", "|`cat ./dir/myfile.txt` | `!type \"dir\\myfile.txt\"`|\n", "\n", "As you can see every command takes some arguments, which specify flags (usually when preceded by `-` or `--`) or files on which to act. The arguments are specified on the same line of the command and separated by spaces. That is to say, a space means \"cue new argument\"." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "*Copyright note: In addition to the copyright shown below, this recitation was developed based on materials from Axel Müller.*" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" } }, "nbformat": 4, "nbformat_minor": 4 }