Download presentation
Presentation is loading. Please wait.
Published byAlexina Nash Modified over 9 years ago
1
CHAPTER 1 UNIX FOR NONPROGRAMMERS By U ğ ur Halıcı
2
Unix for non programmers When you connected via terminal to a machine running Unix, you will have a window to enter you commands $ $ system prompt Terminal window Enter your command here 1
3
MANUAL The man command is used to display the manual entry associated with word entered as argument. The -k option is used to display a list of manual entries that contain entered keyword. man [chapter] word man -k keyword 2
4
CREATING A FILE Use editors vi, emacs, pico or the cat command $ cat >myfile # $ is system prompt 3
5
CREATING A FILE Use editors vi, emacs, pico or the cat command $ cat >myfile # $ is system prompt all characters that follow up # to a new line are comment command output redirection 4
6
CREATING A FILE Use editors vi, emacs, pico or the cat command $ cat >myfile # $ is system prompt Ali Ahmet Can ^D $ $ cat >myfile # $ is system prompt Ali Ahmet Can ^D $ ^D is used to indicate end of input 5
7
CREATING A FILE Use editors vi, emacs, pico or the cat command $ cat >myfile # $ is system prompt Ali Ahmet Can ^D $ $ cat >myfile # $ is system prompt Ali Ahmet Can ^D $ system prompt appears to enter a new command A file with name “myfile” is created whose content is : Ali Ahmet Can A file with name “myfile” is created whose content is : Ali Ahmet Can 6
8
CREATING A FILE Use editors vi, emacs, pico or the cat command $ cat >myfile # $ is system prompt Ali Ahmet Can ^D $ $ cat >myfile # $ is system prompt Ali Ahmet Can ^D $ 7 home 122 halici myfile Current directory Ali Ahmet Can Ali Ahmet Can
9
LISTING THE CONTENTS OF A DIRECTOTY : ls ls –adglR {filename}* {directoryname}* note: * means zero or more and + means one or more Options are: a : list also hidden files, i.e. the filenames starting with. d : directories g : include info about file group l : long listing R: recursively list the contents of subdirectories 8
10
LISTING THE CONTENTS OF A DIRECTOTY : ls $ ls myfile $ ls –l myfile r w - r - - r - - 1 halici 14 April 15 11:41 myfile $ ls myfile $ ls –l myfile - r w - r - - r - - 1 halici 14 April 15 11:41 myfile $ ls myfile $ ls –l myfile - r w - r - - r - - 1 halici 14 April 15 11:41 myfile 9
11
LISTING THE CONTENTS OF A DIRECTOTY : ls $ ls myfile $ ls –l myfile r w - r - - r - - 1 halici 14 April 15 11:41 myfile $ ls myfile $ ls –l myfile - r w - r - - r - - 1 halici 14 April 15 11:41 myfile $ ls myfile $ ls –l myfile - r w - r - - r - - 1 halici 14 April 15 11:41 myfile file type and permissions # of links owner date length file name time 10
12
file type and permissions -r w -r - - file type permissions for owner permissions for group permissions for others 11
13
LISTING A FILE: cat/more/page/head/tail cat: concatanate more, page: to display in parts without scroll head: first n lines, for default n=10 tail: last n lines, for default n=10 $ cat myfile Ali Ahmet Can $ head -2 myfile Ali Ahmet $ tail -2 myfile Ahmet Can $ $ cat myfile Ali Ahmet Can $ head -2 myfile Ali Ahmet $ tail -2 myfile Ahmet Can $ 12
14
RENAMING A FILE : mv mv –i oldFile newFile mv –i {file name}* directoryName mv –i oldDirectory newDirectory The mv command in the first form renames oldFile as newFile. The second form moves collection files to a directory. The last form is used to move the files in oldDirectoty to newDirectory. The option -i prompts confirmation if newFileName already exists 13
15
RENAMING A FILE : mv $ mv myfile myNewFile $ ls myNewFile $ cat myNewFile Ali Ahmet Can $ $ mv myfile myNewFile $ ls myNewFile $ cat myNewFile Ali Ahmet Can $ 14 home 122 halici myfile myNewfile Current directory
16
MAKING A DIRECTORY: mkdir $ mkdir class $ ls –l -rw-r--r-- 1 halici 14 April 15 11:41 myNewFile drwxr-xr-x 2 halici 512 April 15 11:50 class/ $ mkdir class $ ls –l -rw-r--r-- 1 halici 14 April 15 11:41 myNewFile drwxr-xr-x 2 halici 512 April 15 11:50 class/ mkdir newDirectoryName 15 halici myNewfile class Current directory
17
MAKING A DIRECTORY: mkdir $ mkdir class $ ls –l -rw-r--r-- 1 halici 14 April 15 11:41 myNewFile drwxr-xr-x 2 halici 512 April 15 11:50 class/ $ mv myNewFile class $ ls class $ ls class myNewFile $ ls –R class class: myNewFile $ mkdir class $ ls –l -rw-r--r-- 1 halici 14 April 15 11:41 myNewFile drwxr-xr-x 2 halici 512 April 15 11:50 class/ $ mv myNewFile class $ ls class $ ls class myNewFile $ ls –R class class: myNewFile mkdir newDirectoryName 16 halici myNewfile class myNewfile Current directory
18
MOVING TO A DIRECTORY: cd, chdir $ pwd # print working directory /home122/halici $ pwd # print working directory /home122/halici mkdir newDirectoryName 17 halici class myNewfile Current directory
19
MOVING TO A DIRECTORY: cd, chdir $ pwd # print working directory /home122/halici $ cd class $ pwd /home122/halici/class $ $ pwd # print working directory /home122/halici $ cd class $ pwd /home122/halici/class $ mkdir newDirectoryName 18 halici class myNewfile Current directory
20
COPYING A FILE : cp $ cp myNewFile mySecondFile $ ls myNewFile mySecondFile $ $ cp myNewFile mySecondFile $ ls myNewFile mySecondFile $ cp –i oldFileName newFileName cp –ir {file name}* directoryName options: i: confirm r: recursively copy subdirectories 19 halici class myNewfile Current directory mySecondfile
21
DELETING A DIRECTORY: rmdir $ pwd /home122/halici/class $ pwd /home122/halici/class 20 halici class myNewfile Current directory mySecondfile
22
DELETING A DIRECTORY: rmdir $ pwd / home122/halici/class $ cd.. # change to parent directory $ pwd / home122/halici $ ls class $ rmdir class rmdir: class: directory not empty $ $ pwd / home122/halici/class $ cd.. # change to parent directory $ pwd / home122/halici $ ls class $ rmdir class rmdir: class: directory not empty $ 21 halici class myNewfile Current directory mySecondfile
23
DELETING A DIRECTORY: rmdir $ pwd / home122/halici/class $ cd.. # change to parent directory $ pwd / home122/halici $ ls class $ rmdir class rmdir: class: directory not empty $ $ pwd / home122/halici/class $ cd.. # change to parent directory $ pwd / home122/halici $ ls class $ rmdir class rmdir: class: directory not empty $ An error message by the system is displayed. The directory is not deleted since it is not empty 22 halici class myNewfile Current directory mySecondfile
24
DELETING A FILE : rm $ ls class $ ls class myNewFile mySecondFile $ ls class $ ls class myNewFile mySecondFile rm –fir {filename}* f: inhibit error messages i: inform each time r: recursivey (if filename is a directory) 23 halici class myNewfile Current directory mySecondfile
25
DELETING A FILE : rm $ ls class $ ls class myNewFile mySecondFile $rm class/* #remove all files in directory class $ls class $ ls class $ ls class myNewFile mySecondFile $rm class/* #remove all files in directory class $ls class rm –fir {filename}* f: inhibit error messages i: inform each time r: recursivey (if filename is a directory) 24 halici class myNewfile Current directory mySecondfile
26
DELETING A FILE : rm $ ls class $ ls class myNewFile mySecondFile $rm class/* #remove all files in directory class $ls class $ $ ls class $ ls class myNewFile mySecondFile $rm class/* #remove all files in directory class $ls class $ rm –fir {filename}* f: inhibit error messages i: inform each time r: recursivey (if filename is a directory) All the files under the directory class are deleted, nothing remains to list by ls 25 halici class Current directory
27
PRINTING A FILE : lpr $ cat >myclass Ali Amet Can ^D $ ls myclass $ cat myclass Ali Amet Can $ lpr myclass # send the content of the file class to printer $ cat >myclass Ali Amet Can ^D $ ls myclass $ cat myclass Ali Amet Can $ lpr myclass # send the content of the file class to printer 26
28
COUTING WORDS IN FILE: wc $ wc –w myclass 3 $ wc –c myclass 14 $ wc myclass $ wc –w myclass 3 $ wc –c myclass 14 $ wc myclass wc -lwc {filename}* options: l: lines, w:words, 27 myclass Ali Ahmet Can Ali Ahmet Can
29
COUTING WORDS IN FILE: wc $ wc –w myclass 3 $ wc –c myclass 14 $ wc myclass $ wc –w myclass 3 $ wc –c myclass 14 $ wc myclass wc -lwc {filename}* options: l: lines, w:words, no option is used, this is equivalent to –lwc all together 28 myclass Ali Ahmet Can Ali Ahmet Can
30
COUTING WORDS IN FILE: wc $ wc –w myclass 3 $ wc –c myclass 14 $ wc myclass 3 3 14 $ $ wc –w myclass 3 $ wc –c myclass 14 $ wc myclass 3 3 14 $ wc -lwc {filename}* options: l: lines, w:words, no option is used, this is equivalent to –lwc all together 29 myclass Ali Ahmet Can Ali Ahmet Can
31
COUTING WORDS IN FILE: wc $ wc –w myclass 3 $ wc –c myclass 14 $ wc myclass 3 3 14 $ $ wc –w myclass 3 $ wc –c myclass 14 $ wc myclass 3 3 14 $ wc -lwc {filename}* options: l: lines, w:words, no option is used, this is equivalent to –lwc all together l l w w c c 30 myclass Ali Ahmet Can Ali Ahmet Can
32
FILE TYPES -regular file ddirectory file bbuffered special file (such as disk drive) cunbuffered special file (such as disk terminal) lsymbolic link ppipe ssocket 31
33
FILE PERMISSIONS r w –r - - usergroupothers 32
34
FILE PERMISSIONS regular filedirectoryspecial file r read The process may read the contents The process can read the directory (i.e. list the names of the files that it contains) The process may read from the file using the read( ) system call w write The process may change the contents The process may add or remove files to/from the directory The process may write to the file using the write( ) system call x execute The process may execute the file (which only makes sense if it is a program) The process may access files in the directory or any of its subdirectories No meaning 33
35
CHANGING FILE’S PERMISSIONS: chmod chmod –R change{,change}* filename + R: recursively change modes if filename is a directory Change: cluster selectionoperationnew permission u (user)+ (add)r (read) g (group)- (remove)w (write) o (others)= (assign)x (execute) a (all) 34
36
CHANGING FILE’S PERMISSIONS: chmod Examples for change{,change}* g+wadd group write permission u-wxremove user write and execute permissions o+xadd others execute permission u+w,g-radd write permission for user and remove read permission from group g=rgive group just read permission 35
37
CHANGING FILE’S PERMISSIONS: chmod $ ls –l myclass -rw-r--r-- 1 halici 14 April 15 12:05 myclass $ chmod o-r myclass # remove read permission from others -rw-r----- 1 halici 14 April 15 12:05 myclass $ ls –l myclass -rw-r--r-- 1 halici 14 April 15 12:05 myclass $ chmod o-r myclass # remove read permission from others -rw-r----- 1 halici 14 April 15 12:05 myclass 36
38
CHANGING FILE’S PERMISSIONS: chmod The chmod utility allows you to specify the new permission setting of a file as an octal number usergroupothers rwx settingrwxr-x--- binary111101000 octal750 37
39
CHANGING FILE’S PERMISSIONS: chmod $ chmod 750 myclass $ ls –l myclass -rwxr-x--- 1 halici 14 April 15 12:05 myclass $ $ chmod 750 myclass $ ls –l myclass -rwxr-x--- 1 halici 14 April 15 12:05 myclass $ 38
40
CHANGING FILE’S PERMISSIONS: chmod $ chmod 750 myclass $ ls –l myclass -rwxr-x--- 1 halici 14 April 15 12:05 myclass $ $ chmod 750 myclass $ ls –l myclass -rwxr-x--- 1 halici 14 April 15 12:05 myclass $ Permission is set as desired 39
41
CHANGING FILE’S PERMISSIONS: chmod $cat >a aaa ^D $ chmod u-w a # remove write permission from user $ ls –l a #see that it is removed -r--r--r-- 1 halici 4 April 15 12:10 a $ rm a #delete the file a $ ls $cat >a aaa ^D $ chmod u-w a # remove write permission from user $ ls –l a #see that it is removed -r--r--r-- 1 halici 4 April 15 12:10 a $ rm a #delete the file a $ ls 40
42
CHANGING FILE’S PERMISSIONS: chmod $cat >a aaa ^D $ chmod u-w a # remove write permission from user $ ls –l a #see that it is removed -r--r--r-- 1 halici 4 April 15 12:10 a $ rm a #delete the file a $ ls $ $cat >a aaa ^D $ chmod u-w a # remove write permission from user $ ls –l a #see that it is removed -r--r--r-- 1 halici 4 April 15 12:10 a $ rm a #delete the file a $ ls $ The file is removed ! Deleting a file depends on not on the file’s write permission but the write permission of the directory that contains it (ie udating the content of the directory) 41
43
GROUPS Suppose that I am a member of the group “ee” $ ls –lg myfile 42
44
GROUPS Suppose that I am a member of the group “ee” $ ls –lg myfile option g stands for listing also file’s group 43
45
GROUPS Suppose that I am a member of the group “ee” $ ls –lg myfile -rw-r--r-- 1 halici 14 ee April 15 12:20 myfile $ ls –lg myfile -rw-r--r-- 1 halici 14 ee April 15 12:20 myfile Group information 44
46
GROUPS Suppose that I am a member of the group “ee” $ ls –lg myfile -rw-r--r-- 1 halici 14 ee April 15 12:20 myfile $ groups #list my groupe $ ls –lg myfile -rw-r--r-- 1 halici 14 ee April 15 12:20 myfile $ groups #list my groupe 45 Group information
47
GROUPS Suppose that I am a member of the group “ee” If I want to be added to a new group, say named “cls”, I should request the system administrator to do it. $ ls –lg myfile -rw-r--r-- 1 halici 14 ee April 15 12:20 myfile $ groups #list my groupe $ ls –lg myfile -rw-r--r-- 1 halici 14 ee April 15 12:20 myfile $ groups #list my groupe 46 Group information
48
CHANGING FILE’S GROUP : chgrp chgrp –R groupId {filename}* R: recursively changes the group of the files in a directory $ ls –lg myfile -rw-r--r-- 1 halici 14 ee April 15 12:20 myfile $ chgrp cls myfile $ ls –lg myfile -rw-r--r-- 1 halici 14 cls April 15 12:20 myfile $ ls –lg myfile -rw-r--r-- 1 halici 14 ee April 15 12:20 myfile $ chgrp cls myfile $ ls –lg myfile -rw-r--r-- 1 halici 14 cls April 15 12:20 myfile 47
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.