Shell

Every operating system, by definition, has some sort of interface to work with. Most people use the graphical user interface (GUI), as it is easy to understand and navigate, and does not require any specific knowledge. However, graphical interfaces are complex, demanding, and not reproducible. Even before the GUI existed, programmers used code-based interfaces to interact with computers—shells. Both macOS and Linux systems are Unix-based and, hence, leverage the same shell interface, Bash. Windows, on the other hand, has two, a very basic command prompt, and a PowerShell (which we recommend using). There are also ways to install and use Bash on Windows. All those systems allow you to create, change, and delete files and folders, run programs and utilities, and so on. In addition, because those systems are based on textual commands (code, essentially), commands can be stacked, stored, and executed (and re-executed) together as scripts. As text requires minimum memory to exchange, this interface is used to operate remote servers. 

You can access the shell on your computer in at least three ways:

  • Open the original shell terminal. All three operating systems have built-in shell terminals.
  • In Jupyter, open the terminal window via the launcher tab.
  • Open the VS Code Terminal (window four in our interface overview).

Let's use VS Code for now—it has a handy feature for opening the terminal in the current project's folder, thereby saving us time. Note that some commands differ in terms of the name and interface between two systems, although many are similar. The following are a few of the most frequent commands, which are the same on both systems:

Operation Bash command CMD commands Example (bash)
Change directory cd [path] cd [path] cd ../anotherproject/data/
Move file/folders mv [current path] [new path] move [current path] [new path] mv data.csv ../data/dataset1.csv
Copy file cp [current path] [new path] copy [current path] [new path] cp data/data.csv data/dataset2.csv
Retrieve the content of a file cat [path] type [path] cat environment.yaml
Remove file or folder rm [path]  del [path] rm -r data/*.csv (note: this will not move files to the trash bin. Once deleted, the files will not be available)
Show manual man [command] help [command] man rm (use q to get out of the manual)
Show current position (the folder you're in) pwd echo %CD% pwd
Show files and folders in the current folder ls [-l for table format] dir  ls -l
Create file

touch [filename] 

type NUL >> [filename] touch .gitignore
Create folder

mkdir [folder_name]

mkdir [folder_name] mkdir code
Send the string to an output

echo [options] [string]

echo [options] [string]

echo "Hello world"
Filter multiple strings

grep [pattern]

findstr [pattern] [filename]

echo -e "Hello world"

 

In the following examples, we use the double period as a representation of going one level up in the folders tree. Similarly, an asterisk (wildcard) can be used to specify all files/folders following the pattern (for example, where there are any letters/numbers in its place). For example, data/*.csv represents any CSV files in the data folder.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset