CS 497C - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

CS 497C

Description:

There may be an ordinary file by that name in the current directory. ... current directory don't permit the creation of files and directories by the user. ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 15
Provided by: Kindy
Category:
Tags: 497c | directories

less

Transcript and Presenter's Notes

Title: CS 497C


1
CS 497C Introduction to UNIXLecture 12 - The
File System
  • Chin-Chih Changchang_at_cs.twsu.edu

2
Relative Pathnames (. and ..)
  • A relative pathname is a pathname which defines
    the location of a file with with respect to the
    current directory.
  • It uses the symbols . (a single dot) and .. (two
    dots) to refer to the current and parent
    directories, respectively.
  • The command cd .. change your directory to the
    parent directory of the current directory.

3
Relative Pathnames (. and ..)
  • pwd
  • /home/remeo/progs
  • cd ../..
  • pwd
  • /home
  • For example, if you are in your home directory
    /home/romeo and you want to display the contents
    of /etc/service, you can use either one of
    following ways

4
Relative Pathnames (. and ..)
  • cat /etc/service
  • cat ../../etc/service
  • Youll sometimes need to precede a command with
    ./ (a dot and a /).
  • Assume you want to use a cat program written by
    you in the current directory, you can run your
    own cat and ignore the one in /bin
  • ./cat note

5
mkdir Making Directories
  • Directories are created with the mkdir (make
    directory) command.
  • The command is followed by the names of the
    directories to be created.
  • You can create more than one directory in one
    command.
  • mkdir doc src news

6
mkdir Making Directories
  • Sometimes, the system refuses to create a
    directory because
  • The directory may already exist.
  • There may be an ordinary file by that name in the
    current directory.
  • The permissions set for the current directory
    dont permit the creation of files and
    directories by the user.

7
rmdir Removing Directories
  • The rmdir (remove directory) command removes
    directories.
  • You can delete more than one directory in one
    command.
  • They are two important rules when deleting
    directories
  • You cant use rmdir to delete a directory unless
    it is empty.
  • You cant remove a subdirectory unless you are
    placed in a directory hierarchically above the
    one you choose.

8
cp Copying Files
  • The cp command copies a file or a group of files.
  • cp chap1 unit1
  • If the destination file (unit1) doesnt exist, a
    new file will be created. If not, it will be
    overwriten without any warning from the system.
  • If unit1 is a directory, the file will be copied
    into that directory.

9
cp Copying Files
  • You can copy multiple files to a directory.
  • For instance, to copy the file chap1, chap2, and
    chap3 to the progs directory, you can use
  • cp chap1 chap2 chap3 progs
  • The UNIX system uses a set of special characters
    called metacharacters that you can use for
    matching more than one file.

10
cp Copying Files
  • cp is often used with the shorthand notation .
    (dot) to signify the current directory as the
    destination.
  • For instance, to copy the file .profile from
    /home/juliet to your current directory, you can
    use either of the two commands
  • cp /home/juliet/.profile .profile
  • cp /home/juliet/.profile .

11
cp Copying Files
  • You can use the as a shorthand for multiple
    filenames sharing a command string.
  • For example, you can copy chap01, chap02, and
    chap3 in this way
  • copy chap progs
  • The i (interactive) option warns the user before
    overwritting the destination file.
  • The r (recursive) option makes it possible to
    copy an entire directory.

12
rm Deleting Files
  • The rm command removes files and makes space
    available on disk.
  • It normally operates silently and should be used
    with caution. It can delete more than one file
    with a single instruction
  • rm chap01 chap02 chap03
  • rm chap
  • rm progs/chap01 progs/chap02

13
rm Deleting Files
  • Unless used with r option, rm wont remove a
    directory.
  • You may need to delete all files of a directory,
    as part of a cleaning-up operation
  • rm
  • The i (interactive) option makes the command ask
    the user for confirmation before removing each
    file.

14
rm Deleting Files
  • With the r option, rm performs a tree walk a
    thorough recursive search for all subdirectories
    and files within these subdirectories.
  • Using the rm r will delete all files in the
    current directory and all subdirectories and
    their files.
  • rm wont delete any file if its write-protected.
  • The f (force) option overrides this protection
    also.
Write a Comment
User Comments (0)
About PowerShow.com