Introduction Emanuele Valea <valea@lirmm.fr> LIRMM CNRS / - - PowerPoint PPT Presentation

introduction
SMART_READER_LITE
LIVE PREVIEW

Introduction Emanuele Valea <valea@lirmm.fr> LIRMM CNRS / - - PowerPoint PPT Presentation

Introduction Emanuele Valea <valea@lirmm.fr> LIRMM CNRS / Universit de Montpellier Course Outline UNIX operating system: an introduction Basic commands Shell Tools and advanced commands Shell scripts Lesson Outline


slide-1
SLIDE 1

Introduction

Emanuele Valea <valea@lirmm.fr> LIRMM CNRS / Université de Montpellier

slide-2
SLIDE 2

Course Outline

  • UNIX operating system: an introduction
  • Basic commands
  • Shell
  • Tools and advanced commands
  • Shell scripts
slide-3
SLIDE 3

Lesson Outline

  • Introduction
  • The file system
  • How to handle files and directories
  • Basic commands
slide-4
SLIDE 4

Lesson Outline

  • Introduction
  • The file system
  • How to handle files and directories
  • Basic commands
slide-5
SLIDE 5

How to start a session

  • To begin a session:

login: Password:

  • To end a session:

CTRL-d exit logout BE CAREFUL! Unix is case sensitive

slide-6
SLIDE 6

Connection to the system

  • If Linux is installed on your machine:
  • Just turn on your PC!
  • If Linux is installed on a remote server:
  • VNC
  • SSH
  • -X  it allows graphical interface
slide-7
SLIDE 7

Connection to the system: SSH

Unix Server Your PC

slide-8
SLIDE 8

Connection to the system: SSH

  • If your PC runs Linux or Mac:
  • From your terminal simply run:
  • ssh [-X] [<username>@]<hostname>
  • -X  it allows graphical interface
  • If your PC runs Windows, you must use external

programs:

  • PuTTY
  • MobaXterm
slide-9
SLIDE 9

Connection to the system: VNC

VNC Viewer VNC Server

slide-10
SLIDE 10

VNC Server (under Linux)

  • Connect to the VNC Server using SSH
  • Run the server:
  • vncserver –geometry 1280x1024 –depth 24
  • For the first execution you have to enter a password

(that will be used to authenticate the client)

  • It will show a number (for instance “:3”) that

represents the display number

slide-11
SLIDE 11

VNC Viewer

  • Just run the VNC viewer
  • Put the address of the server, including the display

number

  • Example: <hostame>:<display_number>
  • Put your username
  • Use the password you configured in the server
slide-12
SLIDE 12

VNC Server (some hints)

  • Use:
  • vncserver –kill :display
  • to kill the server for the specified display
  • Example:
  • vncserver –kill :3
  • Use vncpasswd to change the password
slide-13
SLIDE 13

Connection to the system

  • Try for yourselves!
slide-14
SLIDE 14

Basic characteristic

  • Multiuser: for each user:
  • username
  • uid
  • gid
  • password
  • Multiprocess

There is the special user “root”

slide-15
SLIDE 15

Command syntax in UNIX

  • command [-options] [arguments]
  • It is possible to execute more than one command

using the character “;” command1 ; command2 ; ... Commands are executed one after the other

slide-16
SLIDE 16

Manual

  • All Unix commands are documented:
  • man <command>
  • apropos <topic>
  • whatis <command>
  • All man pages can be easily found on the internet!
slide-17
SLIDE 17

Getting help

  • One thing to remember:
  • If I have a problem, it is VERY LIKELY that someone has

already solved it.

  • The first place where you will find solutions, are

forums on the internet

  • Example: Stack Overflow, Stack Exchange, ecc…
slide-18
SLIDE 18

Lesson Outline

  • Introduction
  • The file system
  • How to handle files and directories
  • Basic commands
slide-19
SLIDE 19

File System

  • Features:
  • Hierarchic
  • Directory-based File System
  • Uniform (disk, directory, file)
  • Hard link (same file with different names)
  • Soft link (i.e., shortcut)
  • File permissions
slide-20
SLIDE 20

File System Hierarchy

/ bin sbin dev etc lib tmp var usr adm spool tmp bin etc include lib man local

slide-21
SLIDE 21

Directory handling

  • ls
  • It shows the content of the current (or work) directory
  • cd <dir>
  • It changes the current directory
  • pwd
  • Print Work Directory
  • mkdir <dir>
  • It creates a directory
  • rmdir <dir>
  • It removes a directory (dir must be empty)
slide-22
SLIDE 22

Directory handling

  • The father of a directory is called ‘..’
  • Example: cd ..  go back to the upper level in the

directory tree.

  • The list of files and directories of the directory itself

is called ‘.’

  • mkdir /<dirname>  creates a directory in the

root directory

  • mkdir ./<dirname>  creates a sub-directory in

the work directory

slide-23
SLIDE 23

File names

  • The name of the file can be a sequence of any characters
  • A file is called hidden file when its name starts with ‘.’
  • Special characters (for the shell):
  • / \ “ ' * ; ? [ ] ( ) ~
  • ! $ { } < > # @ & | <space>
  • To select a file that is not in the current directory it is

necessary to specify the path:

  • Absolute path: /dir1/dir2/file
  • Relative path: subdir1/subdir2/file
slide-24
SLIDE 24

Lesson Outline

  • Introduction
  • The file system
  • How to handle files and directories
  • Basic commands
slide-25
SLIDE 25

File handling

  • cp [-fir] src1 src2 ... dest
  • To copy one or more files
  • rm [-fir] file1 file2 …
  • To delete one or more files
  • mv [-fi] file1 file2 ... dest
  • To move (or rename) one or more files
slide-26
SLIDE 26

File handling (cont.)

  • Options:
  • -f it does not ask for confirmation
  • -i it asks for confirmation (for each file)
  • -r it works recursively on every file in sub-directories
slide-27
SLIDE 27

File permission modes

  • 3 permission modes:
  • read (r)
  • write (w)
  • execute (x)
  • 3 user categories:
  • user (u): the owner
  • group (g)
  • others (o)
slide-28
SLIDE 28

Directory permission modes

  • Permission modes for files have different meanings:
  • x: the possibility to execute the file
  • r: the possibility to read the file
  • w: the possibility to modify the file
  • Permission modes for directories:
  • x: the possibility to enter the directory
  • r: the possibility to show the list of files
  • w: the possibility to create and remove files
slide-29
SLIDE 29

How to change the permissions

  • To change the permission modes of the file:

chmod [-R] mode file

  • The permission can be specified:
  • as octal value:
  • as symbolic string:
  • +, -, =
  • u(ser), g(roup), o(ther), a(ll)
  • r, w, x

User Group Other 4 2 1 4 2 1 4 2 1 r w x r w x r w x

slide-30
SLIDE 30

How to change the permissions (cont.)

  • Examples:
  • chmod 777 filename
  • chmod +gx filename
slide-31
SLIDE 31

Lesson Outline

  • Introduction
  • The file system
  • How to handle files and directories
  • Basic commands
slide-32
SLIDE 32

ls

  • List directory contents
  • ls [-options] [file ...]
  • Options:
  • -a: do not ignore entries starting with .
  • -l: use a long listing format
  • -g: like -l, but do not list owner
  • -r: reverse order while sorting
  • -t: sort by modification time
  • -R: list subdirectories recursively
slide-33
SLIDE 33

ls - example

  • # ls -alg ~/tmp

total 84 drwx------ 5 maino staff 512 Sep 1 16:14 . drwxr-xr-x 19 maino staff 1024 Sep 6 09:06 ..

  • rw-r--r--

1 maino staff 1240 Jan 21 1992 AA.readme drwxr-x--- 2 maino staff 512 May 22 14:08 examples

  • rw-------

1 maino staff 2416 Jun 30 15:24 gendata.c

  • rw-------

1 maino staff 332 Jun 18 15:29 local.c drwxr-xr-x 2 maino staff 512 May 22 14:08 man

  • rw-r-----

1 maino staff 27930 Mar 12 23:19 new.tex

  • rw-------

1 maino staff 28077 Mar 12 22:52 numer.tex

  • rw-r-----

1 maino staff 70 Jun 2 18:00 prova.tex

  • rw-r-----

1 maino staff 1364 May 6 14:20 random.c

  • rw-r-----

1 maino staff 62 May 6 14:21 random.h drwx------ 2 maino staff 512 May 25 14:36 testprof

slide-34
SLIDE 34

Text file analysis

  • Using a text editor (e.g. vi, emacs, gedit)
  • cat file1 file2 …
  • Writes the contents of all the files listed to the screen
  • head [-n] file …
  • output the first n lines of the file
  • Default: n=10
slide-35
SLIDE 35

Text file analysis

  • tail [-n] [+n] [-f] file …
  • Output the last part of the file:
  • -n:

last n lines, instead of the last 10

  • +n:

all but the first n lines

  • -f:
  • utput appended data as the file grows
slide-36
SLIDE 36

Text file analysis

  • pg file ...
  • more file ...
  • less file ...
slide-37
SLIDE 37

Text file analysis

  • During the visualization:
  • space

next page

  • CR

next line

  • b

previous page

  • /pattern

next page with search pattern

  • ?pattern previous page with search pattern
  • q

quit

slide-38
SLIDE 38

File size and available space

  • df [-k] [drive ...]
  • It shows how much free space is left on your system
  • -k: KB is used (instead of blocks of 512 bytes)
  • du [-aks] <directory> …
  • It prints out the amount of space occupied by a dir
  • -a: detail report for each file
  • -s: it recourses into any subdirectories and prints
  • nly a summary
  • -k: KB is used (instead of blocks of 512 bytes)
slide-39
SLIDE 39

df: example

  • $ df
  • Filesys.

1024-bl. Used Av. Cap. Mnt

  • /dev/hda3

199270 182354 6625 96% /

  • /dev/hda1

61060 20967 36939 36% /usr

  • /dev/hda4

199271 147953 41027 78% /home/pc

slide-40
SLIDE 40

Finding a file

  • find dir expression
  • search for files in a directory hierarchy
  • find /users -name core
slide-41
SLIDE 41

Finding a file

  • -name pattern
  • Base of file name
  • Caveat: use ‘pattern’ for regular expressions
  • -type type
  • File type = b(lock), c(haracter), d(irectory), l(ink), f(ile),

s(ocket)

  • -user username / -group groupname
slide-42
SLIDE 42

File Comparison

  • cmp file1 file2
  • compare two files byte by byte
  • comm [-123] file1 file2
  • compare two sorted files line by line
  • It generates 3 columns:
  • in-file1-only in-file2-only common-lines
  • -1 suppress lines unique to FILE1
  • -2 suppress lines unique to FILE2
  • -3 suppress lines that appear in both files
slide-43
SLIDE 43

File Comparison

  • diff [-options] file1 file2
  • compare files line by line
slide-44
SLIDE 44

time

  • time command
  • run programs and summarize system resource usage
  • Example:
  • time ls -la
slide-45
SLIDE 45

wc

  • wc file
  • Print the number of newlines, words, and bytes in

files

slide-46
SLIDE 46

ftp / sftp

  • It allows transferring files from/to a remote server
  • ftp server
  • sftp server
  • Basic commands:
  • cd

change directory on the remote SERVER

  • ls

list files within the current directory on the remote SERVER

  • binary

prepare the FTP tool to transfer binary files (applications or images)

  • ascii

prepare the FTP tool to transfer ascii or text files such as .html files

  • put

copy a specific file from the local machine to the remote SERVER

  • get

copy a specific file from the remote SERVER to the local PC

  • del

delete a specific file on the remote SERVER

  • bye

end your FTP connection