1 / 17

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

CS 497C – Introduction to UNIX Lecture 11: - The File System. Chin-Chih Chang chang@cs.twsu.edu. The File. UNIX looks at everything as a file. A file in UNIX contains exact bytes that you put into it. It doesn’t even contain its own name. Files can be divided into three categories: searches:

hunter-goff
Download Presentation

CS 497C – Introduction to UNIX Lecture 11: - 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 11: - The File System Chin-Chih Changchang@cs.twsu.edu

  2. The File • UNIX looks at everything as a file. • A file in UNIX contains exact bytes that you put into it. It doesn’t even contain its own name. • Files can be divided into three categories: searches: • Ordinary file – Also known as regular file. It contains only data as a stream of characters. • Directory file – A folder containing the names of other files and directories. • Device file – It represents all hardware devices.

  3. The File • The traditional file is of the ordinary or regular type. • It consists of a stream of data resident on some permanent magnetic media. • You can put anything you want into this type of file. This includes all data, source programs, object and executable code, all UNIX commands, as well as any file created by the user.

  4. The File • Commands like cat, ls, and so forth are treated as ordinary or regular files. • The most common type of ordinary file is the text file. • The characteristic feature of text files is that the data inside them are divided into groups of lines, with each line terminated by the linefeed (LF) character.

  5. The File • A directory file contains no external data but maintains some details of the files and subdirectories that it contains. • A directory file contains two fields for each file – its name and identification number. Every file has a number called the inode number.

  6. The File • The definition of a file has been broadened by UNIX to consider even physical devices as files. • The device file is special. It doesn’t contain any data. Any output directed to it will be reflected onto the respective physical device associated with the filename. This mapping is done by kernel.

  7. What’s in a (File)name? • If you want, you can also use control characters or other unprintable characters in a filename. • These filenames are valid: ^V^B-++b -{}[] @#$% *hi • Commands behave unpredictably if filenames have these characters. You should avoid using control characters.

  8. What’s in a (File)name? • It is suggested the following characters are used when framing filenames: • Alphabets and numerals • The period (.) • The hyphen (-) • The underscore (_) • UNIX imposes no restrictions on the extension. It’s the application that imposes this restriction.

  9. What’s in a (File)name? • Windows users must keep these two points in mind: • A file can have many dots embedded in its name; a.b.c.d.e is a valid filename. • UNIX is sensitive to case; chap01, Chap01, and CHAP01 are three different filenames. • But when you download these files from a UNIX system to a Window’s system, the Windows’ system treat them as the same file. If you are going to transfer files between UNIX and Windows, it’s better to give them different names in Windows.

  10. The Parent-Child Relationship • root directory has all the subdirectories of the system under it. • For instance, bin and usr are two directories under root. • Every file, apart from root, must have a parent, and it should be possible to trace the ultimate parentage of a file or root. • These parent-child relationships the parent is always a directory.

  11. The UNIX File System • Most vendors adopted the SVR4 structure of the UNIX file system. • The standard directories under the root directory are: • /bin and /usr/bin – contains commonly used UNIX commands. • /sbin and /usr/sbin – contains most commands executed by the system administrator. • /etc – contains the configuration files of the system.

  12. The UNIX File System • /dev/ - contains all device files. • /home – contains the home directories of users. • /tmp – allows users to create temporary files. • /var – contains all print jobs, mail queues, and incoming mail. • /lib – contains all library files. • There are a lot more directories, and UNIX flavors differ in name and location of many system directories.

  13. pwd: Knowing Your Current Directory • The current directory is the directory where a user is located. • The pwd (present working directory) command tells the current directory. $ pwd /home/remeo • What you see above is a pathname – a sequence of directory names separated by slashes.

  14. pwd: Knowing Your Current Directory • When you log on to the system, UNIX automatically places you in a directory called the home directory (or login directory). • It is created by the system when a user account is opened. • The shell variables HOME knows your home directory. To evaluate it, use: $ echo $HOME

  15. Absolute Pathnames • Many UNIX commands use file and directory names as arguments. To access the file which is not in your current directory, you need specify the file either with an absolute pathname or with a relative pathname. • An absolute pathname uses the root directory as the ultimate reference for the file.

  16. Absolute Pathnames • A relative pathname uses the current directory as point of reference and specifies the path relative to it. • If you want to use commands which are not in the directories specified in PATH, you can use the absolute pathname to invoke it. • For example, to play a Tetris game, you use: $ /usr/games/tetris-bsd

  17. cd: Changing Directories • You can move around in the file system by using the cd (change directory) command. • When used with an argument, it changes the current directory to the directory specified as the argument. • The cd used without arguments reverts to home directory.

More Related