Week 1 Discussion - Unix and Command Line Basics#
Introduction#
Exercise 23
How will the Unix shell and programming language Bash help us?
Solution to
using Bash we can connect many pieces of software together. For example, we can redirect the output of a program to another. The Unix shell also contains many small software tools which ease working with files.
What is Unix?#
Exercise 24
What is Unix?
Solution to
Unix is an operating system which is different than the widely used Windows. The first Unix was developed in 1969 and we have nowadays many operating systems which are based on the concepts of the first Unix, e.g., tree-based file system, shell or everything is a file
Exercise 25
Where did you see a shell (command-line interface) before?
Solution to
e.g., in the film Matrix or other films which feature computer hackers
at the airport when dropping off the luggage at a counter. The staff sometimes uses a command-line interface to enter passenger data
Exercise 26
what are other words for shell?
Solution to
command-line interface
console
Note that in this book shell is depicted only as a command line interface. In general, shell is an interface to the operating system and it can be both graphical or text-based [1]
Exercise 27
The shell is a very direct and powerful way to manipulate a computer. … or you can wreak havoc on yourself and on others. …
Do you have an example for such a command?
Solution to
sudo rm -rf /
Getting Unix#
Exercise 28
Which did/would you use to get a Unix shell?
A) Mac A) Windows WSL A) Windows + Virtualbox + Ubuntu A) cloud A) other
Command Line basics#
Exercise 29
Which command allows to you to clear the shell?
Solution to
clear
There is also a shortcut: CTRL + L
Exercise 30
What is the command-line prompt?
Solution to
For example:
alena:~ inf1$
Same like the literal meaning, this line prompts you to enter a command.
Exercise 31
Which is the typical structure of commands?
A) command - options - arguments A) command - arguments - options A) arguments - command - options A) options - command - arguments A) I don’t know
Solution to
For example:
echo -n hello
Another examples:
grep -e AGCT -e AGTT reads.txt
ls myfolder -l # also works
Exercise 32
How can you reexecute the commands that you used before?
What if you are searching for a command that you used very long ago?
Solution to
Up
andDown
keys.It is also possible to search for a command using
Ctrl+R
. PressCtrl+R
and type a part of the command that you used before. Then pressCTRL+R
again to jump to the next.Alternatively you can view the history file of your shell, e.g.,
.bash_history
in bash or.histfile
in zsh.
Exercise 33
Browse
Pick a command that you never seen before. If you find the command useful, prepare a one minute presentation of the command. Post your command on the chat so that everyone can present another command. You can share your screen to present the command.
Exercise 34
You want to prepare the following directory structure on your home folder:
photos/2022
photos/2021
documents/
You start creating the directories:
mkdir photos/2022
But get the following error:
mkdir: cannot create directory ‘photos/2022’: No such file or directory
What could be the reason? In other words, what does the error message mean?
How could you fix this?
Solution to
It means that a file or directory does not exist, so the command fails. In this case the missing thing is the directory
photos
.mkdir
cannot create2022
, because the parent directoryphotos
does not exist.We could first
mkdir photos
, thenmkdir photos/2022
. There is an easier way though. Fromman mkdir
:-p, --parents
no error if existing, make parent directories as needed …So using
-p
creates all the parent directories if required.
Exercise 35
What is the problem with the following command sequence?
%%sh cd /tmp # use /tmp as a playground (files in /tmp are deleted after reboot) echo carrots > shopping-list.txt echo thyme > shopping-list.txt echo parsley > shopping-list.txt
How can we avoid/undo our mistake?
Solution to
The file gets overwritten instead of appended.
There is no undo for
>
or>>
operation. We could regularly backup our files, but the better solution is that we become more cautious when using these kind of commands.
For more info browse the section Migration and Destruction
Final reflection#
Exercise 36
Did you reach the following learning objectives for this week? Discuss with your partner.
Describe Unix
Install and/or access Bash
Execute basic commands in the command line
Create and manipluate directories
Inspect, move, copy, and delete files and folders