Module 3
Module 3
Module 3
Agenda – Activity 1
Introduction to the Unix File System
Unix file system
File Types
Directory File Paths
Access Permissions
Demonstration of file system
Agenda – Activity 2
UNIX Commands
Navigating the File System:
pwd, ls, touch, cd
Demonstration of pwd, ls, touch, and cd
Working With Files:
cp, mv, rm, mkdir, rmdir
Demonstration of cp, mv, rm, mkdir, rmdir
Agenda – Activity 2 Continued
vi Editor
Introduction to the vi editor
Practice with the editor
Preview of next week
Activity 1
The Unix File System
Everything is
a File in Unix
Types of Unix Files
There are Three Types of Files:
Ordinary / Regular Files
Directories
Special Files – Internal representation of a
physical device (keyboard, printer,
terminal)
The Tree-Structured File System
root (/)
$HOME variable
Shows your current home directory
print $HOME - display variable setting
Unix Directories
Present Working Directory
Your current location
-or-
Current Directory
Unix Commands: pwd
Use pwd to display the name of your
current working directory
/export/home/morris07/> pwd
Present Working Directory
Absolute Path
Absolute Path
/export/home/morris07/labs
/export/home/morris07/>
cd {directory name}
Absolute Path
Absolute Path
Relative Path
If your pwd was
/export/home/morris07/
/export/home/morris07/> ls
/export/home/morris07/> ls –l
* (long format)
/export/home/morris07/> ls –la
* (long format, and list all entries including those that
begin with a “.”
Unix Commands: ls
/export/home/morris07/> ls –F
* Flags directories with a “/” and executables with a “*”
Using Wildcards:
* Any string of characters
? Any one character (not space)
[] Match any character in the brackets
Unix Commands: ls
Examples
ls –al ~
Lists your home directory
Activity 2
Unix Commands: touch
Use touch to change a file’s access time and
modification time to the current date
NOTE: If the file does not exist, touch will create a new file
Unix Commands: id
Use id to display your userid and groupid
/export/home/morris07/> id
Unix Commands: id
Unix Security
Login name and a password
Encryption on important files
Access permission
Encryption of files
Text page 334
crypt
Description will make more sense after
next week
Requires a key – do not forget the key
Access Permissions
Ordinary File
Read: you can read from the file
Write: you can write to the file
Execute: you can execute the file key
Directory Permissions
Directory
Read
You can read the directory
Write
You can create, move, copy or remove
directory contents
Execute:
You can search the directory
How Permissions are Managed
There are three Permission Groups:
Owner:
Owner’s Group:
Everyone Else/Other:
Permissions
-rwxrwxrwx 1 morris07 student 512 Jan 12 14:07 file.exe
-rw-rw- rw- 1 morris07 student 812 Jan 12 14:22 file.name
drw-rw-rw- 1 morris07 student 812 Jan 12 14:22 labs
-----------------------------------------------------------------------------------------
r read permission
w write permission
x execute permission
- permission not granted
-----------------------------------------------------------------------------------------
owner group everybody At the far left, 1’st character
rwx rwx rwx shows type of file. “-” ordinary
“d” is directory
Unix Commands: chmod
Use chmod to change the file-access
permissions on an existing file
/export/home/morris07/> umask
cp file1 ~/newdir/junk1
Copies the file1 to your home directory in the
> rm {file(s)}
vi is a “right-handed” editor
> vi {file}
Hint: If you forget which mode you are in, hit the
<Esc> key twice to get to Command Mode.
ra
* Replaces the current character with “a”
Rnew stuff
* Replaces the text at cursor with “new stuff”
3yy
* Copies (yanks) 3 lines
p
* would paste the previously yanked lines at the current
cursor position!
The vi Editor: Cut and Paste
dd deletes a line (puts it in the buffer)
p pastes data, after/below cursor
dd
*Cuts
p
*Pastes
The vi Editor: Searching
/{pattern} searches forwards for pattern in file
/<Return> repeats forward search for pattern
?{pattern} searches backwards for pattern in file
?<Return> repeats backward search for pattern
You can automatically tell “vi” to let it break a line into two when it
gets within “n” characters of the right margin. To have “vi” break
your lines automatically when they get within 6 characters of the
right margin, use the following command in “vi” (command mode):
:set wrapmargin=6
or
:set wm=6
The vi Editor: Bonus
This is especially helpful when you are typing a
long paragraphs and don’t want it to be one
continuous line.
If you don’t want to have to enter this “vi”
command every time you enter “vi”, you can
put it in the .exrc file. This file, created by you,
belongs in your home directory. “vi” will read
and execute any commands that it finds in this
file upon startup.
In the .exrc file you don’t need to start any
commands with a colon (:).
The vi Editor: Bonus
~ (tilde) changes the case of the
current position