Introducing the Shell – Introduction to the Command Line for Economics (2024)

Overview

Teaching: 20 min
Exercises: 10 min

Questions

  • What is a command shell and why would I use one?

  • How can I move around on my computer?

  • How can I see what files and directories I have?

  • How can I specify the location of a file or directory on my computer?

Objectives

  • Describe key reasons for learning shell.

  • Navigate your file system using the command line.

  • Access and read help files for bash programs and use help files to identify useful command options.

  • Demonstrate the use of tab completion, and explain its advantages.

What is a shell and why should I care?

A shell is a computer program that presents a command line interfacewhich allows you to control your computer using commands enteredwith a keyboard instead of controlling graphical user interfaces(GUIs) with a mouse/keyboard combination.

There are many reasons to learn about the shell:

  • The shell makes your work less boring. In economics you often need to dothe same set of tasks with a large number of files. Learning the shell will allow you toautomate those repetitive tasks and leave you free to do more exciting things.
  • The shell makes your work less error-prone. When humans do the same thing a hundred different times(or even ten times), they’re likely to make a mistake. Your computer can do the same thing a thousand timeswith no mistakes.
  • The shell makes your work more reproducible. When you carry out your work in the command-line (rather than a GUI), your computer keeps a record of every step that you’ve carried out, which you can use to re-do your work when you need to. It also gives you a way to communicate unambiguously what you’ve done, so that others can check your work or apply your process to new data.
  • Many econometrics tasks require large amounts of computing power and can’t realistically be run on yourown machine. These tasks are best performed using remote computers or cloud computing, which can only be accessedthrough a shell.

In this lesson you will learn how to use the command line interface to move around in your file system.

How to access the shell

On a Mac or Linux machine, you can access a shell through a program called Terminal, which is already availableon your computer. If you’re using Windows, you’ll need to download a separate program to access the shell.

We will spend most of our time learning about the basics of the shellby manipulating some observational data frequently used in economics. Some of the data we’re going to be working with is quite large, andwe’re also going to be using other packages in laterlessons to work with this data.

After launching your terminal, you will see something like this

bash-5.0$ 

This provides a lot of information about the remote server that you’re logging in to. We’re not going to use most of this information forour workshop, so you can clear your screen using the clear command.

$ clear

This will scroll your screen down to give you a fresh screen and will make it easier to read. You haven’t lost any of the information on your screen. If you scroll up, you can see everything that has been output to your screenup until this point.

Navigating your file system

The part of the operating system responsible for managing files and directoriesis called the file system.It organizes our data into files,which hold information,and directories (also called “folders”),which hold files or other directories.

Several commands are frequently used to create, inspect, rename, and delete files and directories.

Preparation Magic

If you type the command:PS1='$ 'into your shell, followed by pressing the Enter key,your window should look like our example in this lesson.
This isn’t necessary to follow along (in fact, your prompt may haveother helpful information you want to know about). This is up to you!

$

The dollar sign is a prompt, which shows us that the shell is waiting for input;your shell may use a different character as a prompt and may add information beforethe prompt. When typing commands, either from these lessons or from other sources,do not type the prompt, only the commands that follow it.

Let’s find out where we are by running a command called pwd(which stands for “print working directory”).At any moment, our current working directoryis our current default directory,i.e.,the directory that the computer assumes we want to run commands in,unless we explicitly specify something else.Here,the computer’s response is /home/dcuser,which is the top level directory within our cloud system:

$ pwd
/Users/koren/Downloads/shell-economics

FIXME: add callout about home directory and Downloads folder

Let’s look at how our file system is organized. We can see what files and subdirectories are in this directory by running ls,which stands for “listing”:

$ ls
LICENSE.mdREADME.mdcodedatadc-economics.zipdoc

ls prints the names of the files and directories in the current directory inalphabetical order,arranged neatly into columns. We’ll be working within the data subdirectory, and creating new subdirectories, throughout this workshop.

The command to change locations in our file system is cd, followed by adirectory name to change our working directory.cd stands for “change directory”.

Let’s say we want to navigate to the data directory we saw above. We canuse the following command to get there:

$ cd data

Let’s look at what is in this directory:

$ ls
derivedraw

We can make the ls output more comprehensible by using the flag -F,which tells ls to add a trailing / to the names of directories:

$ ls -F
derived/raw/

Anything with a “/” after it is a directory. Things with a “*” after them are programs. Ifthere are no decorations, it’s a file.

ls has lots of other options. To find out what they are, we can type:

$ man ls

Some manual files are very long. You can scroll through the file usingyour keyboard’s down arrow or use the Space key to go forward one pageand the b key to go backwards one page. When you are done reading, hit qto quit.

Challenge

Use the -l option for the ls command to display more information for each item in the directory. What is one piece of additional information this long formatgives you that you don’t see with the bare ls command?

Solution

$ ls -l
total 0drwxr-xr-x@ 31 koren staff 992 Oct 9 10:17 deriveddrwxr-xr-x@ 4 koren staff 128 Oct 9 10:16 raw

The additional information given includes the name of the owner of the file,when the file was last modified, and whether the current user has permissionto read and write to the file.

No one can possibly learn all of these arguments, that’s what the manual pageis for. You can (and should) refer to the manual page or other help filesas needed.

Let’s go into the raw directory and see what is in there.

$ cd raw$ ls -F
cepii/worldbank/

We keep navigating deeper into the worldbank subdirectory.

$ cd worldbank$ ls -F
WDICountry-Series.csv*WDICountry.csv*WDIData.csv*WDIFootNote.csv*WDISeries-Time.csv*WDISeries.csv*

This directory contains six files with .csv extensions. A CSV (comma separated values) file stores tabular data (numbers and text) in plain text.

Shortcut: Tab Completion

Typing out file or directory names can waste alot of time and it’s easy to make typing mistakes. Instead we can use tab complete as a shortcut. When you start typing out the name of a directory or file, thenhit the Tab key, the shell will try to fill in the rest of thedirectory or file name.

Return to your home directory:

$ cd

then enter:

$ cd Downloads/she<tab>

The shell will fill in the rest of the directory name forshell-economics.

Now change directories to worldbank in raw, which is in data.

$ cd data$ cd raw$ cd worldbank

Using tab complete can be very helpful. However, it will only autocompletea file or directory name if you’ve typed enough characters to providea unique identifier for the file or directory you are trying to access.

Try to access oneof our sample files:

$ ls W<tab>

The shell auto-completes your command to WDI, because all file names in the directory begin with this prefix. When you hitTab again, the shell will list the possible choices.

$ ls WDI<tab><tab>
WDICountry-Series.csv WDICountry.csv WDIData.csv WDIFootNote.csv WDISeries-Time.csv WDISeries.csv 

Tab completion can also fill in the names of programs, which can be useful if youremember the beginning of a program name.

$ pw<tab><tab>
pwd pwd_mkdb pwhich pwhich5.18 pwpolicy 

Displays the name of every program that starts with pw.

Summary

We now know how to move around our file system using the command line.This gives us an advantage over interacting with the file system througha GUI as it allows us to work on a remote server, carry out the same set of operations on a large number of files quickly, and opens up many opportunities for using software that is only available in command line versions.

In the next few episodes, we’ll be expanding on these skills and seeing how using the command line shell enables us to make our workflow more efficient and reproducible.

Key Points

  • The shell gives you the ability to work more efficiently by using keyboard commands rather than a GUI.

  • Useful commands for navigating your file system include: ls, pwd, and cd.

  • Most commands take options (flags) which begin with a -.

  • Tab completion can reduce errors from mistyping and make work more efficient in the shell.

Introducing the Shell – Introduction to the Command Line for Economics (2024)
Top Articles
The Ultimate Beginner’s Guide to Arbitrum
Average Salary Around the World
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
Things To Do In Atlanta Tomorrow Night
Non Sequitur
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Cvs Sport Physicals
Mercedes W204 Belt Diagram
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Otter Bustr
Selly Medaline
Latest Posts
Article information

Author: Kimberely Baumbach CPA

Last Updated:

Views: 5493

Rating: 4 / 5 (61 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Kimberely Baumbach CPA

Birthday: 1996-01-14

Address: 8381 Boyce Course, Imeldachester, ND 74681

Phone: +3571286597580

Job: Product Banking Analyst

Hobby: Cosplaying, Inline skating, Amateur radio, Baton twirling, Mountaineering, Flying, Archery

Introduction: My name is Kimberely Baumbach CPA, I am a gorgeous, bright, charming, encouraging, zealous, lively, good person who loves writing and wants to share my knowledge and understanding with you.