This page should serve as a reference for the many "things Linux" we use in this course. It is by no means complete – Linux is **huge** – but offers introductions to many important topics.
...
- Macs and Linux have a Terminal program built-in
- Windows options:
- Windows 10+
- Command Prompt and PowerShell programs have ssh and scp (may require latest Windows updates)
- Start menu → Search for Command
- Putty – http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
- simple Terminal and file copy programs
- download either the Putty installer or just putty.exe (Terminal) and pscp.exe (secure copy client)
- Windows Subsystem for Linux – Windows 10 Professional includes a Ubuntu-like bash shells
- See https://docs.microsoft.com/en-us/windows/wsl/install-win10
- We recommend the Ubuntu Linux distribution, but any Linux distribution will have an SSH client
- Command Prompt and PowerShell programs have ssh and scp (may require latest Windows updates)
- Windows 10+
Use ssh (secure shell) to login to a remote computers.
Code Block | ||||
---|---|---|---|---|
| ||||
# General form: ssh <user_name>@<full_host_name> # For example ssh abattenh@ls6.tacc.utexas.edu |
...
Code Block | ||
---|---|---|
| ||
today=$( date ); echo $today # environment variable "today" is assigned today's date today="Today is: `date`"; echo $today # "today" is assigned a string including today's date |
Bash control flow
the bash for loop
As in many programming languages, a for loop performs a series of expressions on one or more item 's in the for's argument list.
The general structure of a for loop in bash are shown below. The <expression> <items> should be (or evaluate to) for's argument list: a space-separated list of items (e.g. 1 2 3 4 or `ls -1 *.gz` ).
Code Block | ||
---|---|---|
| ||
for <variable name> in <expression><items> do <something> <something else> done |
Example, using the seq 4 command to generate a set of 4 numbers: 1 2 3 4.
Code Block | ||
---|---|---|
| ||
for num in `seq 4` do echo $num done # or, since bash lets you put multiple commands on one line # if they are each separated by a semicolon ( ; ): for num in `seq 4`; do echo $num; done |
Here num is the name I gave the variable that is assigned a different number each time through the loop (called the loop's formal argument). The set of such numbers is generated by the seq 4 command. Each number is then referenced as$num inside the loop.
processing multiple files in a for loop
One common use of for loops is to process multiple files, where the set of files to process is obtained by pathname wildcarding. For example, the code below counts the number of reads in a set of compressed FASTQ files:
Code Block | ||||
---|---|---|---|---|
| ||||
for fname in *.gz; do echo "$fname has $((`zcat $fname | wc -l` / 4)) sequences" done |
...