410 likes | 588 Views
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
E N D
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 • The many flavors of Unix and the incompatiblity that came with it is still around • Multiple unix versions: good, because competition enhancesthere 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
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)
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
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
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
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
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
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
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
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)!
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)
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
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
Command line • Login can be Local (console or terminal) Remote: telnet, ssh, putty (Windows ssh client) On-Line help: man – reference, not a tutorialpractice, practice, practice • user: • hallgato:nik119 • Commands: • who am i • uname -a • ls • ls / • man ls
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
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
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
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
Where are we? Who are we? • uname -a • who • who am i (whoami) • w • last • ls • ls /
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
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)
Partitioning • / : root • /home • Swap • /boot • /usr • /var
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 \ !!!)
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
touch orange.txt • ls • ls -l • Joker characters: • *: Denotes any number of chars • ?: Denotes just one char
Tricky filenames (1) • echo „Hallo” > ‘apple*’ • echo „Welt” > appletree • echo „Hi”> applewine • cat appletree • cat applewine • cat apple*Escape character: '\' --> cat apple\*
Tricky filenames (2) • echo „apple” > aa • echo „orange” > bb • echo „fruit” > 'aa bb' • ls • cat aa bb • cat 'aa bb'
Print contents of file (1) • cat applewine • cat /bin/catWhat happened to the console?
Print contents of file (2) • cat applewine • cat /bin/catWhat 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
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
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
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
Directories • Relative path<--> absolute path • ls /etc • pwd • ls ../../etc • ls .. • ls . • PATH • echo $PATH • ./program
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
Directories • Create directory: mkdir • mkdir fruit • touch fruit/apple • touch fruit/orange • ls -l orange • ls –R, ls * : list subdirectories • delete directories: rmdir
Hidden files • Everything that starts with '.' is hidden • touch orange • touch .orange • ls • ls –a • orange and .orange are completely different
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”
Pipe, background • |: pipe • ls –l /etc | more • &: start command in background (later) • command &
Practice (for it makes perfect) Create the following directory structure: ~ directory1 directory2 directory3 directory4 directory41 directory11 directory12 directory21 directory22 directory111 directory23 directory112 Bonus: create a shell script which creates directories like so (creatdir directory113 – directory 11 and 1 are created) directory113
Practice Create files in each directory where the name of the file is file<number>. The <number> should be the number of the directory (eg: directory131: file131) Use touch, >, >> to create files Use TAB Use relative and full path Use your imagination For bonus points: create a shell script that when gets a filename like this, will create the directory and put the file in it