November 21, 2018

Links

Example

cp science.txt a.txt
ln a.txt b.txt
ls -l ?.txt
-rw-r--r--  2 anaraven  staff  7767 21 Nov 09:08 a.txt
-rw-r--r--  2 anaraven  staff  7767 21 Nov 09:08 b.txt
rm a.txt
ls -l ?.txt
-rw-r--r--  1 anaraven  staff  7767 21 Nov 09:08 b.txt

Physical disk

Link work only on one physical disk, since disk locations are valid only inside the same disk

In Unix there is only one “folders tree”, even crossing to different disks

In Windows each disk has a separated tree

C: is one disk, C:/Users/student is a folder inside a folder in the C: disk

Soft links

Example

ln -s b.txt c.txt
ls -l ?.txt
-rw-r--r--  1 anaraven  staff  7767 21 Nov 09:08 b.txt
lrwxr-xr-x  1 anaraven  staff     5 21 Nov 09:08 c.txt -> b.txt
rm b.txt
ls -l ?.txt
lrwxr-xr-x  1 anaraven  staff  5 21 Nov 09:08 c.txt -> b.txt

c.txt is now a broken link

Two commands in one line

echo "Current date and time is"; date
Current date and time is
Wed 21 Nov 2018 09:08:05 +03
for i in 1 2 3; do echo $i; done
1
2
3

Quotes: Putting words together

Single and double quotes can be used to write space inside an argument

for i in '1 2' "3 4" 5; do echo $i; done
1 2
3 4
5

Single and double quotes are different

echo '$USER'
$USER
echo "$USER"
anaraven

Backquotes are different

The symbol ` is called backquote

It is used to run a command and use its output as input to another command

echo "Now is `date`"
Now is Wed 21 Nov 2018 09:08:05 +03

Alternative: $(command)

Sometimes ` is hard to see

It is better to use something that reminds us of getting the value of something

echo "Now is $(date)"
Now is Wed 21 Nov 2018 09:08:05 +03

Creating sequences of numbers

Up to 5

seq 5
1
2
3
4
5

Creating sequences of numbers

From 2 to 6

seq 2 6
2
3
4
5
6

Creating sequences of numbers

From 2 to 10 in steps of 3

seq 2 3 10
2
5
8

Putting it all together

for i in $(seq 1 3 15); do echo $i; done
1
4
7
10
13

Text editor

Traditional Unix editor

All UNIX systems come with a text editor called vi

Modern UNIX systems have also an improved version called vim

It is a very powerful system, but hard to learn

(with great power comes great responsibility)

Here we will learn to use nano, which is easier to learn

Nano

How to use nano

Open the editor with the command nano

The last two lines show the commands you can use

When it says ^G it means CTRL-G

When it says M-U it means ESC U

CTRL and G are pressed at the same time

ESC is pressed first, then released, then press U

Try it

Write this

Traditional Unix editor
=======================

All UNIX systems come with a text editor called `vi`

Modern UNIX systems have also an improved version
called `vim`

It is a **very powerful** system, but hard to learn

(with great power comes great responsibility)

Here we will learn to use `nano`, which is easier to learn