introduction to linux - tedusar.eu · d. isadvantages compared with. w. indows not all programs...
TRANSCRIPT
INTRODUCTION TO LINUX
REALLY SHORT HISTORY Before GNU/Linux there were DOS, MAC and
UNIX. All systems were proprietary. The GNU project started in the early 80s by
Richard Stallman Goal to make a free version of UNIX Developers make money by modifying and
extending existing software depending on companies needs
In the early 90s the Linux kernel appears which quickly becomes the defacto kernel for GNU
The GNU General Public License ensures that the source codes will be free for all to copy, study and to change
ADVANTAGES OVER WINDOWS It's free to relatively inexpensive Source code is available, due to GPL Bugs are fixed quickly and help is readily available
through the Internet (IRC, forums) Linux is
more stable than Windows A truly multi-user and multi-tasking
multiuser: OS that can simultaneously serve a number of users multitasking: OS that can simultaneously execute a number of
programs runs on equipment that other operating systems consider
too underpowered, e.g. 386 systems, embedded devices and smartphones.
Overall highly reliable as an operating system
DISADVANTAGES COMPARED WITH WINDOWS Not all programs exist for Linux
e.g. Office, Photoshop WINE enables you to run the majority of Windows
software in Linux Virtual machine with Windows
Isn't as popular as Windows Though this is changing as Linux distributions
develop more user friendly interfaces No specific commercial company is responsible
for Linux Typically companies maintain only their own
distribution of Linux
TYPES OF INTERFACES Typically we classify these into
GUI – Graphical user interface CLI – Console line interface
TYPES OF INTERFACES Typically we classify these into
GUI – Graphical user interface CLI – Console line interface
LINUX AND WINDOWS Linux:
From the very start it has been CLI oriented. The GUI is just an additional program that passes commands to the CLI Features accessible from the GUI also accessible from the
CLI (but not necessarily a simple command) Always possible to switch to CLI if something goes wrong
Windows Started out as a GUI focused operating system.
DOS console still available, but lacking in expressive power and user friendliness
CLI is returning to Windows – PowerShell Cygwin or MSYS - a collection of programs enabling a
Linux-like CLI in Windows
GRAPHICS USER INTERFACE IN LINUX By adopting the X-Window technology, the
graphical user interface is also available for Linux: Uses pointing devices (e.g. mouse) to control the
system, similar to Microsoft’s Windows Advantages: Tasks selectable from menus or icons.
Learning curve is very low, can do certain types of work immediately.
Disadvantages: Slow and requires certain resources to run Not an issue on modern PCs
Suitable for general users and personal computers Ubunto, Linux Mint and others
COMMAND LINE INTERFACE IN LINUX Traditional Linux (Unix also) uses command line
driven interface (or text-based interface) User needs to type command to instruct the computer
to do work (as in DOS) Advantage: fast performance. Very few resources are
required for its use. More flexible and easier automation of tasks
Disadvantages: user needs to type, making it error prone. Learning curve is higher than GUI
Suitable for advanced users and for the systems that interaction with user is not frequent, such as servers or embedded systems
LINUX SHELL Shell interprets CLI commands and
requests appropriate services from the Linux kernel
Similar to DOS but DOS has only one shell, while Linux can select from a variety shells Bourne Again shell (Bash), Debian
Almquist (dash), Z shell (Zsh)
Different shells have similar but different functionality
Bash is the default for most The GUI interface is an application
started from shell
Kernel
Bash, Tcsh, Zsh
ls pwd whoami
SOME QUICK HANDS ON TERMINAL While we are in the GUI, to get to the terminal
(CLI), we must find and open the program “Terminal”
THE TERMINAL Typically we are greeted by a window that looks like
this
andrew@production:~$ Immediately noticable:
Our user name (andrew) The computers name (production) Our security status (regular user - $ or super user - #)
THE TERMINAL - TTY As mentined, we can always access the terminal.
One mode is to switch to the virtual terminal – TeleTYpewriter - TTY
Ctrl+Alt+Fn lets us switch between12 TTY terminals Fn being F1,F2,F3…F12
The GUI in Ubuntu runs in terminal 7 – TTY7! Same as using the terminal program, only here
we are directly in the console. The terminal program in GUI is just a fancy TTY
USER MANAGEMENT As a user you can change your files, user
information and run programs Depends on your privileges
As a superuser (su) you can do any operation to anything and anyone Dangerous, try to avoid using superuser for
everything (typically named root) Anyone ever rooted their phone?
“Permission denied” when executing command as user? May need to execute command as superuser Append sudo to command (sudo – superuser do)
ADDING USERS Easy and straightforward
Run the following as a superuser (root or via
sudo) useradd –m USERNAME
The –m flag will create a home directory passwd USERNAME
Set the users password so he can login usermod –s /bin/bash USERNAME
Modify the users shell (-s) to use bash By default the shell is /bin/sh, a lightweight shell
LINUX FILE ACCESS PRIVILEGES Linux is a multiuser system, the files of all users
are stored in a single file structure Mechanism is required to restrict one user to
access the files of another user, if he is not supposed to
User can impose access permission to each file to restrict its access
The term “access permission” refers to read permission write permission execute permission
LINUX FILE ACCESS PRIVILEGES Access permission can also be assigned to a directory Directory is also a file that contains the attributes of
the files inside it If read permission is not given to a directory
cannot show the structure of this directory e.g. cannot use ls
If write permission is not given to a directory cannot modify anything of the directory structure e.g. cannot copy a file into this directory since it will modify
the directory structure by adding one more file If execute permission is not given to a directory
nearly nothing can be done with this directory, even cd
LINUX FILE ACCESS PRIVILEGES Use ls –l to view current directory files and
details
It is a directory
Owner policy The directory can be read, written and executed by the owner
Group policy The directory can be read and executed but not written by other users in the same group
Everyone else policy The directory can be read and executed but not written by other users in a different group
Owner Owner’s group
file size
File last modified date Hard link
no
file name
d rwx r-x r-x 2 john users 4096 July 24 2013 Autostart
POLICY PERMISSSIONS
Total value Read
Value 4
Permissions Write
Value 2
Execute Value 1
Listing
0 no read no write no execute --- 1 no read no write execute --x 2 no read write no execute -w- 3 no read write execute -wx 4 read no write no execute r-- 5 read no write execute r-x 6 read write no execute rw- 7 read write execute rwx
LINUX FILE ACCESS PRIVILAGES The access permission of a file or directory can be
changed by using the command
chmod xyz filename/directory name
660 : 110 110 000 ⇒ rw- rw- --- 545 : 101 100 101 ⇒ r-x r-- r-x
xyz refers 3 digit in octal form (cant go higher than 7) For example
421 421 421
LINUX FILE ACCESS PRIVILEGES The owner of a file or directory can be changed by
using the command
chown user:group filename/directory
user – for which user are user access privileges applied to
group – for which group are user access privileges applied to
LINUX FILE SYSTEM STRUCTURE According to the File System Standard (FSSTND)
proposed in 1994, every LINUX system should contain a set of standard files and directories
23
root /
bin
boot dev etc home
lib lost+found mnt opt
proc
root sbin
tmp usr
var
fd sd sd …
group passwd john doe bin lib local
file
directories
LISTING CONTENT OF ROOT /
THE FILESYSTEM In Linux, a file is defined as simply the thing that
deals with a sequence of bytes Hence everything are files
An ordinary file is a file; a directory is also file; a network card, a hard disk, any device are also files since they deal with a sequence of bytes
A few types of files simple/ordinary file (text file, c++ file, etc) directory symbolic (soft) link special file (device) named pipe (FIFO)
It is essetial that we know some basics on how to navigate the filesystem
SYMBOLIC LINKS AND DEVICES Symbolic (soft) link
Not a real file, just a link to another file Allow giving another name to a file without actually
duplicating it – save disk space Special file (device)
Each hardware device, e.g. keyboard, hard disk, CD-ROM, etc is associated with at least one file
Typically located in /dev directory Applications can read and write any devices by reading
and writing their associate file – hence the access method is known as device independent The drives is responsible for communicating with the actual
hardware Divide into two types: character special files, e.g. keyboard,
and block special files, e.g. hard drive
LINUX FILE SYSTEM STRUCTURE Root Directory ( / )
Top of the file system. Contains everything. /bin
Contain the binaries (executable code) of most essential Linux commands, e.g. bash, cat, cp, ln, ls, etc.
/boot Contain all the files needed to boot the Linux system,
including the binary of the Linux kernel. /dev
Contains the special files for devices, e.g. fd0, sda, etc.
LINUX FILE SYSTEM STRUCTURE /etc
Contain host-specific files and directories, e.g. information about system configuration
/home Contain the home directories of every user in the
system, e.g. dlun, guest, etc /lib
Store all essential libraries for different language compilers
/lost+found Contain all the files on the system not connected to
any directory. System administrator should determine the fate of
the files in this directory
LINUX FILE SYSTEM STRUCTURE /mnt Ubunto will typically mount to /media!
Used by system administrator to mount file systems temporarily by using the ‘mount’ command
Before using any devices (located in /dev), they have to be mounted to the system for registration
For example, after mounting a CD-ROM, the file system in it will be mapped to /mnt/cdrom directory Ubunto maps to /media/CD_name
User can then read and write files in the CD-ROM by accessing this directory
Similar to mapping a drive letter to a CD-ROM in Windows
Different from the special file in /dev. The special file is only a place where data of the CD-ROM is transferred or stored. No file system concept.
LINUX FILE SYSTEM STRUCTURE /opt
Use to install optional, add-on software packages, e.g. LibreOffice and such
/proc Contains process and system information
/root Home directory of the user root, usually the
administrator /sbin
The directories /sbin, /usr/sbin, and /usr/local/sbin contain system administration tools, utilities and general root only commands, such as halt, reboot and shutdown
LINUX FILE SYSTEM STRUCTURE /tmp
Contain temporary files. Usually files in this directory will be deleted from time to time to avoid the system fills with temp files
/usr One of the largest sections of the Linux file system Contain read-only data that are shared between
various users /var
Contain (variable) data that keeps on changing as the system is running.
FREQUENTLY USED COMMANDS TO NAVIGATE AND MANIPULATE THE FILESYSTEM
pwd : show the name of the current directory ls : to show the names of the file in the current
directory cd : change directory
cd / change to the root directory cd .. change to the parent of that directory
cp : copy one file to another cp abc.txt xyz.txt copy abc.txt to xyz.txt
rm : remove file rmdir : remove (empty) folder man : ask for the manual (or help) of a command
man cd ask for the manual of the command cd
FREQUENTLY USED COMMANDS TO NAVIGATE AND MANIPULATE THE FILESYSTEM
touch: create an empty file touch abc.txt create empty file with name abc.txt
cat : show the content of a text file cat abc.txt show the content of abc.txt
nano: simple text editor (one of many) vi : advanced text editor (read manual and tutorials!) man : ask for the manual (or help) of a command
man cd ask for the manual of the command cd
PROCESS MANAGEMENT Linux is a multitasking system Multiple programs can be executed at the same
time Ultimately, a program needs to be executed by a
CPU If there is only one CPU, how are multiple
programs executed at the same time? They are not, they share the CPU time CPU sharing happens so fast it feels like all
programs are executing in parallel
VIEW PROCESSES One can easily see the system status of
executables with command top
VIEW PROCESSES Or using ps -a
KILLING PROCESSES
If a process becomes unresponsive, one way to end it is to use signals; the command kill -ID PID ID what kill signal to send PID proces ID, can be found in top command and
elsewhere
Common kill signal IDs 1 – Hang up, safest way to ask a process to stop 2 – Kill program, same as pressing Ctrl + C 9 – Forces termination, last resort 15 – Ask process to end itself
INSTALLING APPLICATIONS Using apt-get
Typically recommended to do apt-get update Will fetch an up to date list of applications
Install package with apt-get install PACKAGE Search through the list of applications with apt-cache search NAME
Update all installed packages with apt-get upgrade
HINTS Always use TAB
It will auto-complete what we are typing by looking at available executables and files
If more than one option is available, press TAB multiple times to switch between them
Available executables are determined by PATH and files are determined by our location in the filesystem
EXERCISE ONE Position yourself to the home directory
cd ~ Using the wget command, download these slides
from http://gemma.uni-mb.si/ros2014/slides.pdf Syntax is wget URL
wget http://gemma.uni-mb.si/ros2014/slides.pdf
Open the slides and go to the next page
EXERCISE TWO Again using the wget command, download more
exercises from http://gemma.uni-mb.si/ros2014/exercises.txt
You can open them with any text editor (gedit)
HELPFUL LINKS Expanded cheat sheet for command line
http://www.cheatography.com/davechild/cheat-sheets/linux-command-line/
Introduction to Linux command line http://www.phas.ubc.ca/~mbelab/computer/linux-
intro/html/ Writing Bash scripts
Scripts are typically non compiled programs http://mywiki.wooledge.org/BashGuide