advanced linux usage - github pagesadvanced linux usage 2019-02-05 ... start with one, git gud,...

70

Upload: others

Post on 20-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and
Page 2: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Advanced Linux Usage

2019-02-05

Martin Dahlö[email protected]

Page 3: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Multiple files

● Same program, many files

Page 4: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Multiple files

● Same program, many files

Page 5: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Multiple files

● Same program, many files

Page 6: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Multiple files

● Same program, many files○ 10 files? Ok○ 1000 files? Not ok

Page 7: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Multiple files

● Same program, many files○ 10 files? Ok○ 1000 files? Not ok

● Reproducibility○ Self and others

Page 8: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Multiple files

● Same program, many files○ 10 files? Ok○ 1000 files? Not ok

● Reproducibility○ Self and others

A solution - write a script!

Page 9: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 10: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 11: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 12: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 13: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 14: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 15: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 16: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Still not OK for 1000 or more files!

Page 17: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 18: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 19: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Variables

● Assigningmy_variable=5my_variable=”nice text”

Page 20: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Variables

● Assigningmy_variable=5my_variable=”nice text”

● Using$my_variable

Page 21: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Variables

● Assigningmy_variable=5my_variable=”nice text”

● Using$my_variable

$ my_variable=”Dave”

Page 22: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

● Assigningmy_variable=5my_variable=”nice text”

● Using$my_variable

$ my_variable=”Dave” $ echo “Hello, $my_variable.”

Variables

Page 23: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

● Assigningmy_variable=5my_variable=”nice text”

● Using$my_variable

$ my_variable=”Dave” $ echo “Hello, $my_variable.” Hello, Dave.

Variables

Page 24: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 25: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 26: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 27: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Loops

for var in 1 2 3;do echo $vardone

Page 28: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Loops

for var in text works too;do echo $vardone

Page 29: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Loops

for var in mix them 5;do echo $vardone

Page 30: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Loops

for var in *.txt;do echo $vardone

Page 31: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 32: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 33: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Debugging!

Page 34: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 35: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 36: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 37: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 38: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

$1

Page 39: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

$1 $2

Page 40: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

$1 $2 $3

Page 41: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

$1 $2 $3 $4

Page 42: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 43: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 44: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 45: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 46: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 47: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Basic script

Page 48: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● Control statement if condition; then

actionfi

Page 49: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● Control statement if true; then

echo ”This is true”fi

result:This is true

Page 50: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● Control statement if false; then

echo ”This is true”fi

result:

Page 51: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● Control statement if [[ 5 < 9 ]]; then

echo ”This is true”fi

result:This is true

Page 52: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● Control statement if [[ 5 > 9 ]]; then

echo ”This is true”fi

result:

Page 53: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● Control statement if [[ 5 == 9 ]]; then

echo ”This is true”fi

result:

Page 54: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● Control statement if [[ ”Hello” == ”Hello” ]]; then

echo ”This is true”fi

result:This is true

Page 55: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● Control statement if [[ ”Hello” == ”Hi” ]]; then

echo ”This is true”fi

result:

Page 56: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● Control statement if [[ ”Hello” == ”Hel”* ]]; then

echo ”This is true”fi

result:This is true

Page 57: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● For all samples except dog

Page 58: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● For all samples except dog

Page 59: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● For all samples except dog

Ex: $file is /path/to/dog_1.bam

Page 60: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● For all samples except dog

Ex: $file is /path/to/dog_1.bam

basename $file

Page 61: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● For all samples except dog

Ex: $file is /path/to/dog_1.bam

basename $file

dog_1.bam

Page 62: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● For all samples except dog

Ex: $file is /path/to/dog_1.bam

basename $file

dog_1.bam

Page 63: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

If

● For all samples except dog

Ex: $file is /path/to/dog_1.bam

basename $file

dog_1.bam

Page 64: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Different languages

● Programming is programming○ Perl, Python, Bash, and more

Page 65: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Different languages

● Programming is programming○ Perl, Python, Bash, and more

Page 66: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Different languages

● Programming is programming○ Perl, Python, Bash, and more

Page 67: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Different languages

● Programming is programming○ Perl, Python, Bash, and more

Page 68: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Different languages

● Programming is programming○ Perl, Python, Bash, and more

● Start with one, git gud, (learn another)

Page 69: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Different languages

● Programming is programming○ Perl, Python, Bash, and more

● Start with one, git gud, (learn another)

PYTHON

Page 70: Advanced Linux Usage - GitHub PagesAdvanced Linux Usage 2019-02-05 ... Start with one, git gud, (learn another) Different languages Programming is programming Perl, Python, Bash, and

Laboratory time! (yet again)