Computation Boot Camp

Day 2 The Shell

Patrick Cahan

The Shell

Getting started. Launch the Terminal

Make a new directory

mkdir ~/bootcamp2016/Day2

Change current working directory

cd ~/bootcamp2016/Day2

Shell commands (2)

Directory listing

ls -lath

Creating new files

touch aFile.txt

Make a copy of the file

cp aFile.txt aNewFile.txt

Shell commands (3)

Moving a file

mkdir dumpingZone
mv aNewFile.txt dumpingZone/

Deleting files

rm aNewFile.txt
ls -lath

Shell commands (4) -- Wildcards

touch a.txt
touch b.txt
touch c.txt
touch d.csv

Move all .txts

mv *.txt dumpingZone/
ls -lath
ls -lath dumpingZone

Shell environment variables

echo $PATH
echo $HOME

Shell environment variables defined in .bash_profile

emacs ~/bash_profile

Add ~/bootcamp2016/Day2/dumpingZone to your path
Ctrl x-s to save file
Now source it

source ~/.bash_profile
echo $PATH

grep

Grep searches for string matches in a given input

grep Harvard ../Day1/timesData.csv

Awk selects columns

awk 'BEGIN { FS = "," } ; {print $2,$1}' ../Day1/timesData.csv

Piping output

grep Harvard ../Day1/timesData.csv | awk 'BEGIN { FS = "," } ; {print $2,$1, $15}'

Day 2 assignment -- World Development Indicators (WDI)