0% found this document useful (0 votes)
72 views24 pages

Linux 101: Johan Montelius

This document provides an overview of Linux and UNIX operating systems. It discusses the different UNIX families including GNU/Linux distributions like Ubuntu. It describes basic shell commands for navigating files and directories. It also covers using pipes to connect commands, working with text files, generating frequency lists from text, using tools like gnuplot, LaTeX, and make to write a thesis.

Uploaded by

Thomas Wang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views24 pages

Linux 101: Johan Montelius

This document provides an overview of Linux and UNIX operating systems. It discusses the different UNIX families including GNU/Linux distributions like Ubuntu. It describes basic shell commands for navigating files and directories. It also covers using pipes to connect commands, working with text files, generating frequency lists from text, using tools like gnuplot, LaTeX, and make to write a thesis.

Uploaded by

Thomas Wang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Linux 101

Johan Montelius
KTH

2017

1 / 24
The Unix Family

MULTICS MIT/GE/Bell Labs

UNIX AT&T (Bell Labs)

Mach, Carnegie Mellon BSD Berkeley SysV AT&T Minix, Tanenbaum

GNU/Hurd OS X, Apple FreeBSD NetBSD GNU/Linux, Stallman/Tordvals

iOS, Apple Orbis OS, Sony Android, Google

Probably left out a hundred other systems.

2 / 24
Even more

Figure: from www.levenez.com/unix/history.html 3 / 24


GNU/Linux distributions
The kernel will not get you far, you will need: drivers, file system, network,
security, codecs, window manager, compilers, browsers, office, games . . .

You can, but few do, download and compile exactly the components that you
want . . . few people do that.

openSUSE: supported by Novell,


Debian: the base for many - second most popular distro
Ubuntu, Mint . . . most popular
GenToo: BSD like, professional
Fedora: used by Linus, Red Hat users
commercial version, CentOS . . .
Arch Linux: for advanced users,
Mandriva: a.k.a Mandrake, Red Antergos, KaOS, Manjaro
Hat offspring, KDE, Intel only
Slackware: you’ll learn a lot
4 / 24
Ubuntu

Supported by Canonical
Based on Debian packages.
Two regular releases a year :04 and
:10
LTS - five year support, released
every second year
Things work and are easy to
maintain.

5 / 24
Ubuntu, Kubuntu, Lubuntu,....
Which version of Ubuntu to choose is very much a choice of desktop
environment.

6 / 24
the elephant in the room

7 / 24
Some basic stuff

the shell
files and directories
some tools: grep, wc, sed . . .
write a thesis: gcc, latex, gnuplot, make
environment variables

8 / 24
the shell

9 / 24
the directory

Commands that you should to know:

ls - list files and directories touch - touch a file


mkdir - make a directory rm - remove a file
rmdir - remove a directory mv - move a file
cd - change directory cp - copy a file
pwd - path of working directory ln - create a link (soft/hard) to a
file

10 / 24
shell expansions
The shell will expand any input before issuing command.

~ precede by space - expands to home directory.


* as in *.c - expands to a sequence of characters to matches files in the
directory
? as in f??.txt - expands to any single character
[06] as in ID220[06].pdf - expands one of the specified characters
$ as in $HOME - expands to the variable value (more on this later)

Expansion can be controlled by enclosing arguments in single quotes ’ ’, double


quotes " " (variables will be expanded) or precede character by backslash \.
11 / 24
work with a text file

Some more or less simple ways to explore the content of a text file:

cat - concatenate files sort - sort rows


less - less is of course more wc - word count
head - the beginning of a file uniq - remove duplicates
tail - the end of a file tr - transpose char-by-char
grep - search a file for pattern sed - stream editor
diff - difference of two files awk - more powerful than sed

12 / 24
pipes and redirect

The shell can set a file as the standard input of a command or redirect the
standard output and/or standard error.
< as in wc < foo.txt will set standard input.
> as in ls > out.txt will set standard output.
2> as in grep foo bar.txt 2> err.txt will set standard error.
The power of the UNIX shell is the concept of pipes.

grep typedef foo.c | sort | uniq | less

Standard output of one command becomes standard input of the next command

13 / 24
an example

Den bok jag nu sätter mig ner att skriva måste verka meningslös på många -
om jag alls vågar tänka mig, att "många" får läsa den - eftersom jag alldeles
självmant, utan någons order, börjar ett sådant arbete och åndå inte själv är
riktigt på det klara med vad avsikten är.

2019 jag
1818 och
1505 att
1429 det
1045 i
979 en
:
14 / 24
from text to frequency list

Turn a raw text into and ordered frequency list.


Remove special characters (.,?!;:-()”) from text using sed or tr.
Replace space by linefeed to turn the text into a list of words.
Sort the list using sort.
Remove duplicates but add frequency using uniq.
Sort the result using sort.
Everything is of course connected using pipes.

Experiment yourself, the devil is in the details.

15 / 24
to write a thesis

Run the benchmark and save the result in a text file.

Use gnuplot to produce a graph.

Write the thesis, including the graph, using LATEX.

Set up a Makefile to automate the process.

16 / 24
gnuplot

gnuplot

generate graphs from data in text file (tab separated)


interactive or from script
not a program for statistics (for statistics use R)

17 / 24
LATEX

pdflatex

will let you focus on content


easy to include content from other files
generates pdf

18 / 24
make

make

the work horse in any UNIX project


script will set up the dependencies between files
will run programs as needed to produce final output i.e “make”
used for programming as well as documentation

19 / 24
shell variables

The shell maintains a set of variables that can be accessed from the shell,
but not immediately from child processes.

set - control the shell environment HOME - home directory


<variable>=<value> - defines a PWD - current directory
variable value PATH - paths searched when looking
$<variable> - access variable for executables
from shell USER - user name

20 / 24
the environment

The environment is a set variables that can be accessed by programs using the
standard library function call getenv().

The shell will set up a set of exported variables that will be visible as
environment variables when a child process is created.
Functions from standard library.
export <variable> - make
variable accessible from child getenv() - get the value of
process variable
printenv - list all environment putenv() - set the value of variable
variables execle() - execute command in
env - run command in specified new environment
environment : - there are more
21 / 24
package-configure-make-execute

package - a set of source files and scripts

configure - check that everything is available, build Makefile

make - make, compile, environment variables define the target

execute - execute, environment variables describe the session

22 / 24
Summary

UNIX - many families, GNU/Linux is one, Ubuntu a distribution


the shell - your interface to any UNIX system
files and directories - learn to navigate the tree
shell and environment variables
work with text file, connect sequences with pipes

Do learn gnuplot, latex and make before starting your thesis.

23 / 24
Finally

Usage of the shell will be on the exam; best way to study is to use it!

24 / 24

You might also like