1 / 14

CS 497C – Introduction to UNIX Lecture 12: - The File System

CS 497C – Introduction to UNIX Lecture 12: - The File System. Chin-Chih Chang chang@cs.twsu.edu. Relative Pathnames (. and ..). A relative pathname is a pathname which defines the location of a file with with respect to the current directory.

Télécharger la présentation

CS 497C – Introduction to UNIX Lecture 12: - The File System

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. CS 497C – Introduction to UNIXLecture 12: - The File System Chin-Chih Changchang@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 • You’ll 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 don’t 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 can’t use rmdir to delete a directory unless it is empty. • You can’t 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) doesn’t 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 won’t 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 won’t delete any file if it’s write-protected. • The –f (force) option overrides this protection also.

More Related