Η παρουσίαση φορτώνεται. Παρακαλείστε να περιμένετε

Η παρουσίαση φορτώνεται. Παρακαλείστε να περιμένετε

Σύστημα αρχείων του UNIX, Διασωλήνωση, Άδειες πρόσβασης, ο editor vi

Παρόμοιες παρουσιάσεις


Παρουσίαση με θέμα: "Σύστημα αρχείων του UNIX, Διασωλήνωση, Άδειες πρόσβασης, ο editor vi"— Μεταγράφημα παρουσίασης:

1 Σύστημα αρχείων του UNIX, Διασωλήνωση, Άδειες πρόσβασης, ο editor vi
2ο ΕΡΓΑΣΤΗΡΙΟ ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

2 Φλοιός UNIX χρήστης Φλοιός UNIX φλοιοί Τύποι Πυρήνας
Η διεπαφή του χρήστη με το σύστημα Διερμηνεύει τις εντολές Εκτελεί τα προγράμματα Τύποι Bourne (sh), Korn (ksh), C (csh), Bourne Again (bash) Ένδειξη αναμονής (Prompt) συνήθως “%”, “$”, or “>“ Μπορεί να τροποποιηθεί από τον χρήστη Πυρήνας Hardware εφαρμογές φλοιοί χρήστης ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

3 Εκτέλεση εντολών στο φλοιό
ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

4 Μορφή εντολής UNIX [prompt]$ <command> <flags> <args> Ή <command> <options> <arguments> Η πρώτη λέξη είναι η εντολή Το υπόλοιπο τμήμα, αν υπάρχει, είναι επιλογές (options) και ορίσματα (arguments) Οι εντολές είναι case sensitive (διαφορά μεταξύ κεφαλαίων και μικρών) και γράφονται με μικρά γράμματα Μια εντολή μπορεί να έχει ή να μην έχει ορίσματα $ date $ ls -l Τα ορίσματα είναι συνήθως αρχεία και κατάλογοι ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

5 Εντολές (2) επιλογές: Μεμονωμένα γράμματα Προηγείται μια παύλα “-” Συνδυασμός ή διαχωρισμός (π.χ. -al = -a -l) Προηγούνται άλλων ορισμάτων Πρέπει να υπάρχουν κενά μεταξύ των εντολών, των επιλογών και των ορισμάτων Πολλαπλές εντολές διαχωρίζονται με “;” και εκτελούνται σειριακά. Χαρακτήρες ελέγχου: Ctrl-c, Ctrl-h, Ctrl-z, … On-line βοήθεια (man pages) ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

6 UNIX Filesystem / ... ... ... ... ... root directory
bin etc usr home ... tmp ... ... ls hosts eagle studin kicker UNIX File System All the stored information (files) on a UNIX computer are kept in a filesystem which is organized in a hierarchy structured like an upside down tree. The top is the root (written “/”). Beneath the root are files and directories. What is a Directory? A directory is a file which contains other files or directories. They are used to help organize related files so that it is easier for you to find where they are. Directories are just like subdirectories on the PC or folders on the Mac, and may contain files and other directories. Here is a list of some directory that are part of most UNIX file systems: /dev/ Where special files are kept /bin/ Executable system utilities, like sh, cp, rm /etc/ System configuration files and databases /lib/ Operating system and programming libraries /tmp/ System scratch files (all users can write here) /usr/bin/ Additional user commands /usr/include/ Standard system header files /usr/lib/ More programming and system call libraries /usr/local/ Typically a place where local utilities go /usr/man The manual pages are kept here What is a file? In general terms, a file is a collection of related information (usually a program or data) which is stored within the physical storage space of a computer system. This is the file commonly used and covers anything from text to graphical files. thesis bin ... mail User home directory ch1.tex ... ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

7 Ονόματα αρχείων και καταλόγων
Διαχωρισμός κεφαλαίων και μικρών χαρακτήρων Χρήση οποιουδήποτε χαρακτήρα Αποφυγή των “/”, “>“, “ “, “!”, Επιτρέπονται αλλά χρησιμοποιούνται δύσκολα με τα προγράμματα φλοιού Μήκος: εξαρτάται από το σύστημα, συνήθως μεγάλο Πρέπει να είναι μοναδικά εντός του ίδιου καταλόγου Wildcards – χαρακτήρες μπαλαντέρ “*” οποιοδήποτε πλήθος χαρακτήρων “?” οποιοσδήποτε χαρακτήρας “[ ]” καθένας από τους χαρακτήρες μεταξύ των αγκυλών ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

8 Pathnames pathname: είναι μια διεύθυνση που εντοπίζει τον κατάλογο ή το αρχείο στο σύστημα αρχείων του UNIX. απόλυτο pathname: ξεκινούν πάντοτε με “/” /home/eagle/thesis/ch1.tex σχετικό pathname: δεν ξεκινά ποτέ με “/” thesis/ch1.tex Σχετικό όνομα διαδρομής ένα επίπεδο πάνω: χρήση “..” ../thesis/ch1.tex ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

9 Πλοήγηση σε καταλόγους
μετακίνηση $ cd /etc $ cd thesis/fig $ cd .. Πού βρίσκομαι $ pwd /home/eagle Δημιουργία/διαγραφή $ mkdir GoodStuff $ rmdir BadStuff ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

10 Πλοήγηση σε καταλόγους(2)
File listing $ ls - normal list $ ls -a - normal list + plus hidden files $ ls -l - long list $ ls -al - long list + hidden files $ ls -F - normal list + file type ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

11 Long Listing Files access permission owner group name modification
bash$ ls -l total 306 -rwxr-xr-x 1 zoman zoman Aug ChModAll -rwx zoman zoman Aug Dis -rwxr-xr-x 1 zoman zoman Aug MyClean -rwxr zoman zoman Aug chksp -rwxr zoman zoman Aug d2t -rwx zoman zoman Aug dvi2ps -rwxr-x--x 1 zoman zoman Aug hcal -rwxr-x--x 1 zoman zoman Aug hdate -rwx zoman zoman Aug mps -rwx zoman zoman Aug pa -rwxr-x zoman zoman Aug praytime -rwx zoman zoman Aug spl bash$ access permission owner group name List Directory Contents To list the normal files and subdirectories within your current working directory, use the ls command. To list the files in another directory, such as "/home", include the directory name in the command: $ ls /home This command will list all files and subdirectories (except hidden files) in the directory you specify. Adding options to the ls command alters how the directory is listed. The command $ ls  -a lists all files and subdirectories in the directory, including "hidden files" (any file whose name begins with a period "."). $ ls  -F puts a "/" at the end of directories in the listing and an "*" at the end of a program (executable) file. This allows you to tell at a glance whether the item is a file, a program, or another directory. $ ls  -l displays a long list of directory contents that includes: file type, access permissions, owner, size, creation date, and file name. You may combine options. For example, ls -al displays all files in the long format. modification date and time # of links size (bytes) type ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

12 Άδειες πρόσβασης (access permissions)
Η άδεια πρόσβασης σε ένα αρχείο ελέγχει τι μπορεί να γίνει με τα περιεχόμενα του αρχείου. Η άδεια πρόσβασης σε ένα κατάλογο όπου βρίσκεται το αρχείο ελέγχει αν το αρχείο μπορεί να μετονομαστεί ή να διαγραφεί. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

13 r-x r-x rwx -rwxr-xr-x Άδειες πρόσβασης
Ο πρώτος χαρακτήρας δείχνει τον τύπο του αρχείου: directory (d) plain file (-) r-x r-x rwx -rwxr-xr-x Το υπόλοιπο, προσδιορίζει 3 τύπους χρηστών owner group others Τι επιτρέπεται (r) read (w) write (x) execute Understanding Access Permissions Permissions are defined as read, write, and execute. The read, write, and execute permissions are referred to as r, w, and x, respectively. Those to whom the permissions apply are the user who owns the file, those who are in the same group as the owner, and all others. The user, group, and other permissions are referred to as u, g, and o, respectively. The access permission is contained in the collection of d's, r's, w's, and x's to the left of the output of the command ls -al. These ten spaces, containing either letters or dashes, tell you what kind of file is shown and how secure it is. Let's start with the first column (from left). If you see a `d' here, it means the object you are looking at is a subdirectory. If you see a `-', the object is a file of some sort (either program or data). The next nine letters detail how secure your files are. The first group of three letters describes your own privileges. An `r' means you can read a file, a `w' means you can write to a file (write means you can edit and delete it), an `x' means you can run the file (if it is a program -- an `x' setting for a data file will only cause problems), and a `-' means that you are restricted from using a file. Almost always, you want to have `rw-' for your data files, and `rwx' for your programs. The next middle set of three letters describes what members of your group can do. Groups are special constructs you can make which allow members of a team to share files with their own set of access restrictions. Usually, you won't belong to any groups so you should set these permissions to `---'. Finally, the last three letters are by far the most important, as they represent what anyone on the system can do to your files. By default, many machines set permissions to everyone can read the file, even though they cannot edit / delete it or run it as a program. For sensitive information, this is obviously undesirable. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

14 Προστασία των αρχείων -r-- --- --- (400) -rw- --- --- (600)
-rw- r-- r-- (644) -rw- rw- rw- (666) dr-x r-x r-x (555) dr-x (500) drwx (700) drwx r-x r-x (755) drwx rwx rwx (777) ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

15 Μεταβολή των αδειών πρόσβασης
chmod permission files Μέθοδος χαρακτήρων $ chmod a=r-x file $ chmod u=rw- file $ chmod ugo+r file $ chmod go-w file Αριθμητική μέθοδος $ chmod 744 file $ chmod 600 file ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

16 Permission Settings Permission settings με χρήση οκταδικών αριθμών.
w = 010 = 2 x = 001 = 1 None = 000 = 0 Οι αριθμοί μπορούν να προστίθενται. rwx = 7 ( ) = 111 rw = 6 (4 + 2) = 110 rx = 5 (4 + 1) = 101 ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

17 Default Permissions Κάθε φορά που ένα directory ή file δημιουργείται πρέπει να αποκτά άμεσα άδειες πρόσβασης συνήθως 644 για αρχεία, 755 για directories Χρησιμοποιείται η εντολή umask $ umask ddd ddd είναι ένας τριψήφιος οκταδικός αριθμός παράδειγμα $ chmod owner:rw group:r other:r (typical dir) $ chmod owner.rwx group:rx other:rx (typical file) ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

18 Αριθμητικές άδειες πρόσβασης
-rwxrwxrwx -rwxr-xr-x -rw-r--r-- -r owner 111 group others 777 101 111 755 100 110 644 000 100 400 An access permission looks something like this : file/directory? user group others d/ rwx rwx rwx How to Set Numerical Access Permissions Numerical access permissions are set using octal numbers. An octal number, which is made up of three components (r, w, and x), has a value of 0 to 7. For this reason the three access types (r, w, and x) are linked to an octal value, so that when all values are added together they are between 0 and 7 (inclusive). Below are the values : r = 4 , w = 2 , x = 1 , Total = 7 This is the same for each of the three user types (u, g , and o). Below is a listing showing which numbers are used to set the required access state :- = No access permission --x = Execute permission only. -w = Write permission only. -wx 3 = Write and Execute permission (2 + 1). r = Read permission only. r-x = Read and Executeute permission (4 + 1). rw = Read and Write permission (4 + 2). rwx = Read, Write and Execute permission ( ) ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

19 The SuperUser Κάθε σύστημα Unix έχει ένα τουλάχιστον userid με ξεχωριστή σημασία Αυτό αναφέρεται συνήθως ως root αν και το όνομα μπορεί να είναι διαφορετικό Ο root έχει τη δυνατότητα πρόσβασης σε όλα τα αρχεία και τους καταλόγους, ανεξάρτητα των δικαιωμάτων και των αδειών πρόσβασης ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

20 Η εντολή umask Κατά τη δημιουργία ενός νέου αρχείου, το ΛΣ πρέπει να αποφασίσει ποια bits προστασίας θα παραχωρήσει εξ αρχής σε αυτό. Η ρύθμιση αυτή αποφασίζεται από την τιμή της umask. Η τιμή umask ρυθμίζεται για κάθε χρήστη από τις ρυθμίσεις που υπάρχουν στα αρχεία αρχικοποίησης του χρήστη (.profile για Bourne shell ή ;login για C shell), κατά τη διαδικασία εισόδου του χρήστη στο σύστημα, π.χ. umask 077 umask 022 ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

21 Θέτοντας τις εξ ορισμού άδειες πρόσβασης μέσω της εντολής umask
Κάθε φορά που δημιουργούνται files ή directories, τους ανατίθενται οι εξ ορισμού ρυθμίσεις για τις άδειες πρόσβασης. Αυτές οι εξ ορισμού ρυθμίσεις αποδίδονται καταρχήν είτε από το ΛΣ είτε από τα προγράμματα αρχικοποίησης που εκτελούνται κατά την εκκίνηση κάθε λογαριασμού. Ο καθορισμός των εξ ορισμού αδειών ή δικαιωμάτων πρόσβασης (default permissions) απαλλάσσει τους χρήστες από τη διαδικασία ρητού καθορισμού των δικαιωμάτων κάθε φορά που δημιουργούν ένα file ή directory. Το ΛΣ παραχωρεί τις εξ ορισμού τιμές (default permission values) 777 στα εκτελέσιμα αρχεία και 666 σε όλα τα άλλα αρχεία. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

22 Αν είναι επιθυμητός ένας περαιτέρω περιορισμός αυτών των δικαιωμάτων κατά τη δημιουργία αρχείων και καταλόγων, πρέπει να οριστεί μια καθορισμένη μάσκα δικαιωμάτων χρήστη (user mask) μέσω της εντολής umask. Η μάσκα χρήστη είναι μια αριθμητική τιμή που αποφασίζει τα δικαιώματα πρόσβασης όταν δημιουργείται ένα αρχείο ή ένας κατάλογος. Τα δικαιώματα που προκύπτουν ως αποτέλεσμα της umask είναι όσα απομένουν μετά την αφαίρεση αυτών που προσδιορίζει η τιμή της umask. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

23 Default File Protections (umask)
Η εξ ορισμού (default) τιμή των αδειών πρόσβασης στα αρχεία που δημιουργεί ένας χρήστης καθορίζεται από τη χρήση της εντολής umask στο αρχείο αρχικοποίησης. Το όνομα του αρχείου αυτού εξαρτάται από το πρόγραμμα φλοιού που εκτελείται κάθε φορά. Σύνταξη της εντολής: umask ugo Οι καταστάσεις πρόσβασης που προσδιορίζονται με την εντολή umask αποτελούν το συμπλήρωμα της εντολής chmod. Η εντολή umask προσδιορίζει εκείνα τα δικαιώματα πρόσβασης που δεν είναι επιθυμητά να υπάρχουν, π.χ. Η αφαίρεση του δικαιώματος write για group και others, προσδιορίζεται με την τιμή umask 022 Η αφαίρεση όλων των δικαιωμάτων για group και others, προσδιορίζεται με την τιμή 077 ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

24 Setting Default Access Permissions
Η εντολή umask ρυθμίζει μια μάσκα που περιορίζει τις άδειες πρόσβασης που εκχωρούνται σε νέα αρχεία. Για την εμφάνιση της τρέχουσας τιμής της umask, πρέπει να εισάγετε απλά το όνομα της εντολής δηλ. umask. Οι τιμές της umask είναι τα συμπληρώματα των τιμών της chmod : 1 αφαιρεί το δικαίωμα execute , 2 αφαιρεί το δικαίωμα access, και 4 αφαιρεί το δικαίωμα read . Όπως και στην εντολή chmod οι τιμές για την umask μπορούν να συνδυασθούν π.χ.. Η τιμή 7 (=4+2+1) αφαιρεί όλα τα δικαιώματα πρόσβασης. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

25 Παράδειγμα Η απόδοση των αδειών πρόσβασης : Θα γίνει με την εντολή:
στον ιδιοκτήτη (owner) read, write, and execute (0 περιορισμοί) για όλα τα νέα αρχεία, Η αφαίρεση του δικαιώματος write (2) από το group (είναι ισοδύναμο με την παραχώρηση των δικαιωμάτων read και execute), και Η αφαίρεση των δικαιωμάτων read και write (2+4=6) από τους υπόλοιπους (other) (είναι ισοδύναμο με την παραχώρηση του execute μόνον) Θα γίνει με την εντολή: umask 026 Παρατήρηση: Η τιμή 026 είναι το συμπλήρωμα της τιμής751 ( =751) που χρησιμοποιεί η εντολή chmod. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

26 Η default τιμή για αρχεία (files) είναι: -rw-r--r-- ή 644 (=666-022)
Σύμφωνα με την τεκμηρίωση του UNIX οι εξ ορισμού τιμές της umask είναι 666 για τα files και 777 για τα directories. Συνήθως στο περιβάλλον UNIX τα αρχεία αρχικοποίησης θέτουν την τιμή της umask 022 οπότε: Η default τιμή για αρχεία (files) είναι: -rw-r--r-- ή (= ) Η default τιμή για καταλόγους (directories) είναι: drwxr-xr-x ή (= ) ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

27 umask – τιμές και οι αντίστοιχες άδειες πρόσβασης σε νέα αρχεία
FILES DIRECTORIES Value Permissions Value Permissions 0 rw rwx 1 rw rw- 2 r r-x 3 r r-- 4 -w wx 5 -w w- x Η umask δεν ενεργοποιεί το δικαίωμα execute για τα αρχεία ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

28 Παραδείγματα Η εντολή umask 2 ή umask 002 δίνει: -rw-rw-r-- (files)
drwxrwxr-x (directories) Η εντολή umask 22 δίνει: -rw-r--r-- (files) drwxr-xr-x (directories) ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

29 umask umask Value Default File Mode Default Directory Mode 077
600 (rw———-) 700 (rwx———) 067 710 (rwx—x—-) 066 711 (rwx—x—x) 027 640 (rw-r——-) 750 (rwxr-xr-x) 022 644 (rw-r—r—) 755 (rwxr-xr-x) 000 666 (rw-rw-rw-) 777 (rwxrwxrwx) For files permission string is 666 – umask For directories permissions string is umask ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

30 Η εντολή chmod Η εντολή chmod αλλάζει τις άδειες πρόσβασης ενός ή περισσοτέρων αρχείων. Μόνον ο ιδιοκτήτης του αρχείου και ο superuser μπορούν να τροποποιήσουν τις άδειες πρόσβασης. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

31 Παραδείγματα # make read/write-able for everyone chmod a+w myfile
# add the 'execute' flag for directory chmod u+x mydir/ # open all files for everyone chmod 755 * # descend recursively into directory opening all files chmod -R a+r dir ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

32 chmod Permission Owner Group Other Read 4 Write 2 - Execute Total 6
ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

33 Παραδείγματα $ chmod 700 directory $ ls -ld directory
drwx fred Jan 6 18:32 directory $ chmod 755 directory drwxr-xr-x 2 fred Jan 6 18:32 directory ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

34 drw------- 2 fred 3234 Jan 6 18:34 filename $ chmod 644 filename
$ ls -l filename drw fred Jan 6 18:34 filename $ chmod 644 filename drwxr-xr-x 2 fred Jan 6 18:34 filename ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

35 Η επιλογή –R της εντολής chmod
Χρησιμοποιείται για την απόδοση δικαιωμάτων σε ολόκληρη την δενδρική δομή που ακολουθεί κάτω από ένα directory π.χ. chmod -R ug+r,o-r,a+X pathname ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

36 Directory Access Permissions
The access permissions associated with directories influence the operations which can be performed on files they contain. The meanings of the directory access permissions are: read allows display of a directory -- read permission is required in order to use ls to list characteristics of files within a directory; otherwise you will receive the message "No permission" following the name of each file in the directory. execute enables access to the contents of a directory -- execute permission is required in order to cd into a directory or to access (execute or examine) any of the files it contains. Without execute permission, you will typically receive the message "Permission Denied". write enables creation, deletion, and moving of files within the directory. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

37 Thus deletion of a file is limited by the permission associated with the directory and not by the individual file access permissions. Be careful to whom you provide directory write access permissions. They will not be allowed to modify the file if they do not have file write access permission, but they can remove it if they have directory write permission. If you wish to share files with others, you need to be sure that both the permissions for the file and the directory containing it are set appropriately. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

38 Making programs executable
A UNIX program is normally executed by typing its pathname. If the x execute bit is not set on the file, this will generate a `Permission denied' error. This protects the system from interpreting nonsense files as programs. To make a program executable for someone, you must therefore ensure that they can execute the file, using a command like chmod u+x filename This command would set execute permissions for the owner of the file; chmod ug+x filename would set execute permissions for the owner and for any users in the same group as the file. Note that script programs must also be readable in order to be executable, since the shell has the interpret them by reading. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

39 Εντολές για την εμφάνιση και επεξεργασία αρχείων
Listing files cat head tail Listing files page per page more less Editing files vi pico ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

40 Χειρισμός αρχείων copy move (rename) remove (delete) cp mv rm
ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

41 Ανακατεύθυνση εισόδου / εξόδου (Input/Output Redirection)
Συνήθως τα προγράμματα διαβάζουν από το πληκτρολόγιο και γράφουν τα αποτελέσματα και τα μηνύματα λάθους στην οθόνη. Κάθε εκτελούμενο πρόγραμμα ανοίγει τρία αρχεία: standard input, standard output, and standard error που συσχετίζονται με το πληκτρολόγιο, την οθόνη και την οθόνη αντίστοιχα. Η είσοδος μπορεί να γίνει απευθείας από ένα αρχείο χρησιμοποιώντας τα σύμβολα “<“ και “<<“. Η έξοδος μπορεί να κατευθυνθεί σε ένα αρχείο χρησιμοποιώντας τα σύμβολα “>“ και “>>“. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

42 Τυπική εντολή Unix                                                                                                  ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

43 Διασωλήνωση (Piping) και φιλτράρισμα (Filtering)
παράδειγμα $ ls /etc > list.temp $ more list.temp $ rm list.temp Συγκρίνετε τα αποτελέσματα με $ ls /etc | more Διασωλήνωση (Piping) Κατευθύνει την έξοδο μιας εντολής στην είσοδο μιας άλλης Σύμβολο διασωλήνωσης “|”. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

44 Pipeline process: who | wc -l
ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

45 Εντολές - φίλτρα more file head file tail file sort file uniq file
types a file's contents, one screen or line at a time head file types the first 10 lines of a file tail file types the last 10 lines of a file sort file sorts lines of file into alphabetical order uniq file eliminates all adjacent duplicate lines wc file counts lines, words, characters in a file ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

46 UNIX: Multi-user Multi-tasking
Περισσότεροι από ένας χρήστες μπορούν «να τρέχουν» προγράμματα την ίδια χρονική στιγμή και περισσότερες από μια διεργασίες μπορούν να εκτελούνται την ίδια χρονική στιγμή. Το Unix είναι ένα Λ.Σ. multiuser & multitasking. Στο Unix, κάθε πρόγραμμα ξεκινά ως μια διεργασία. Μια διεργασία είναι ένα πρόγραμμα σε εκτέλεση. Μπορούν να υπάρχουν πολλές διεργασίες που εκτελούν το ίδιο πρόγραμμα (π.χ. έναν editor). Για κάθε χρήστη που αλληλεπιδρά με το σύστημα: Μόνον μια διεργασία βρίσκεται στο προσκήνιο (foreground) Μπορούν να υπάρχουν αρκετές διεργασίες στο παρασκήνιο (background) ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

47 Διεργασίες inetd kernel Process 0: Kernel bootstrap. Start process 1.
kernal mode user mode Process 1: create processes to allow login. /etc/init fork exec fork exec inetd lpd /etc/getty /etc/getty condition terminal for login httpd exec exec /bin/login /bin/login check password exec exec At start up time, process 0 launched in the kernel mode (boot) Process0 starts process1 in the user model (manual transfer of control. Process 1 starts other processes (fork system call). Each time a command/program is executed, the shell forks a new process for it. shell shell command interpreter ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

48 Multi-tasking Time sharing: πολλές διεργασίες εκτελούνται «εικονικά» την ίδια στιγμή. Κάθε διεργασία έχει έναν αριθμό ταυτότητας διεργασίας (process identification number – PID) Εντολές για την εμφάνιση των διεργασιών $ ps $ ps -ef ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

49 Διεργασίες προσκηνίου και παρασκηνίου (Background & Foreground Processes)
Μία κάθε στιγμή $ sleep -60 Κλειδώνει το τερματικό μέχρι να ολοκληρωθεί Background processes Μία ή περισσότερες μπορούν να εκτελούνται την ίδια χρονική στιγμή στο παρασκήνιο Αποδεσμεύουν το τερματικό $ sleep -60 & $ sleep -60 Ctrl-z $ bg ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

50 Ακύρωση / διακοπή διεργασιών
Ακύρωση μιας διεργασίας που εκτελείται στο προσκήνιο Ctrl-c Σκοτώνοντας (Killing) μια διεργασία παρασκηνίου $ kill pid - get the pid using ps command $ kill -9 pid ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

51 Ειδικοί χαρακτήρες | < > ;
Διασωληνώνει την έξοδο μιας εντολής ως είσοδο μιας άλλης εντολής. Για παράδειγμα ls -al |more < Ανακατευθύνει την είσοδο μιας εντολής. Για παράδειγμα , sort <in_file > Ανακατευθύνει την έξοδο μιας εντολής. Για παράδειγμα , ls > dir_list ; Χρησιμοποιείται για τον διαχωρισμό εντολών στην ίδια γραμμή. Για παράδειγμα , ls -l | more; cat file1 ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

52 Process Monitoring The ps Command Syntax: ps [options]
The ps command is a general utility for checking process status. It reports information such as current percentage of the CPU being used by processes, percent of memory, accumulated CPU time, and other statistics. It is not a real-time display, but takes a snapshot of the system. Syntax: ps [options] The ps command specified by itself will display your current processes. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

53 Παράδειγμα UID PID PPID STIME TTY TIME CMD
root Mar 18 ? 0:03 /usr/sbin/inetd -s root Mar 18 ? 0:02 /usr/sbin/vold smith :02:31 pts/4 0:01 /usr/local/csh jones :12:30 pts/8 0:00 -csh smith :09:25 pts/2 0:14 emacs NILS.c brown :53:33 pts/7 0:00 idt -soft ppi-cesar.cgm ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02

54 The columns and information displayed varies between architectures.
Column Description UID User ID of process PID Process id number PPID Process ID of parent process STIME Starting time of process TTY Controlling terminal of process, ? when no controlling terminal TIME Cumulative execution time for the process CMD Command name The columns and information displayed varies between architectures. ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΙΙ – ΕΡΓΑΣΤΗΡΙΟ - 02


Κατέβασμα ppt "Σύστημα αρχείων του UNIX, Διασωλήνωση, Άδειες πρόσβασης, ο editor vi"

Παρόμοιες παρουσιάσεις


Διαφημίσεις Google