230 likes | 427 Views
Basic UNIX. McGraw Hill 2000. All rights reserved. Introduction. UNIX is an operating system UNIX has 3 main parts: Kernel - manages hardware resources like terminals and printers File System - accesses files; tree structured Shell - interacts with users UNIX is interactive
E N D
Basic UNIX • McGraw Hill 2000. All rights reserved.
Introduction • UNIX is an operating system • UNIX has 3 main parts: • Kernel - manages hardware resources like terminals and printers • File System - accesses files; tree structured • Shell - interacts with users • UNIX is interactive • UNIX is multi-tasking • UNIX is multi-user
System Prompt • % or $ or computername> • System prompt indicates that system is waiting for a command • Enter commands at the prompt: • %pine %menu • %date %who • %help %whoami • %cal %cal arg (arg = year) • %man arg (arg = command name) • Note: UNIX commands are case sensitive!
File System • File is a container for data • 3 kinds of files: Directories (like folders) • Container for files and other directories • Sub-directory is a directory contained within another directory Ordinary files Special files
File Structure • Directories and files are organized in a tree-like hierarchy • Directory at the top is known as the root directory and is represented as a / • Some standard subdirectories under the root directory are etc, usr, and tmp
UNIX Tree-like Hierarchy • root • / • mnt • n • bin • tmp_mnt • m • Full pathname: • /n/m/37/ehepp • 00 • 37 • 39 • ehepp • hdb • jrp
Home Directory • “Home” directory is where you find yourself when you log in • To print the name of the directory you are in: • %pwd (print working directory) • Shows the “full pathname” • eg. /n/m/37/ehepp
Pathnames • A pathname is the concatenation of the directories you traverse to reach a file • A relative pathname is the concatenation of the directory names from where you are currently “located” in the file hierarchy • A full pathname specifies the complete path traversed starting with the root (also called an absolute pathname)
File and Directory Organization • You can create and maintain files and directories in your home directory • Use subdirectories to organize files • Use the mkdir command to create a subdirectory: • %mkdir myCS403stuff • New subdirectory will be be created in current directory (also called working directory)
Moving Through the File Structure Using the cd command • cd is the change directory command • Specify a directory name as an argument to cd command to move to that directory within the current directory • %cd myCS403stuff • Specify a full pathname as an argument to change directories • %cd /n/m/37/ehepp/myCS403stuff
cd Command (continued) • %cd or %cd ~ will put you in your home directory: • %cd • %pwd /n/m/37/ehepp • To move up one one level in a directory hierarchy, follow the cd command with two dots: • %cd .. • %pwd /n/m/37
Rename a file (move) %mv index.html index.old Delete a file (remove) %rm -i mystuff.txt Look at contents of a file %more index.html Copy a file %cp -i index.html index.bkup Create a file %pico myfile.html Update a file %pico myfile.html File Manipulation
Other UNIX Commands • List a directory’s contents • %ls • List a directory’s contents in the “long form” • %ls -l • List a directory’s contents including hidden files • %ls -a • Remove a directory • %rmdir myCS403stuff
File Permissions • Permissions provide a measure of security by establishing who is able to access what files and directories, and how they can be accessed • File and directory permissions can be displayed using the ls -l command %ls -l -r--r--r-- 1 marymc Spanish 167 Jul 27 08:15 file.txt
Permission Codes • 3 identifiers specify who can access the file: • User who owns file – u (aka “owner”) • Users who are members of the same group as the file owner - g • All other users - o (aka “rest of the world”) • 3 levels of access: • Read - r • Write - w • Execute – x (or “search” for directories)
Permission Codes (continued) • Nine characters are split into three sets of three characters each: • 1st set identifies permissions for the user • 2nd set identifies permissions for the group • 3rd set identifies permissions for others (the rest of the world) r w x r w x r w x u g o
Permission Code Examples • r - - r - - r - - user, group members, and others can read the file • r - - - - - - - - only the user can read the file • r w - r - - - - - user can read and write the file, group members can read the file, all others are denied access
Changing Permissions • Use the chmod command to change permissions • Two ways to use chmod command: • Symbolic form • Numeric form
Symbolic Form of chmod • Uses permission code symbols (u, g, o, r, w, x) to add and remove permissions • Basic form of command: • To add a permission: • %chmod [who]+[access] filename • eg. - %chmod o+r README • To remove a permission: • %chmod [who]-[access] filename • eg. - %chmod o-w README • Note: Can set more than one at a time eg. - %chmod o+r,og-w myfile.html
Numeric Form of chmod • Think of 9 character permission codes as 9 on/off switches represented by 1/0 r w x r w x r w x 1 1 1 1 1 1 1 1 1 r w x r - x r - - 1 1 1 1 0 1 1 0 0 • View the binary representation as 3 triplets 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 7 7 7 7 5 4
Numeric Form of chmod (continued) • Use chmod command with octal value representing desired permissions • Examples: %chmod 777 myfile.html 1 1 1 1 1 1 1 1 1 r w x r w x r w x %chmod 711 mydirectory 1 1 1 0 0 1 0 0 1 r w x - - x - - x %chmod 644 myfile.html 1 1 0 1 0 0 1 0 0 r w - r - - r - -
File Names • UNIX is case sensitive so Myfile.html is not the same as myfile.html • Avoid special characters in file names: • < > | & * • Extension at end of file name indicates type of file: • .html or .htm - Web page • .c - C program file • .ps - postscript file • * represents any arbitrary characterstring • eg. - %ls *.html