1 / 40

UNIX

UNIX. Working with Directories. Objectives. Introduce the Unix directory structure. Introduce the following Unix directory commands: ls : show contents of directory cd : change directories mkdir : make a new directory chmod : change directory permissions

zuri
Download Presentation

UNIX

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UNIX Working with Directories

  2. Objectives • Introduce the Unix directory structure. • Introduce the following Unix directory commands: • ls : show contents of directory • cd : change directories • mkdir : make a new directory • chmod : change directory permissions • rmdir : delete/remove a directory • cp : copy a directory • mv : move/rename a directory • Introduce directory symbols (/,~)

  3. Overview of an Operating System • Provides a user interface • Allows sharing of hardware • Provides a means for sharing data • May schedule resource usage among multiple users • May schedule resource usage among multiple tasks • Facilitates input and output • Provides graceful error recovery Note: Unix provides support for all of the above tasks .

  4. OS Resource Management Storage Processors OS Data I/O Devices

  5. Unix Files • Unix files are collections of data under a given name. Can be text, binary, a link, or a directory. • Directories are files that contain other files.

  6. UNIX Directories • the directory structure • the home directory (~) • the root directory (/) • changing directories (cd) • display the working directory (pwd) • displaying files in a directory (ls) • making a directory (mkdir) • changing directory permissions (chmod) • copying directories (cp) • moving directories (mv) • removing a directory (rmdir)

  7. Unix Directory Structure • Directories are similar to the folders in a Windows environment. • inverted tree format (root on top) • devices (C:, D:, etc.) not specified

  8. Unix Sample Directory Structure

  9. Unix/Windows Sample Directory Structure Unix Directory Structure note: Unix does not precede pathnames with device identifiers (e.g. c:, D:, etc.) Windows Directory Structure

  10. Some Standard Directories • / (root) Base of the file system hierarchy • bin Binary images of some UNIX commands • dev Filenames that correspond to devices • etc System administrator files • lib Library files • tmp Temporary files - some UNIX commands • home User portion of file system (may also be called usr on some systems)

  11. File/Directory Naming • Up to 255 characters in length • Case sensitive (jan not same as Jan) • Recommended characters are: • Upper/lower case (A-Z, a-z) • Numbers (0-9) • Underscore (_) • Period (.) • Comma (,)

  12. The root directory (/) • The root directory (/) is the starting location for all directories in Unix Caution: if a directory name is preceded by the root directory (/), Unix assumes that we wish to specify the entire directory path!

  13. What do you need to do with directories? Using Windows or Mac as an example, what operations can you do with directories?

  14. The Home Directory • The home directory becomes the current directory when logging on (not the root directory (/)). • May be referenced using: • system variable HOME (try echo $HOME) • the tilda (try echo ~)

  15. Directory symbols • Unix provides shortcut symbols to refer to certain directories. • Examples: • / (forward slash) – the root directory • ~ (tilda) – your home directory • . (period) – the current directory • ..(double period) – the parent directory (one up in the tree)

  16. Unix Directory Navigation • Absolute – Always begins with the root directory. Example: /home/zabc123/public_html • Relative – begins with the current directory (do not start with a slash(/) as that means absolute) Example: public_html assuming we are in the /home/zabc123 directory, public_html refers to the absolute directory name: /home/zabc123/public_html

  17. Relative Directory Navigation • May use the double period (..) to move up the tree relative from the current directory. • Cannot use .. in the root directory. Why not? • Example: Assuming we are in directory: /home/zabc123/public_html ../myprog will refer to directory /home/zabc123/myprog since .. means /home/zabc123/

  18. Change Directories (cd) • Format: cd [directory] • If the directory is omitted the user is returned to his/her home directory, directory may be either an absolute or relative directory name • Examples:

  19. Identifying the Working directory (pwd) • On occasion the user may forget where he or she may be in the directory hierarchy. • The pwd (present/print working directory) command will display the current directory on the screen.

  20. Displaying contents of a directory (ls) • Format: ls [-options] [directoryname] • If directoryname is omitted, current directory is listed. • Popular options (recall Unix is case sensitive): • -a Shows you all files, even files that are hidden (these files begin with a dot.) • -d will list the directory (useful with the –l option) • -l will list each of the files in the current directory giving: • permissions (d-directory, l - link, r-read, w-write, x-execute or access from internet). The permissions will be repeated for the three types of accessibilities: user (you only); group; other (basically the world). • The number of links or directories within the directory. • username • group name • file size in bytes • date and time of the last modification, • the file name or directory. • -R Recursive, shows listings of subdirectories • -F List directories with /; executables with * • -q Print non-graphic invisible control chars

  21. ls –l Example file type (d=directory,  = file, l=link,etc) permissions links or subdirectories (including . & ..) owner group -rw-r--r-- 1 zucker faculty 18 Jan 31 11:02 sordid -rwx--x--x 1 zucker faculty 42 Sep 24 13:23 temp drwx--x--x 3 zucker faculty 4096 Jan 24 10:40 test size (bytes) creation or modified date creation or modified time file/directory name

  22. ls –l permissions file type (d=directory,  = file, l=link,etc) user group other -rw-r--r-- 1 zucker faculty 18 Jan 31 11:02 sordid drwx--x--x 3 zucker faculty 4096 Jan 24 10:40 test • Permission types: • r – Read (persons may view the file) • w – Write (persons may modify or delete file) • x – Execute (persons may be able to execute • the file or if the file is a directory, the directory may be accessed) • In this example: • file sordid may be read and modified by the owner (zucker), read only by the group (faculty), and read only by the world. • directory test may be read, written, and accessed by the owner (zucker) and accessed by the group (faculty) and the world

  23. ls -ld • Occasionally you will want to look at the permissions of a directory: • ls –ldirectoryname will give you a long listing of the directory contents, not the directory itself. • ls –ld directoryname will give a long listing of the directory, not the contents of the directory.

  24. Creating a Directory (mkdir) • mkdir [options] directory name • Short for Make a Directory • Creates a subdirectory of the existing directory • May want to use upper-case letters for directory names (to distinguish from files, discussed later)

  25. mkdir (continued) • If you wish to create multiple levels you must use the –p option (p for parents), for example: #will fail if directory abc does not exist mkdir abc/def # will create abc and the subdirectory def mkdir –p abc/def • If you wish to create several subdirectories you may use the curly braces ( { } ) to create a set of subdirectories. For example: mkdir {abc,def} Will result in two subdirectories being created, abc and def

  26. File/Directory Naming(review) • Up to 255 characters in length • Case sensitive (jan not same as Jan) • Recommended characters are: • Upper/lower case (A-Z, a-z) • Numbers (0-9) • Underscore (_) • Period (.) • Comma (,)

  27. chmod [options] mode directory • Changes the access mode for a given directory; only the owner of the directory or the SuperUser can change its access mode. • Options • -R recursively • Can use octal permission numbers • r – 4 : read permission • w – 2 : write permission • x – 1 : execute permission* • For directories execute permission allows users to access a directory without reading it. This is important for creating html directories, allowing web users to view web content within a directory, but not be able to read the directory itself. *

  28. Octal Permissions

  29. chmod Examples • using octal permissions • chmod 751 mydir • mydir permissions would show as drwxr-x--x give user read (4), write (2), and execute (1) (4+2+1=7) permission give group read (4) and execute (1) (4+1=5) permission give everyone execute (1) permission { { { { directory other user group

  30. chmod [options] mode directory • Class of user: • u User (you) • g Group • o Other (all others) • a All u, g, and o • Permission Values: • r Read • w Write • x Execute • Operations: • + add permission • - remove permission • = set permission (replace existing)

  31. chmod Examples • Using options

  32. Copying Directories(cp) • cp-rsourcedirectory destinationdirectory • Copies an entire directory structure If destination directory exists before issuing cp command, the cp command creates a subdirectory within the directory otherwise it makes a new copy • Options (required for directory copying) • -R or –r Copy directories recursively

  33. Copy Directory example / DirA DirB Assumption: we are currently located in DirB Command issued: cp –r /DirA . Result: Since the period (.) represents the current directory and DirA does not exist, the subdirectory DirA is created / DirA DirB DirA

  34. Copy Directory example / DirA DirB Assumption: we are currently located in DirB Command issued: cp –r /DirA DirB Result: Since the DirB relative to the current directory (DirB) does not exist, the subdirectory DirB is created / DirA DirB DirB

  35. Copy Directory example / DirA DirB Assumption: we are currently located in DirB Command issued: cp –r /DirA DirC Result: Since the DirB relative to the current directory (DirB) does not exist, the subdirectory DirC is created / DirA DirB DirC

  36. Move/Rename Directories (mv) • mvsourcedirectory nonexistentdirectory • mvsourcedirectory existingdirectory Renames or moves the source directory to: • 1. the nonexistent directory • 2. a subdirectory of the existing directory

  37. Remove/Delete a Directory (rmdir) • rmdirdirectoryname Directory must be empty Current working directory cannot be the directory you are removing Does not ask for confirmation, be careful

  38. Remove/Delete a Directory (rm) • rm -rfdirectoryname • Similar to the –r for cp, means recursively Directory and all contents (including subdirectories and their contents) will be deleted Current working directory cannot be the directory you are removing Does not ask for confirmation, be careful see cartoon on back cover of Unix in a NutShell

  39. UNIX Directories • the directory structure • the home directory (~) • the root directory (/) • changing directories (cd) • display the working directory (pwd) • displaying files in a directory (ls) • making a directory (mkdir) • changing directory permissions (chmod) • copying directories (cp) • moving directories (mv) • removing a directory (rmdir)

  40. Next Time • Please review the following file commands in the text: • touch • cat • chmod • rm • cp • mv

More Related