Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 48

CHAPTER 1

UNIX FOR
NONPROGRAMMERS
By Uur Halc
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
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
CREATING A FILE
Use editors vi, emacs, pico or the cat command







$ cat >myfile # $ is system prompt






3
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
CREATING A FILE
Use editors vi, emacs, pico or the cat command







$ cat >myfile # $ is system prompt
Ali
Ahmet
Can
^D
$

^D is used to
indicate end
of input
5
CREATING A FILE
Use editors vi, emacs, pico or the cat command







$ 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

6
CREATING A FILE
Use editors vi, emacs, pico or the cat command







$ cat >myfile # $ is system prompt
Ali
Ahmet
Can
^D
$

7
home 122
halici
myfile
Current
directory
Ali
Ahmet
Can
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
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
9
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
file type and
permissions
# of links
owner
date length
file name
time
10
file type and permissions

-


r w -

r - -

r - -

file
type

permissions
for
owner

permissions
for
group

permissions
for
others

11
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
$

12
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
RENAMING A FILE : mv

$ mv myfile myNewFile
$ ls
myNewFile
$ cat myNewFile
Ali
Ahmet
Can
$

14
home 122
halici
myfile myNewfile
Current
directory
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 newDirectoryName

15
halici
myNewfile class
Current
directory
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 newDirectoryName

16
halici
myNewfile class
myNewfile
Current
directory
MOVING TO A DIRECTORY: cd, chdir


$ pwd # print working directory
/home122/halici






mkdir newDirectoryName

17
halici
class
myNewfile
Current
directory
MOVING TO A DIRECTORY: cd, chdir

$ pwd # print working directory
/home122/halici
$ cd class
$ pwd
/home122/halici/class
$

mkdir newDirectoryName

18
halici
class
myNewfile
Current
directory
COPYING A FILE : cp

$ 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
mySecondfil
e
DELETING A DIRECTORY: rmdir

$ pwd
/home122/halici/class











20
halici
class
myNewfile
Current
directory
mySecondfil
e
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
$



21
halici
class
myNewfile
Current
directory
mySecondfil
e
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
$



An error message by the system is
displayed. The directory is not deleted
since it is not empty

22
halici
class
myNewfile
Current
directory
mySecondfil
e
DELETING A FILE : rm
$ 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
mySecondfil
e
DELETING A FILE : rm
$ 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
mySecondfil
e
DELETING A FILE : rm
$ 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
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



26
COUTING WORDS IN FILE: wc
$ wc w myclass
3
$ wc c myclass
14
$ wc myclass



wc -lwc {filename}*

options:
l: lines,
w:words,

27
myclass
Ali
Ahmet
Can
COUTING WORDS IN FILE: wc
$ 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
COUTING WORDS IN FILE: wc
$ 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
COUTING WORDS IN FILE: wc
$ 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


w


c

30
myclass
Ali
Ahmet
Can
FILE TYPES
- regular file
d directory file
b buffered special file (such as disk drive)
c unbuffered special file (such as disk terminal)
l symbolic link
p pipe
s socket
31
FILE PERMISSIONS

r w


r - -

r - -

user


group

others
32
FILE PERMISSIONS
regular file directory special 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
CHANGING FILES PERMISSIONS:
chmod
chmod R change{,change}* filename
+


R: recursively change modes if filename is a directory









Change:
cluster selection operation new permission
u (user) + (add) r (read)
g (group) - (remove) w (write)
o (others) = (assign) x (execute)
a (all)
34
CHANGING FILES PERMISSIONS:
chmod
Examples for change{,change}*

g+w add group write permission
u-wx remove user write and execute permissions
o+x add others execute permission
u+w,g-r add write permission for user and
remove read permission from group
g=r give group just read permission

35
CHANGING FILES 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
36
CHANGING FILES PERMISSIONS:
chmod
The chmod utility allows you to specify the new
permission setting of a file as an octal number

user group others
rwx rwx rwx
setting rwx r-x ---
binary 111 101 000
octal 7 5 0
37
CHANGING FILES PERMISSIONS:
chmod







$ chmod 750 myclass
$ ls l myclass
-rwxr-x--- 1 halici 14 April 15 12:05 myclass
$
38
CHANGING FILES PERMISSIONS:
chmod







$ chmod 750 myclass
$ ls l myclass
-rwxr-x--- 1 halici 14 April 15 12:05 myclass
$

Permission is set as desired

39
CHANGING FILES 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

40
CHANGING FILES 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
$

The file is removed ! Deleting a file depends on not on the
files write permission but the write permission of the directory
that contains it (ie udating the content of the directory)

41
GROUPS
Suppose that I am a member of the group ee







$ ls lg myfile




42
GROUPS
Suppose that I am a member of the group ee







$ ls lg myfile




option g stands for listing
also files group
43
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



Group information
44
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 group
ee

45
Group information
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 group
ee

46
Group information
CHANGING FILES 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

47

You might also like