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
Use ssh (secure shell) to login to a remote computers.
Code Block |
---|
language | bash |
---|
title | SSH to a remote computer |
---|
|
# General form:
ssh <user_name>@<full_host_name>
# For example
ssh abattenh@ls6.tacc.utexas.edu |
...
- Right arrow and Left arrow move the cursor forward or backward on the current command line.
- Use Ctrl-a (holding down the Control key and a) to jump the cursor to the beginning start of the line.
- Use Ctrl-e to jump the cursor to the end of the line.
- Arrow keys are also modified by Ctrl- (Windows) or Option- (Mac)
- Ctrl-right-arrow (Windows) or Option-right-arrow (Mac) will skip by "word" forward
- Ctrl-left-arrow (Windows) or Option-left-arrow (Mac) will skip by "word" backward
...
Code Block |
---|
|
This text will be output
And this USER environment variable will be evaluated: student01
|
Arithemetic in bash
Arithmetic in bash is very weird:
Code Block |
---|
|
echo $(( 50 * 2 + 1 ))
n=0
n=$(( $n + 5 ))
echo $n |
And it only returns integer values, after truncation.
Code Block |
---|
|
echo $(( 4 / 2 ))
echo $(( 5 / 2 ))
echo $(( 24 / 5 )) |
As a result, if I need to do anything other than the simplest arithemetic, I use awk:
Code Block |
---|
|
awk 'BEGIN{print 4/2}'
echo 3 2 | awk '{print ($1+$2)/2}' |
You can also use the printf function in awk to control formatting. Just remember that a linefeed ( \n ) has to included in the format string:
Code Block |
---|
|
echo 3.1415926 | awk '{ printf("%.2f\n", $1) }' |
You can even use it to convert a decimal number to hexadecimal using the %x printf format specifier. Note that the convention is to denote hexadecimal numbers with an initial 0x.
Code Block |
---|
|
echo 65 | awk '{ printf("0x%x\n", $1) }' |
Bash control flow
the bash for loop
...