Unix/Linux basics

41
Unix/Linux basics Operating systems lab Gergely Windisch

description

Unix/Linux basics. Operating systems lab Gergely Windisch. Unix. It was created around the 70’s for mini computers. It has spread to the mainframes, workstations and then to personal computers Simplicity was always an aim The kernel was written in C (almost from the beginning) -> new - PowerPoint PPT Presentation

Transcript of Unix/Linux basics

Page 1: Unix/Linux basics

Unix/Linux basics

Operating systems labGergely Windisch

Page 2: Unix/Linux basics

Unix • It was created around the 70’s for mini computers. It has spread to

the mainframes, workstations and then to personal computers• Simplicity was always an aim• The kernel was written in C (almost from the beginning) -> new• The many flavors of Unix and the incompatiblity that came with it is

still around

• Multiple unix versions: good, because competition enhances there is no one accepted solution (incompatiblity)

• Standardization work, multiple standards (the important is „what”, not „how”)

• Commercially avalable Unix versions: Sun/Solaris, HP/HP-UX, IBM/AIX

• Interesting: Mac OS X (BSD based)

Multiuser, multitask operting system

Page 3: Unix/Linux basics

A Linux

• Born in 1991– Linus Torvalds – x86– Started life as a terminal app for minix

• Nowdays an alternative to Unix and Windows systems• Linux is not Unix, but similar• Unix like in appearance and programming API, different

under the hood• The kernel is not held by one company but is developed

by the community (with centralized management - Linus)

• The code base is developed by the community• Wide spectrum of supported hardware architectures• There are some pioneer solutions, but there are also

some weak spots compared to the „big” Unix versions (thread management in the 2.4 kernels for example)

Page 4: Unix/Linux basics

Linux - distributions• Linux distributions– „A Linux distribution (also called GNU/Linux by some

vendors and users) is a member of the family of Unix-like software distributions built on top of the Linux kernel. Such distributions (often called distros for short) consist of a large collection of software applications such as word processors, spreadsheets, media players and database applications. The operating system will consist of the Linux kernel and, usually, a set of libraries and utilities from the GNU project, with graphics support from the X Window System. „ - Wikipedia

– http://upload.wikimedia.org/wikipedia/commons/8/8c/Gldt.svg

Page 5: Unix/Linux basics

Linux – distros (cont’d)• Even more colorful than unix

– free and commercial as well• Most important commercial versions: RedHat and

Suse• Free versions: Debian and co. (debian based), Fedora

(RedHat based) and openSuse• Live CD try without installation– Knoppix: http://www.knoppix.org/ (Debian GNU/Linux)– Demolinux: http://www.demolinux.org/ (Mandrake)– More at:

http://en.wikipedia.org/wiki/Live_CD

Page 6: Unix/Linux basics

Useful links

• http://www.hup.hu – Hungarian Unix Portal– Only in hungarian for those of you who are

interesten in the language

• http://www.kernel.org – Place of the linux kernel

• http://www.distrowatch.com – home of practically all the distributions

Page 7: Unix/Linux basics

Where can I practice?

• Downloading linux: – www.ubuntu.com, www.debian.org,

www.slackware.com, www.suse.de, en.opensuse.org, www.distrowatch.com

• VMWARE pre-built images:http://www.vmware.com/vmtn/appliances/directory/cat/45

Page 8: Unix/Linux basics

Where can I get help?

• Everywhere!– The Hungarian Unix Portal:

http://hup.hu (again, for the eager minded)– Linux Knowledge Base and Tutorial:

http://www.linux-tutorial.info– http://en.wikipedia.org/wiki/Linux– Linux Shell Scripting Tutorial:

http://www.freeos.com/guides/lsst/– http://www.google.com

Page 9: Unix/Linux basics

The graphical world…

• Distributions– RedHat (www.redhat.com)– Ubuntu (www.ubuntu.com)– Debian (www.debian.org)– Slackware (www.slackware.com)–Mandriva (www.mandriva.com)– Suse (opensuse.org)– Let’s look at some of them

Page 10: Unix/Linux basics

Linux basics

• Linux is like Unix – API and the command line is unix compatible

• As far as we get into the subject, all the distros are the same

• Makes no difference which one we install

Page 11: Unix/Linux basics

Linux basics (cont’d)

• Multiuser: we do not rule the whole machine – just one session (many concurrent users)

• Authentication before being able to do anything – user + password

• System access is restricted – we can only modify those to which we have the permissions

• Simple users cannot change (break) the system (for that would affect others)!

Page 12: Unix/Linux basics

• Because of the multiuser environment, linux is somewhat different to other pc operating systems: one machine, multiple terminals. Still apparent today: virtual console

• Text based mode (shell) and graphical interface (X)• GUI is spreading like mushroom after the rainy season - but

the main interface for setting the system up is still the console.• Terminal access via TCP/IP, earlier it was via RS-232 (serial

port)• In a PC based desktop solution the machine and the view isn’t

separated, however it is still separated underneath (modularity)

Page 13: Unix/Linux basics

Root user

• Every OS needs a superuser who can access everything, set things up

• In Unix, the role is called root. Root has total control over the machine

• There can only be one root, it’s task cannot be given to multiple users

• Possible solutions: – sudo, RBAC (hasn’t really caught on)– Security Enhanced Linux

Page 14: Unix/Linux basics

Let’s start linux!

• VMWare workstation– Ubuntu8.10, XUbuntu8.10, Ubuntu 8.10 Server

• Credentials:– hallgato / nik119

• Take a good look around the system– Try programs like gimp, openoffice, kate, xcalc,

gmplayer, firefox etc.– Install software using Synaptic

• Packages vs. source

Page 15: Unix/Linux basics

Command line• Login can beLocal (console or terminal)Remote: telnet, ssh, putty (Windows ssh client)On-Line help: man – reference, not a tutorial practice, practice, practice

• user: – hallgato:nik119

• Commands:– who am i– uname -a– ls – ls /– man ls

Page 16: Unix/Linux basics

Take a look around!

• Ubuntu 8.10 tty1• Last login: When did we log in last• 2.6.27-2-386: current kernel– there can be multiple kernels on the machine

• Ubuntu Server does not have X

Page 17: Unix/Linux basics

Kernel• Three number versioning scheme

– Kernel version– Major revision– Minor revision

• Fourth number for immediate patches (2.6.8.1)• 1991 – Linux 0.01• 1994 – Linux 1.0• 1996 – Linux 2.0• 1999 - Linux 2.2.0• 2001 - Linux 2.4.0• 2003 - Linux 2.6.0

Page 18: Unix/Linux basics

Console

• The character interface is called console (or terminal)

• Virtual consoles. Switch: alt+F1 – alt+F6• Command line interpreter is BASH (shell)• Use tab key to complete commands– mor[tab]: more– cd /sbi[tab]: cd /sbin

• press tab twice if nothing happens

Page 19: Unix/Linux basics

Parancsok

• man : Manual – reference– There is a manual for almost every command

• man ls• ls –help• man man

• Commands– command

• switch: -• full name of switch: --

– eg: ls -a == ls --all

Page 20: Unix/Linux basics

Where are we? Who are we?

• uname -a• who• who am i (whoami)• w• last• ls• ls /

Page 21: Unix/Linux basics

Directories

• Important directories– / : root directory– /etc: home of the configuration files– /bin: executable commands– /var: files that change a lot : log, spool, mail– /home: users own directories– /usr/local: files of installed applications

Page 22: Unix/Linux basics

Könyvtárak

– /sbin: executables reserved for root– /boot: stuff for booting– /root: own directory of the root– /proc: system data (dynamic)

• cat /proc/cpuinfo (later)

Page 23: Unix/Linux basics

Partitioning

• / : root• /home• Swap• /boot

• /usr• /var

Page 24: Unix/Linux basics

File basics

• All files are byte streams• Files are denoted by their names• Filename can be quite long• There is no extension – can contain .• Hierarchical structure• Directory separator: / (and not \ !!!)

Page 25: Unix/Linux basics

File alapok (2)

• echo „Hello” > apple.txt• ls• ls -l• cat apple.txt• echo „Leo” >> apple.txt• cat apple.txt• echo „Hello World” > apple.txt• cat apple.txt

Page 26: Unix/Linux basics

• touch orange.txt• ls• ls -l

• Joker characters:• *: Denotes any number of chars• ?: Denotes just one char

Page 27: Unix/Linux basics

Tricky filenames (1)

• echo „Hallo” > ‘apple*’• echo „Welt” > appletree• echo „Hi”> applewine• cat appletree• cat applewine• cat apple*

Escape character: '\' --> cat apple\*

Page 28: Unix/Linux basics

Tricky filenames (2)

• echo „apple” > aa• echo „orange” > bb• echo „fruit” > 'aa bb'• ls• cat aa bb• cat 'aa bb'

Page 29: Unix/Linux basics

Print contents of file (1)

• cat applewine• cat /bin/cat

What happened to the console?

Page 30: Unix/Linux basics

Print contents of file (2)

• cat applewine• cat /bin/cat

What happened to the console?cat should only be used for printing text files

• /usr/bin/cat is a binary, with control codes• Print contents of any file: od• od /bin/cat• od -c /bin/cat

Page 31: Unix/Linux basics

File type

• Extension does not always help– file command

• file /usr/bin/file

• Uses file headers– Try tricking it into making a mistake:

• cp /usr/bin/apt-get . (use tab!)• file apt-get• mv apt-get something.mp3• file something.mp3

Page 32: Unix/Linux basics

File commands

• Remove: rm– rm apt-get– rm –r: remove recursively (subdirectories as well)

• Copy: cp– cp apple.txt orange.txt– ls

• Move: mv– mv apple.txt orange.txt– ls

Page 33: Unix/Linux basics

Directories

• cwd: current working directory– pwd command returns cwd

• ~: own directory of user– echo ~

• /home/user (/root): default dir to the user• . : current directory• .. : parent directory

Page 34: Unix/Linux basics

Directories

• Relative path<--> absolute path• ls /etc• pwd• ls ../../etc• ls ..• ls .• PATH– echo $PATH

• ./program

Page 35: Unix/Linux basics

Directories

• Moving around– cd

• cd /etc• cd etc• cd jumps to the user home directory• cd ~ jumps to the user home directory• cd .. jumps to the parent directory• cd / jumps to the root directory

Page 36: Unix/Linux basics

Directories

• Create directory: mkdir• mkdir fruit• touch fruit/apple• touch fruit/orange• ls -l orange• ls –R, ls * : list subdirectories• delete directories: rmdir

Page 37: Unix/Linux basics

Hidden files

• Everything that starts with '.' is hidden– touch orange– touch .orange– ls– ls –a

• orange and .orange are completely different

Page 38: Unix/Linux basics

Multiple commands

• &&: command1 && command2– Run command 2 after command 1– ls –l / && echo „success”– ls –l /homme && echo „success”

• ||: command1 || command2– run command2 after command 1 if command 1

failed– ls –l / || echo „failure”– ls –l /homme || echo „failure”

Page 39: Unix/Linux basics

Pipe, background

• |: pipe• ls –l /etc | more

• &: start command in background (later)– command &

Page 40: Unix/Linux basics

Practice (for it makes perfect)

~

directory1 directory2 directory3

directory21

directory22

directory23

directory4

directory11 directory12

directory111

directory113

directory112

directory41

Create the following directory structure:

Bonus: create a shell script which creates directories like so (creatdir directory113 – directory 11 and 1 are created)

Page 41: Unix/Linux basics

PracticeCreate files in each directory where the name of the file is file<number>. The <number> should be the numberof the directory(eg: directory131: file131)

Use touch, >, >> to create filesUse TABUse relative and full pathUse your imagination

For bonus points: create a shell script that when gets a filenamelike this, will create the directory and put the file in it