Contents

Intro - The (unix) command line: BASH

Contents

Intro - The (unix) command line: BASH

Where are we now?

Before we start a lesson it is usually helpfull to reflect on why we want to learn about a certain topic.

So please take a few minutes to reflect on the following questions.

1.1 What do you know about Command-Line-Interfaces?

1.2 What do you know about BASH?

1.4 What may a lesson on the subject of BASH possibly contain?

1.5 Can you imagine any benefits resulting from learning about BASH?

Note: Feel free to do this in your head or in a separate document. Remember, to interactively engage with the material either open it in MyBinder (the small rocket button at the top of the website) or [download the course material](link to course zip), go through the [setup process](link to setup) and open this file (i.e digital_literacy.ipynb in the introduction folder) using Jupyter Notebooks or VScode.

Goals

  • learn basic and efficient usage of the shell for various tasks

    • navigating directories

    • file handling: copy, paste, create, delete

What is the “shell”?

  • The shell is a command-line interface (CLI) to your computer

    • This is in contrast to the graphical user interfaces (GUIs) that you normally use!

  • The shell is also a scripting language that can be used to automate repetitive tasks

But what’s this “bash shell”?

It’s one of many available shells!

  • sh - Bourne SHell

  • ksh - Korn SHell

  • dash - Debian Almquist SHell

  • csh - C SHell

  • tcsh - TENEX C SHell

  • zsh - Z SHell

  • bash - Bourne Again SHell <– We’ll focus on this one!

WHY so many?

  • They all have different strengths / weaknesses

  • You will see many of them throughout much of neuroimaging software, too!

    • sh is most frequently used in FSL (FMRIB Software Library)

    • csh/tcsh is very common in FreeSurfer and AFNI (Analysis of Functional NeuroImages)

So we’re going to focus on the bash shell?

Yes! It’s perhaps the most common shell, available on almost every OS:

  • It’s the default shell on most Linux systems

  • It’s the default shell in the Windows Subsytem for Linux (WSL)

  • It’s the default shell on Mac <=10.14

    • zsh is the new default on Mac Catalina (for licensing reasons 🙄)

    • But bash is still available!!

Alright, but why use the shell at all?

Isn’t the GUI good enough?

  • Yes, but the shell is very powerful

  • Sequences of shell commands can be strung together to quickly and reproducibly make powerful pipelines

  • Also, you need to use the shell to accesss remote machines/high-performance computing environments (like Compute Canada or the local Goethe-Cluster)

NOTE: We will not be able to cover all (or even most) aspects of the shell today.

But, we’ll get through some basics that you can build on going forward.

Before we get started

For this part of the lecture you will have to follow along on your own machine.

Windows users will have to download the Windows-subystems-for-linux (wsl) application, this will install a Unix subsystem which will allow you to work with the bash shell. Simply follow e.g. the Foss Guide: Install bash on windows. Bash already comes preinstalled on Unix systems such as Linux and Mac.

Further we’re going to be working with a dataset from https://swcarpentry.github.io/shell-novice/data/shell-lesson-data.zip. Download that file and unzip it on your Desktop!

The (bash) shell

Now, let’s open up your terminal!

  • Windows: Open the Ubuntu application (installed via the guide above)

  • Mac/Linux: Open the Terminal (Command + Space Bar / Ctrl + Alt + t)

When the shell is first opened, you are presented with a prompt, indicating that the shell is waiting for input:

$

The shell typically uses $ as the prompt, but may use a different symbol.

IMPORTANT: When typing commands, either in this lesson or from other sources, do not type the prompt, only the commands that follow it!

Am I using bash?

Let’s check! You can use the following command to determine what shell you’re using:

!echo $SHELL
/bin/bash

If that doesn’t say something like /bin/bash,

  • then simply type bash, press Enter, and try running the command again

  • there might be other ways depending on your OS/installation, please let us know

Note: The echo command does exactly what its name implies: it simply echoes whatever we provide it to the screen!

(It’s like print in Python / R or disp in MATLAB or printf in C or …)

What’s with the $SHELL?

  • Things prefixed with $ in bash are (mostly) environmental variables

    • All programming languages have variables!

  • We can assign variables in bash but when we want to reference them we need to add the $ prefix

  • We’ll dig into this a bit more later, but by default our shell comes with some preset variables

    • $SHELL is one of them!

Soooo, let’s try our ~first~ second command in bash!

This command lists the contents of our current directory:

ls
desserts/  environment.yml  intro_to_shell.ipynb  shell-lesson-data/

What happens if we make a typo? Or if the program we want isn’t installed on our computer?

Will the computer magically understand what we were trying to do?

ks
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/tmp/ipykernel_42124/53694076.py in <module>
----> 1 ks

NameError: name 'ks' is not defined

Nope! But you will get a (moderately) helpful error message 😁

The cons of the CLI

  • You need to know the names of the commands you want to run!

  • Sometimes, commands are not immediately obvious

    • E.g., why ls over list_contents?

Key Points

  • A shell is a program whose primary purpose is to accept commands and run programs

  • The shell’s main advantages are its high action-to-keystroke ratio, its support for automating repetitive tasks, and its capacity to access remote machines

  • The shell’s main disadvantages are its primarily textual nature and how cryptic its commands and operation can be

Working with Files and Directories

How do we actually make new files and directories from the command line?

First, let’s remind ourselves of where we are:

cd ~/Desktop/shell-lesson-data
/home/michael/Desktop/shell-lesson-data
pwd
'/home/michael/Desktop/shell-lesson-data'
ls -F
exercise-data/  north-pacific-gyre/  thesis_backup/

Creating a directory

We can create new directories with the mkdir (make directory) command:

mkdir thesis

Since we provided a relative path, we can expect that to have been created in our current working directory:

ls -F
exercise-data/  north-pacific-gyre/  thesis/

(You could have also opened up the file explorer and made a new folder that way, too!)

Good naming conventions

  1. Don’t use spaces

  2. Don’t begin the name with -

  3. Stick with letters, numbers, ., -, and _

    • That is, avoid other special characters like ~!@#$%^&*()

Creating a text file

Let’s navigate into our (empty) thesis directory and create a new file:

cd thesis
/home/michael/Desktop/shell-lesson-data/thesis

We can make a file via the following command:

!touch draft.txt

touch creates an empty file. We can see that with ls -l:

ls -l
total 0
-rw-rw-r-- 1 michael michael 0 Okt 28 09:20 draft.txt

Moving files and directories

Let’s start by going back to the data-shell directory:

cd ~/Desktop/shell-lesson-data
/home/michael/Desktop/shell-lesson-data

We now have a thesis/draft.txt file, which isn’t very informatively named. Let’s move it:

mv thesis/draft.txt thesis/quotes.txt

The first argument of mv is the file we’re moving, and the last argument is where we want it to go!

Let’s make sure that worked:

ls thesis
quotes.txt

Note: we can provide more than two arguments to mv, as long as the final argument is a directory! That would mean “move all these things into this directory”.

Also note: mv is quite dangerous, because it will silently overwrite files if the destination already exists! Refer to the -i flag for “interactive” moving (with warnings!).

More on mv

Note that we use mv to change files to a different directory (rather than just re-naming):

mv thesis/quotes.txt .

The . means “the current directory”, so we should have moved quotes.txt out of the thesis directory into our current directory.

Let’s check that worked as expected:

ls thesis
ls quotes.txt
quotes.txt

(Note: providing a filename to ls instead of a directory will list only that filename if it exists. Otherwise, it will throw an error.)

Exercise: Moving files to a new folder

After running the following commands, Jamie realizes that she put the files sucrose.dat and maltose.dat into the wrong folder. The files should have been placed in the raw folder.

$ ls -F
 analyzed/ raw/
$ ls -F analyzed
fructose.dat glucose.dat maltose.dat sucrose.dat
$ cd analyzed

Fill in the blanks to move these files to the raw/ folder (i.e. the one she forgot to put them in):

$ mv sucrose.dat maltose.dat ____/____
mv sucrose.dat maltose.dat ../raw

Remember, the .. refers to the parent directory (i.e., one above the current directory)

Copying files and directories

The cp (copy) command is like mv, but copies instead of moving!

cp quotes.txt thesis/quotations.txt
ls quotes.txt thesis/quotations.txt
quotes.txt  thesis/quotations.txt

We can use the -r (recursive) flag to copy a directory and all its contents:

cp -r thesis thesis_backup
ls thesis thesis_backup
thesis:
quotations.txt

thesis_backup:
quotations.txt

Exercise: Renaming files

Suppose that you created a plain-text file in your current directory to contain a list of the statistical tests you will need to do to analyze your data, and named it: statstics.txt

After creating and saving this file you realize you misspelled the filename! You want to correct the mistake and remove the incorrectly named file. Which of the following commands could you use to do so?

  1. cp statstics.txt statistics.txt

  2. mv statstics.txt statistics.txt

  3. mv statstics.txt .

  4. cp statstics.txt .

  1. No: this would create a file with the correct name but would not remove the incorrectly named file

  1. Yes: this would rename the file!

  1. No, the . indicates where to move the file but does not provide a new name.

  1. No, the . indicates where to copy the file but does not provide a new name.

Moving and Copying

What is the output of the closing ls command in the aequence shown below:

$ pwd
/Users/jamie/data
$ ls
proteins.dat
$ mkdir recombine
$ mv proteins.dat recombine
$ cp recombine/proteins.dat ../proteins-saved.dat
$ ls
  1. proteins-saved.dat recombine

  2. recombine

  3. proteins.dat recombine

  4. proteins-saved.dat

  1. No: proteins-saved.dat is located at /Users/jamie

  1. Yes!

  1. No: proteins.dat is located at /Users/jamie/data/recombine

  1. No, proteins-saved.dat is located at /Users/jamie

Removing files

Let’s go back to data-shell and remove the quotes.txt file we created:

cd ~/Desktop/shell-lesson-data
/home/michael/Desktop/shell-lesson-data
rm quotes.txt

The rm command deletes files. Let’s check that the file is gone:

ls quotes.txt
ls: cannot access 'quotes.txt': No such file or directory

Deleting is FOREVER 💀💀

  • The shell DOES NOT HAVE A TRASH BIN.

  • You CANNOT recover files that have been deleted with rm

  • But, you can use the -i flag to do things a bit more safely!

    • This will prompt you to type Y or N before every file that is going to be deleted.

Removing directories

Let’s try and remove the thesis directory:

rm thesis
rm: cannot remove 'thesis': Is a directory

rm only works on files, by default, but we can tell it to recursively delete a directory and all its contents with the -r flag:

rm -r thesis

Because deleting is forever 💀💀, the rm -r command should be used with GREAT CAUTION.

Operations with multiple files and directories

Oftentimes you need to copy or move several files at once. You can do this by specifiying a list of filenames

Exercise: Copy with Multiple Filenames

(Work through these in the data-shell/data directory.)

In the example below, what does cp do when given several filenames and a directory name?

$ mkdir backup
$ cp amino-acids.txt animals.txt backup/

What does cp do when given three or more filenames?

$ ls
amino-acids.txt  animals.txt  backup/  elements/  morse.txt  pdb/  planets.txt  salmon.txt  sunspot.txt
$ cp amino-acids.txt animals.txt morse.txt
  1. When given multiple filenames followed by a directory all the files are copied into the directory.

  1. When give multiple filenames with no directory, cp throws an error:

cp: target morse.txt is not a directory

Using wildcards for accessing multiple files at once

* is a wildcard which matches zero or more characters.

Consider the data-shell/proteins directory:

ls exercise-data/proteins/
cubane.pdb  ethane.pdb  methane.pdb  octane.pdb  pentane.pdb  propane.pdb

This matches every file in the proteins directory.

ls exercise-data/proteins/*pdb
exercise-data/proteins/cubane.pdb   exercise-data/proteins/octane.pdb
exercise-data/proteins/ethane.pdb   exercise-data/proteins/pentane.pdb
exercise-data/proteins/methane.pdb  exercise-data/proteins/propane.pdb

This matches every file in the proteins directory ending in .pdb.

ls exercise-data/proteins/p*.pdb
exercise-data/proteins/pentane.pdb  exercise-data/proteins/propane.pdb

This matches all files in the proteins directory starting with p and ending with .pdb

Using wildcards for accessing multiple files at once (cont’d)

? is a wildcard matching exactly one character.

ls exercise-data/proteins/?ethane.pdb
exercise-data/proteins/methane.pdb

This matches any file in proteins that has one character followed by ethane.pdb. Compare to:

ls  exercise-data/proteins/*ethane.pdb
exercise-data/proteins/ethane.pdb  exercise-data/proteins/methane.pdb

Which matches any file in proteins that ends in ethane.pdb.

Using wildcards for accessing multiple files at once (cont’d)

You can string wildcards together, too!

ls  exercise-data/proteins/???ane.pdb
exercise-data/proteins/cubane.pdb  exercise-data/proteins/octane.pdb
exercise-data/proteins/ethane.pdb

This matches and file in proteins that has any three characters and ends in ane.pdb

Wildcards are said to be “expanded” to create a list of matching files. This happens before running the relevant command. For example, the following command will fail:

ls  exercise-data/proteins/*pdf
ls: cannot access 'exercise-data/proteins/*pdf': No such file or directory

Exercise: List filenames matching a pattern

When run in the proteins directory, which ls command(s) will produce this output?

ethane.pdb methane.pdb

  1. ls *t*ane.pdb

  2. ls *t?ne.*

  3. ls *t??ne.pdb

  4. ls ethane.*

  1. No: This will give ethane.pdb methane.pdb octane.pdb pentane.pdb

  1. No: this will give octane.pdb pentane.pdb

  1. Yes!

  1. No: This only shows file starting with ethane

Key points

  • cp old new copies a file

  • mkdir path creates a new directory

  • mv old new moves (renames) a file or directory

  • rm path removes (deletes) a file

  • * matches zero or more characters in a filename, so *.txt matches all files ending in .txt

  • ? matches any single character in a filename, so ?.txt matches a.txt but not any.txt

  • The shell does not have a trash bin: once something is deleted, it’s really gone

Summary

  • The bash shell is very powerful!

  • It offers a command-line interface to your computer and file system

  • It makes it easy to operate on files quickly and efficiently (copying, renaming, etc.)

  • Sequences of shell commands can be strung together to quickly and reproducibly make powerful pipelines

Soapbox

  • Bash is fantastic and you will (likely) find yourself using it a lot!

  • However, for complex pipelines and programs we would strongly encourage you to use a “newer” programming lanuage

    • Like Python, which we will also be discussed in this workshop!

  • There are a number of reasons for this (e.g., better control flow, error handling, and debugging)

Finding Things

Oftentimes, our file system can be quite complex, with sub-directories inside sub-directories inside sub-directories.

What happens in we want to find one (or several) files, without having to type ls hundreds or thousands of times?

First, let’s navigate to the data-shell/writing directory:

cd ~/Desktop/shell-lesson-data/
/home/michael/Desktop/shell-lesson-data

The directory structure of data-shell/writing looks like:

Let’s get our bearings with ls:

ls
exercise-data/  north-pacific-gyre/  thesis_backup/

Unfortunately, this doesn’t list any of the files in the sub-directories. Enter find:

!find .
.
./exercise-data
./exercise-data/numbers.txt
./exercise-data/creatures
./exercise-data/creatures/minotaur.dat
./exercise-data/creatures/basilisk.dat
./exercise-data/creatures/unicorn.dat
./exercise-data/animal-counts
./exercise-data/animal-counts/animals.csv
./exercise-data/writing
./exercise-data/writing/haiku.txt
./exercise-data/writing/LittleWomen.txt
./exercise-data/proteins
./exercise-data/proteins/pentane.pdb
./exercise-data/proteins/methane.pdb
./exercise-data/proteins/ethane.pdb
./exercise-data/proteins/propane.pdb
./exercise-data/proteins/octane.pdb
./exercise-data/proteins/cubane.pdb
./.bash_profile
./north-pacific-gyre
./north-pacific-gyre/NENE01843A.txt
./north-pacific-gyre/NENE01843B.txt
./north-pacific-gyre/NENE02043A.txt
./north-pacific-gyre/NENE01729A.txt
./north-pacific-gyre/NENE01736A.txt
./north-pacific-gyre/NENE01729B.txt
./north-pacific-gyre/NENE01812A.txt
./north-pacific-gyre/NENE02040B.txt
./north-pacific-gyre/NENE01751A.txt
./north-pacific-gyre/NENE02018B.txt
./north-pacific-gyre/NENE01978A.txt
./north-pacific-gyre/NENE02043B.txt
./north-pacific-gyre/goodiff.sh
./north-pacific-gyre/NENE02040Z.txt
./north-pacific-gyre/NENE01978B.txt
./north-pacific-gyre/NENE01751B.txt
./north-pacific-gyre/NENE01971Z.txt
./north-pacific-gyre/NENE02040A.txt
./north-pacific-gyre/goostats.sh
./thesis_backup
./thesis_backup/quotations.txt
./.suprise.txt

Remember, . means “the current working directory”. Here, find provides us a full list of the entire directory structure!

Filtering find

We can add some helpful options to find to filter things a bit:

!find . -type d
.
./exercise-data
./exercise-data/creatures
./exercise-data/animal-counts
./exercise-data/writing
./exercise-data/proteins
./north-pacific-gyre
./thesis_backup

This will list only the directories underneath our current directory (incluing sub-directories).

Alternatively, we can list only the files with:

!find . -type f
./exercise-data/numbers.txt
./exercise-data/creatures/minotaur.dat
./exercise-data/creatures/basilisk.dat
./exercise-data/creatures/unicorn.dat
./exercise-data/animal-counts/animals.csv
./exercise-data/writing/haiku.txt
./exercise-data/writing/LittleWomen.txt
./exercise-data/proteins/pentane.pdb
./exercise-data/proteins/methane.pdb
./exercise-data/proteins/ethane.pdb
./exercise-data/proteins/propane.pdb
./exercise-data/proteins/octane.pdb
./exercise-data/proteins/cubane.pdb
./.bash_profile
./north-pacific-gyre/NENE01843A.txt
./north-pacific-gyre/NENE01843B.txt
./north-pacific-gyre/NENE02043A.txt
./north-pacific-gyre/NENE01729A.txt
./north-pacific-gyre/NENE01736A.txt
./north-pacific-gyre/NENE01729B.txt
./north-pacific-gyre/NENE01812A.txt
./north-pacific-gyre/NENE02040B.txt
./north-pacific-gyre/NENE01751A.txt
./north-pacific-gyre/NENE02018B.txt
./north-pacific-gyre/NENE01978A.txt
./north-pacific-gyre/NENE02043B.txt
./north-pacific-gyre/goodiff.sh
./north-pacific-gyre/NENE02040Z.txt
./north-pacific-gyre/NENE01978B.txt
./north-pacific-gyre/NENE01751B.txt
./north-pacific-gyre/NENE01971Z.txt
./north-pacific-gyre/NENE02040A.txt
./north-pacific-gyre/goostats.sh
./thesis_backup/quotations.txt
./.suprise.txt

We can also match things by name:

!find . -name "*.txt"
./exercise-data/numbers.txt
./exercise-data/writing/haiku.txt
./exercise-data/writing/LittleWomen.txt
./north-pacific-gyre/NENE01843A.txt
./north-pacific-gyre/NENE01843B.txt
./north-pacific-gyre/NENE02043A.txt
./north-pacific-gyre/NENE01729A.txt
./north-pacific-gyre/NENE01736A.txt
./north-pacific-gyre/NENE01729B.txt
./north-pacific-gyre/NENE01812A.txt
./north-pacific-gyre/NENE02040B.txt
./north-pacific-gyre/NENE01751A.txt
./north-pacific-gyre/NENE02018B.txt
./north-pacific-gyre/NENE01978A.txt
./north-pacific-gyre/NENE02043B.txt
./north-pacific-gyre/NENE02040Z.txt
./north-pacific-gyre/NENE01978B.txt
./north-pacific-gyre/NENE01751B.txt
./north-pacific-gyre/NENE01971Z.txt
./north-pacific-gyre/NENE02040A.txt
./thesis_backup/quotations.txt
./.suprise.txt

Executing with find

What if we want to perform some operation on the output of our find command? Say, list the file sizes for each file (as in ls -lh)?

We can do that with a bit of extra work:

!find . -name "*.txt" -exec ls -lh {} \;
-rw-rw-r-- 1 michael michael 13 Sep 16  2021 ./exercise-data/numbers.txt
-rw-rw-r-- 1 michael michael 218 Sep 16  2021 ./exercise-data/writing/haiku.txt
-rw-rw-r-- 1 michael michael 1,1M Sep 16  2021 ./exercise-data/writing/LittleWomen.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01843A.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01843B.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE02043A.txt
-rw-rw-r-- 1 michael michael 4,4K Sep 16  2021 ./north-pacific-gyre/NENE01729A.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01736A.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01729B.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01812A.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE02040B.txt
-rw-rw-r-- 1 michael michael 4,4K Sep 16  2021 ./north-pacific-gyre/NENE01751A.txt
-rw-rw-r-- 1 michael michael 3,5K Sep 16  2021 ./north-pacific-gyre/NENE02018B.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01978A.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE02043B.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE02040Z.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01978B.txt
-rw-rw-r-- 1 michael michael 4,4K Sep 16  2021 ./north-pacific-gyre/NENE01751B.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01971Z.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE02040A.txt
-rw-rw-r-- 1 michael michael 0 Okt 28 09:20 ./thesis_backup/quotations.txt
-rw-rw-r-- 1 michael michael 0 Okt 27 19:45 ./.suprise.txt

Note the very funky syntax:

  • The -exec option means execute the following command,

  • ls -lh is the command we want to execute,

  • {} signifies where the output of find should go so as to be provided to the command we’re executing, and

  • \; means “this is the end of command we want to execute”

We can also “pipe” the output of find to the ls -lh command as follows:

ls -lh $( find . -name "*.txt" )
-rw-rw-r-- 1 michael michael   13 Sep 16  2021 ./exercise-data/numbers.txt
-rw-rw-r-- 1 michael michael  218 Sep 16  2021 ./exercise-data/writing/haiku.txt
-rw-rw-r-- 1 michael michael 1,1M Sep 16  2021 ./exercise-data/writing/LittleWomen.txt
-rw-rw-r-- 1 michael michael 4,4K Sep 16  2021 ./north-pacific-gyre/NENE01729A.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01729B.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01736A.txt
-rw-rw-r-- 1 michael michael 4,4K Sep 16  2021 ./north-pacific-gyre/NENE01751A.txt
-rw-rw-r-- 1 michael michael 4,4K Sep 16  2021 ./north-pacific-gyre/NENE01751B.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01812A.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01843A.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01843B.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01971Z.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01978A.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE01978B.txt
-rw-rw-r-- 1 michael michael 3,5K Sep 16  2021 ./north-pacific-gyre/NENE02018B.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE02040A.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE02040B.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE02040Z.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE02043A.txt
-rw-rw-r-- 1 michael michael 4,3K Sep 16  2021 ./north-pacific-gyre/NENE02043B.txt
-rw-rw-r-- 1 michael michael    0 Okt 27 19:45 ./.suprise.txt
-rw-rw-r-- 1 michael michael    0 Okt 28 09:20 ./thesis_backup/quotations.txt

Here, the $( ) syntax means “run this command first and insert it’s output here”, so ls -lh is provided the output of the find . -name "*.txt" command as arguments.


Which concludes our BASH lesson!

Goals

Did we meet our goals?

  • learn basic and efficient usage of the shell for various tasks

    • navigating directories

    • file handling: copy, paste, create, delete

Where are we now?

Please take a moment to reflect on if and how your understanding of the concept of digital literacy has possibly changed following this lecture.

2.1 How well informed we’re you about CLI/BASH

2.2 How well informed do you feel now about CLI/BASH

2.3 What was one of the mentioned reasons on why you should care about BASH that seemed especially important to you?

2.4 Can you see yourself using BASH in your life/research?

**2.5 What more would you need to learn about BASH to make it work for your research endeavours and where would you find relevant information?

2.6 What was the most surprising part of the training/lecture for you? What information in particular stood out to you?

2.7 Could you think of other impacts that a better understanding of BASH may have on your life? (E.g. a deeper understanding of how file systems work?)

Additional materials

There are lots of excellent resources online for learning more about bash:

Acknowledgments


  • most of what you’ll see within this lecture was prepared by Ross Markello and further adapted by Peer Herholz & Michael Ernst

  • based on the Software Carpentries “Introduction to the Shell” under CC-BY 4.0

Michael Ernst
Phd student - Fiebach Lab, Neurocognitive Psychology at Goethe-University Frankfurt

Peer Herholz (he/him)
Research affiliate - NeuroDataScience lab at MNI/MIT
Member - BIDS, ReproNim, Brainhack, Neuromod, OHBM SEA-SIG, UNIQUE

logo logo   @peerherholz