{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# The Linux Commandline (bash)\n",
"## 8/29/2023\n",
"\n",
"print view
\n",
"notebook"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Linux\n",
"\n",
"*Happy Birthday Linux! Here's your cake:*\n",
"
"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Installing (Linux)\n",
"\n",
"For this class we expect you to do your work on your own computing resources. \n",
"\n",
"Your code will be evaluated using Ubuntu 22.04. You use the system package manager (**apt**) and the python package manager (**pip**) to install additional software needed for the course. **sudo** runs a command with super user privileges.\n",
"\n",
"```\n",
"sudo apt install git vim wget python-pip ipython-notebook python-tk clustalw libcairo2 libcairo2-dev libxml2 libxml2-dev cmake libeigen3-dev swig graphviz python-pygraphviz imagemagick python3-openbabel\n",
"\n",
"sudo pip3 install pysb matplotlib biopython prody MDAnalysis cython sklearn Pillow py3Dmol pandas pydotplus pydot bionetgen\n",
"```\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# macOS\n",
"\n",
"Macs also have a built-in commandline (Terminal.app). Many of the packages we use are also available of OS X. However, keep in mind your assignments must run properly on Ubuntu 22.04.\n",
"\n",
"MacPorts is most convenient for installing software (https://www.macports.org), but not all packages that we use are readily available.\n",
"\n",
"# Windows\n",
"\n",
"As of **Windows 10**, can [install Linux Subsystem](https://docs.microsoft.com/en-us/windows/wsl/install-win10). In theory should work just like Ubuntu and is much less cumbersome to use than the Windows shell."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Colab\n",
"\n",
"[Google Colab](https://colab.research.google.com/) provides a cloud-based solution from running python. You can run bash commands by prefixing them with `!`.\n",
"\n",
"Since your colab runtime will eventually timeout, we strongly recommend install Jupyter notebook locally on your own machine rather than using cloud resources. \n",
"\n",
"
"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Commands\n",
"\n",
"The first word you type is the program you want to run. bash will search PATH environment variable for an appropriately named executable and run it with the specified arguments.\n",
"\n",
"* ipython - start interactive python shell (more later)\n",
"* ssh *hostname* - connect to *hostname*\n",
"* passwd - change your password\n",
"* nano - a user-friendly text editor\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# A BASH cheatsheet\n",
"\n",
"https://mscbio2025.github.io/notes/bash_cheatsheet.pdf"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# ls - directory listing\n",
"```bash\n",
"$ ls -l\n",
"total 8\n",
"-rw-rw-r-- 1 dkoes dkoes 19 Sep 3 09:08 hello.txt\n",
"drwxrwxr-x 2 dkoes dkoes 4096 Sep 3 09:08 lecture\n",
"$ pwd\n",
"/home/dkoes/intro\n",
"$ cd lecture/../..\n",
"$ pwd\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"```bash\n",
"$ ls -l\n",
"total 8\n",
"-rw-rw-r-- 1 dkoes dkoes 19 Sep 3 09:08 hello.txt\n",
"drwxrwxr-x 2 dkoes dkoes 4096 Sep 3 09:08 lecture\n",
"$ ls *.txt\n",
"```\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Spacing Out\n",
"\n",
"du - disk usage of files/directores\n",
"```bash\n",
"[dkoes@n052 tmp]$ du -s\n",
"146564\t.\n",
"[dkoes@n052 tmp]$ du -sh\n",
"144M\t.\n",
"[dkoes@n052 tmp]$ du -sh intro\n",
"4.0K\tintro\n",
"```\n",
"\n",
"df - usage of full disk\n",
"```bash\n",
"[dkoes@n052 tmp]$ df -h .\n",
"Filesystem Size Used Avail Use% Mounted on\n",
"pulsar:/home 37T 28T 9.3T 75% /net/pulsar/home\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Dude, where's my stuff?\n",
"\n",
"locate find a file system wide\n",
"find search directory tree\n",
"which print location of a command\n",
"man print manual page of a command\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Save the Environment\n",
"\n",
"NAME=value set NAME equal to value **No spaces around equals**\n",
"\n",
"export NAME=value set NAME equal to value and make it stick\n",
"\n",
"`$` *dereference* variable\n",
"```bash\n",
"user@python$ X=3\n",
"user@python$ echo $X\n",
"3\n",
"user@python$ X=hello\n",
"user@python$ echo $X\n",
"hello\n",
"user@python$ echo X\n",
"X\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Getting at your variables\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"```bash\n",
"$ ls -l\n",
"total 8\n",
"-rw-rw-r-- 1 dkoes dkoes 19 Sep 3 09:08 hello.txt\n",
"drwxrwxr-x 2 dkoes dkoes 4096 Sep 3 09:08 lecture\n",
"$ ls '*.txt'\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Capturing Output\n",
"\n",
"```\n",
"`cmd`\n",
"``` \n",
"evaluates to output of cmd\n",
"```bash\n",
"$ FILES=`ls`\n",
"$ echo $FILES \n",
"hello.txt lecture\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Your Environment\n",
"\n",
"env list all set environment variables\n",
"\n",
"PATH where shell searches for commands\n",
"\n",
"LD_LIBRARY_PATH library search path\n",
"\n",
"PYTHONPATH where python searches for modules\n",
"\n",
".bashrc initialization file for bash - set PATH etc here\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# History\n",
"\n",
"history show commands previously issued\n",
"\n",
"up arrow cycle through previous commands\n",
"\n",
"Ctrl-R search through history for command **AWESOME**\n",
"\n",
".bash_history file that stores the history\n",
"\n",
"HISTCONTROL environment variable that sets history options: ignoredups\n",
"\n",
"HISTSIZE size of history buffer"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Shortcuts\n",
"\n",
"Tab autocomplete\n",
"\n",
"Ctrl-D EOF/logout/exit\n",
"\n",
"Ctrl-A go to beginning of line\n",
"\n",
"Ctrl-E go to end of line\n",
"\n",
"alias new=cmd \n",
"\n",
"make a nickname for a command\n",
"```bash\n",
"$ alias l='ls -l'\n",
"$ alias\n",
"$ l\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"\n",
"## Loops\n",
"\n",
"```bash\n",
"for i in x y z\n",
"do\n",
" echo $i\n",
"done\n",
"\n",
"for i in *.txt\n",
"do\n",
" echo $i\n",
"done\n",
"```\n",
"\n",
"Lots more... (TLDP)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# String Manipulation\n",
"\n",
"http://tldp.org/LDP/abs/html/string-manipulation.html\n",
"\n",
"```bash\n",
"$ i=\"ovolo\"\n",
"$ echo ${i%o}\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Batch processing files\n",
"\n",
"\n",
"```bash\n",
"for file in *.png\n",
"do\n",
" convert $file ${file%.png}.tif\n",
"done\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Assignment 1\n",
" * Due in a week\n",
" * Use GradeScope to hand-in\n",
" * **Test your code before submitting**"
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}