970 likes | 1.18k Views
COMP 104: Intro to Unix. Week 2. Review of Last Week. History of Unix Unix design philosophy The Unix shell, variables and options Unix commands: alias, cat, date, echo, exit, finger, hostname, login, lp, ls, man, more, passwd, set, setenv, uname, wc, whatis, whereis, who, whoami.
E N D
COMP 104: Intro to Unix Week 2
Review of Last Week • History of Unix • Unix design philosophy • The Unix shell, variables and options • Unix commands: alias, cat, date, echo, exit, finger, hostname, login, lp, ls, man, more, passwd, set, setenv, uname, wc, whatis, whereis, who, whoami
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 • More UNIX Commands • File Permissions: • id, umask, chmod • Demonstration of id, umask, chmod • In class assignment • Break (10 minutes)
Agenda – Activity 3 • vi Editor • Introduction to the vi editor • Practice with the editor • Preview of next week
The Unix File System Everything is aFile 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 (/) bin dev etc lib lost+found sys tmp usr bin games lib local spool
Another Example The following directory tree, and files are located under /export/home/smith/comp110 |_[assignment1] | \_assign1-1.doc | |_[assignment2] | \_assign2-1.doc | |_[lab1] \_[doc] | \_bubblesort.man | |_[report] | \_lab1.report | |_[source] \_sort.cpp sort.o
Common Unix Directories /bin stores basic Unix programs /dev contains files that represent devices /etc files for managing the system /lib contains libraries of programs /lost+found contains ‘misplaced’ files /sys contains system source files /tmp temporary storage /usr important directory – contains many things
Unix Directories Root Directory / Your Home Directory /export/home/{userid} $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
Absolute Path Absolute Path /export/home/morris07/labs NOTE: These always start with a “/” from root.
Unix Commands: cd Use cd to change your working directory /export/home/morris07/> cd {directory name}
Relative Path If your pwd was /export/home/morris07/ You could do: cd examples To move into the examples subdirectory
Relative Path (Shorthand) Single dot . Your current directory Double dot .. Your parent directory cd . Takes you to where already are! cd .. Takes you to the pwd’s parent directory. cd ~Takes you to your home directory cd - Takes you to the previous directory
Unix Commands: ls Use ls to list the contents of a directory /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 *.c Lists all files ending with ‘.c’ ls file? Lists any file with file and one character at the end ls v[6,7]file Lists v6file and v7file
Using Relative Path in ls • ls -al .. Lists your parent directory • ls –al ~ Lists your home directory
Unix Commands: touch Use touch to change a file’s access time and modification time to the current date /export/home/morris07/>touch {file name} 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 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 ----------------------------------------------------------------------------------------- ownergroupeverybody 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 >chmod{mode} {file} >chmod777 file.name
Numeric Value of Permissions FILE MODE, or MODE read permission = 4 write permission = 2 execute permission = 1 no permission = 0 To calculate the proper permissions you want to assign, simply add the numbers together: read + write + execute = 4 + 2 + 1 = 7 read + write = 4 + 2 = 6 …
chmod: Calculating the Mode Number Meaning 400 Owner has read permission 200 Owner has write permission 100 Owner has execute permission 040 Group has read permission 020 Group has write permission 010 Group has execute permission 004 Everyone else has read permission 002 Everyone else has write permission 001 Everyone else has execute permission -------- 777
Numeric Value of Permissions chmod 777 lab1 Allows rwx to everyone! chmod 755 lab1 Allows rwx to user, and rx to group/others. Or to deny group and others rwx permissions: chmod 700 lab1
Symbolic-Mode File Permissions Letters represent the groups and permissions: u = User, g = Group, o = Others + or – To add or remove a permission from: r = Read, w = Write, x = Execute chmod ugo+rwx lab1 Allows rwx to everyone! Or to deny group and others rwx permissions: chmod go-rwx lab1