Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert jupyter notebook to shell script. Add README #23

Merged
merged 2 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Unix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The bulk of this tutorial is written in [Unix (1).ipynb](Unix (1).ipynb) and [Unix (2).ipynb](Unix (2).ipynb). We found that it was better to do a live demonstration in a linux shell rather than installing the bash kernel for Jupyter, so [Unix (1).ipynb](Unix (1).ipynb) was repurposed into [Unix (1).sh](Unix (1).sh).

Files necessary for the tutorial are stored in files_for_practice.tar.gz

More detailed information on `ssh` and GNU `screen` are in their respective markdown files.

106 changes: 106 additions & 0 deletions Unix/Unix (1).sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Intro to Unix
# File system
ls /
ls -la /
pwd
cd
cd specific dir
cd ..
cd -
cd ~

ls ~
mkdir newdir
cd newdir

wget https://raw.githubusercontent.com/KIPAC/BootCamp/master/Unix/files_for_practice.tar.gz
tar -xzf files_for_practice.tar.gz

cd files_for_practice/random_files
mkdir mp3
mv *.mp3 mp3
mkdir est
cp est.* est
mv architecto.mp3 consequuntur.html
rm -i molestias.css

# Read text files
tail -n 2 users.txt
head -n 3 clients.txt

# Where are these programs?
which tar
which wget
which which

# The PATH environment variable stores the directories the shell searches when it is told a command
echo $PATH

# File permissions
cd ../executables
./wget
./tar

chmod u+x tar
./tar

chmod u-r alphabet.txt
cat alphabet.txt
chmod u+r alphabet.txt
cat alphabet.txt

# I/O redirection
command < input_file
command > output_file
command < input_file > output_file

# append
command >> output_file

# use stdout from command1 as stdin of command2
command1 | command2

# for example if we want to pass in alphabet.txt to reverse we use
chmod u+x reverse
./reverse < alphabet.txt

# how many files are in a directory?
# use one program to list the files
# use another program to count
cd ../random_files
ls -l | wc -l
ls -l *.png | wc -l

cd
# grep
grep ^d users.txt
grep ^d *.txt
ls -l | grep -E i.\.mp3

# search grepdata.txt for all lines that do not begin with a capital letter
grep '^[^A-Z]' grepdata.txt

# sed
# sed 's/phrase/replacement/' filename
sed 's/\./SPAM/' users.txt
sed -i.bak 's/\./SPAM/' users.txt

# awk
ls -l | awk '{print $1}'

# ps and kill
ps
kill

# Editing your .bashrc
alias ll="ls -larth"
alias farmshare="ssh rice.stanford.edu"
cdls() { cd "$@" && ls; }

# Screen and Notebook
# Useful for daily workflow like keeping a kernel running, but not intended to run long jobs.
screen -S jupyter
jupyter notebook --port=1738 --no-browser
ssh -t -L 1738:localhost:1738 rice.stanford.edu
screen -X -S myscreen quit