Day 23 - Bash/Terminal

Fall 2022

Dr. Jared Joseph

November 02, 2022

Overview

Timeline

  • What is the Terminal?
  • Working with the Terminal
  • Common Commands
  • Code-Along

Goal

To learn how to navigate through a directory structure in the terminal

What is the Terminal

Why Use This?

  • It’s fast (computationally)
  • You can interface it with R or other languages
  • You can alter massive sets of files all at once
  • You can write code to share
  • Sometimes its the only choice

Context

Working with the Terminal

Terminal Overview

Commands in the Terminal

Getting Help

File Paths

We have been using file paths all along.

Dot (.) is “here,” so

read.csv("./data/dates.csv)

Is “start here, then look in data for dates.csv

.
├── data
│   ├── country_stats.csv
│   ├── country_users.csv
│   ├── dates.csv
│   ├── landing_page.csv
│   ├── pages.csv
│   ├── project_1_data.zip
│   ├── referrals.csv
│   ├── search.csv
│   ├── shop.csv
│   ├── state_stats.csv
│   └── state_users.csv
├── docs
│   └── standards_report.qmd
├── Project-1-SCMA.Rproj
├── src
│   └── PUT_CODE_HERE.txt
└── vis
    └── SAVE_VIS_HERE.txt

Permissions

Every file on a computer has certain permissions attached to it.


On your computer, you typically have access to everything. On a shared computer, you may not.


On your own computer, you can run commands as super-user (sudo) to run anything regardless of permissions.

read
Can you open the file and look at it?
write
Can you make changes to the file and save them?
execute
Can you run the program (if it is one)?

Common Commands

Common Commands

ls
List files
cd
Change directory
cat
Concatenate
man
Manual for a ton of commands
nano
Tiny text editor
touch
Creates an empty file
mkdir
Makes an empty directory
cp
Copies a file or directory
mv
Moves a file or directory
rm
REMOVE FOREVER

ls

List files

ls [Where you want to list] [Optional flags]

Common Flags:

  • -l Provide extra information
  • -h make the output human readable
  • -a show all files, even hidden ones

cd

Change Directory

cd [where you want to go]

  • Use cd ~ to return to your user folder
  • Can take absolute or relative paths
    • cd .. will take you up one level
.
├── data
│   ├── country_stats.csv
│   ├── country_users.csv
│   ├── dates.csv
│   ├── landing_page.csv
│   ├── pages.csv
│   ├── project_1_data.zip
│   ├── referrals.csv
│   ├── search.csv
│   ├── shop.csv
│   ├── state_stats.csv
│   └── state_users.csv
├── docs
│   └── standards_report.qmd
├── Project-1-SCMA.Rproj
├── src
│   └── PUT_CODE_HERE.txt
└── vis
    └── SAVE_VIS_HERE.txt

cat

Concatenate

cat [path to file to Concatenate]

Will print out the fill content of a file smooshed into one long string of characters

man

Manual

man [name of command]

A community driven manual that provides more readable help for a ton of commands. Always a great palce to start.

touch & mkdir

touch (create a file)

touch [name of empty file you want to make]

mkdir (make directory)

mkdir [name of directory you want to make]

cp & mv

cp (copy)

cp [path of file/directory to copy] [path to where to create copy]

Will create a copy of whatever you point it at.

mv (move)

mv [path of file/directory to move] [path of where to move to]

Also used to re-name things

nano

nano

nano [path of file to edit]

nano is a tiny text editor on the command line

rm

Remove

rm [path to thing you absolutely never want to see again]

USE WITH THE UTMOST CAUTION

Code-Along

For Next Time

Topic

Advanced git/GitHub

To-Do

  • Complete Worksheet
  • Read: The Turing Way