Lesson 1
Overview
Course lessons
Bash Basics
Bash Basics is all about getting started. We will betalking about where and how to acess your teminal, how to navigate and edit files/directories as well as the most common commands and special keys you will need to know.
Lesson 2
Bash Commands and Keywords
-
-
- ls -a List all files and folders
- ls <foldername> List files in a folder
- ls -lh Detailed list with a human-readable output
- ls -l *.jpg List only jpeg files
- ls -lh <fileName> Result for only a single file
- cd <foldername> Change directory - If the folder name has spaces, use quotes. Example: cd "Folder With Spaces"
- cd .. Go up one folder.
- du -h Disk usage of folders in a human-readable output
- du -ah Disk usage of files and folders in a human-readable output
- du -sh Only show disk usage of folders
- pwd Print the working directory
- man <command> Shows the manual for a command or program
-
-
-
- ~ Points to the home directory
- # Insert a comment
- & Run as a background job
- ' Strong Quote
- " Weak quote
-
complete -A keyword : followed by� : Space Tab Tab to get a list of all the shell keywords.
Finally, terminals send characters (bytes), not keystrokes. Special keys such as Tab, Backspace, Enter and Esc are encoded as control characters.
Control characters are not printable, they display in the terminal as ^ and are intended to have an effect on applications.
Lesson 3
Basic file manipulation and the rm command
- creating/editing
-
- mkdir <foldername> Create a new folder
- touch <filename> Create or update a file
-
- moving/renaming
-
- mv file.txt documents/ Move a file to a folder
- mv <folderName> <foldername2> Move a folder into a folder
- mv filename.txt filename2.txt Rename a file
- mv <foldername>/.. Move a folder up in the hierarchy
-
- copying
-
- cp image.jpg newimage.jpg Copy and rename a file
- cp image.jpg <foldername>/ Copy to a folder
- cp -R folder1/ folder2/ Recursively (-R) copies folder1 and all of its contents into folder2.
-
- rm <filename>�removes files only
- rmdir <foldername>�removes folders
- use�-r (recursive option) to delete all files and subfolders
Never use rm/rmdir -r * !!
Finally, these shortcuts will help you navigate your command line while typing.
Bash basics 2
In bash basics 2 we discuss customizing your terminal for your individual needs. This can mean putting in shortcuts to projects or changing the coloursheme to be more easy on the eyes.
Lesson 4
Bash Basics 2 Webinar
Lesson 5
Editing your Bash Profile
Lesson 6
Curated list of favorite aliases
Bash Basics 3
Moving on from navigating files systems Bash basics 3 focuses on writing scrips. This module will teach you how to define variables read user input as well as write functions and loops.
Lesson 7
Bash Basics 3 Webinar
Lesson 8
Setting up and Running Bash scripts
-
-
- ./<filename>.sh � most commonly used
- source <filename>.sh
- /bin/bash <filename>.sh
- bash <filename>.sh � assuming /bin is in your $PATH
- sh <filename>.sh
-
image: example of a simple script
Lesson 9
Variables and user Input
image: list of echo options taken from O'Reilly
It can be very useful to define variables after the program has been set in motion. For example, a short script to pull a number of random samples from a larger dataset could benefit from setting the number of samples or the random key without having to edit the script every time. Or setting the name of your output file as the script completes. For these examples, you could use user input. When using the read <varaible> command in your script the user will be prompted to enter some input.Lesson 10
Functions loops and conditionals
For Loop:
- the for loop executes a set of commands for each item in a given list
for var in <list> do <commands> done
While Loop:
- while expression evaluates as true a while loop will continue to execute
while [<some tests>] do <commands> done
Until Loop:
- commands will be executed until statement evaluates as true
until [<some tests>] do <commands> done