slide1
Download
Skip this Video
Download Presentation
UNIX

Loading in 2 Seconds...

play fullscreen
1 / 40

UNIX - PowerPoint PPT Presentation


  • 164 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'UNIX' - zuri


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

UNIX

Working with Directories

objectives
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 (/,~)
overview of an operating system
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 .

os resource management
OS Resource Management

Storage

Processors

OS

Data

I/O Devices

unix files
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.
unix directories
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)
unix directory structure
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
unix windows sample directory structure
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

some standard directories
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)

file directory naming
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 (,)
the root directory
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!

what do you need to do with directories
What do you need to do with directories?

Using Windows or Mac as an example, what operations can you do with directories?

the home directory
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 ~)
directory symbols
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)
unix directory navigation
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

relative directory navigation
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/

change directories cd
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:
identifying the working directory pwd
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.
displaying contents of a directory ls
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
ls l example
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

ls l permissions
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
ls ld
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.
creating a directory mkdir
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)
mkdir continued
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

file directory naming review
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 (,)
chmod options mode directory
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.

*

chmod examples
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

chmod options mode directory30
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)
chmod examples31
chmod Examples
  • Using options
copying directories cp
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
copy directory example
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

copy directory example34
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

copy directory example35
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

move rename directories mv
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
remove delete a directory rmdir
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

remove delete a directory rm
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

unix directories39
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)
next time
Next Time
  • Please review the following file commands in the text:
    • touch
    • cat
    • chmod
    • rm
    • cp
    • mv
ad