Unix File System - PowerPoint PPT Presentation

1 / 37
About This Presentation
Title:

Unix File System

Description:

I neglected to mention one of the key things you'll need to know as Unix users... Most important options: [-f] doesn't ask if anythings okay it just forces it ... – PowerPoint PPT presentation

Number of Views:127
Avg rating:3.0/5.0
Slides: 38
Provided by: mer95
Category:
Tags: anythings | file | system | unix

less

Transcript and Presenter's Notes

Title: Unix File System


1
Unix File System
  • CSCI 2467 System Programming Concepts
  • Computer Science Department
  • University of New Orleans
  • Instructor Michael Ruth
  • mruth_at_cs.uno.edu

2
Topics
  • Before We Get Started
  • Quick Review
  • Trees
  • File System
  • Files And Directories
  • Quick Definitions
  • Filenames - Absolute vs Relative
  • Guarded Access through Permissions

3
Before We Get Started
  • I neglected to mention one of the key things
    youll need to know as Unix users
  • RTM (Read the manual)
  • If you want to know what a command does (standard
    commands) you use the manual command to do so
  • Ex
  • man man
  • man cd
  • man mv
  • This becomes even more important when you cant
    remember the option that make this a one time
    command

4
Quick Review From Last Week
  • Everything is a file
  • Allows for every I/O subsystem to be handled
    uniformly
  • Mouse, printer, text file, etc
  • Unix files have neither record structure nor
    attributes (not really, but we said that too)
  • Everything can and should be treated as ASCII
  • The file system is hierarchal
  • Tree structure

5
First, some math (graph theory)
  • Graph consist of a set of nodes and a set of
    edges that establish relationships (connections)
    between the nodes
  • Trees are special cases of graphs
  • The relationship is children/parent
  • Each node has zero or more child nodes, which are
    below it in the tree (by convention, trees grow
    down, not up as they do in nature).
  • A node that has a child is called the child's
    parent node (or ancestor node, or superior).
  • A node has at most one parent.
  • The bottommost nodes are called leaves and the
    topmost node is called the root
  • A subtree is a portion of a tree data structure
    that can be viewed as a complete tree in itself

6
Now a picture pictures help I hope
B is a child of A, therefore A is a parent of B
A
A
Root Node
B
R
B
tree with root node B highlighted here is a
subtree of the Tree with root A
C
D
E
T
Leaf Nodes
7
Recursively, Treewise
  • A tree is either empty (having no nodes with no
    children) or is made up of a single node which
    has any number child trees
  • This recursive definition allows us to consider
    how this definition makes everything uniform

8
File System
  • File System
  • method for storing and organizing computer files
    and the data they contain to make it easy to find
    and access them
  • More formally, a file system is a set of abstract
    data types (ADTs) that are implemented for the
    storage, hierarchical organization, manipulation,
    navigation, access, and retrieval of data.
  • In Unix this concept is produced in the form of a
    tree.
  • The tree itself is how the ADTs are stored in the
    more concrete file system
  • The files themselves are the ADTs
  • We interact with the kernel to move around in the
    system as well as move things around the system

9
Files and Unix
  • Files are the center point to any Unix system and
    for purposes of the Unix File System (or UFS)
    they are identified by an inode data type
  • More about inodes later (after weve discussed
    what the information contained in them actually
    is)
  • The only important point is that inodes have
    identifying numbers (unique for each file on each
    device)
  • file is just a sequence of binary digits
  • It is up to the program using the file to
    understand the meaning and internal layout of
    information in the file and present it to a user
    as a document, image, song, or program

10
Directories
  • In computing, a directory is an entity in a file
    system which contains a group of files and/or
    other directories.
  • A typical file system contains thousands of
    files, and directories help organize them by
    keeping related files together.
  • A directory contained inside another directory is
    called a subdirectory of that directory (think
    subtree)
  • Together, the directories form a hierarchy, or
    tree structure
  • The root of the UFS tree is denoted by /
  • However, in Unix Directories themselves are files
    which do not contain the files themselves, rather
    they contain links to the files along with the
    file names

11
Pictorially
/
12
Filenames
  • Every file has a filename
  • Current versions of Unix allow up to 255
    characters, older versions limit to 14
  • Almost any character can be used in a filename
  • Sticking with the following will save many
    problems
  • Uppercase letters (A-Z)
  • Lowercase letters (a-z)
  • Numbers (0-9)
  • Period ( . ) can be used as any other character
    and may denote special files
  • Exception is the root directory, which is always
    named /
  • No other file can use this name

13
More Naming Concerns
  • Other characters may be used by escaping them
    with a \ character
  • Willie\Weasil - displays as WillieWeasil
  • Much confusion can result from this
  • File names are case sensitive
  • my_file, My_File, and MY_FILE are all unique
    names

14
Getting around in UFS
  • Working directory?
  • Where you are in a Unix system
  • pwd
  • Provides absolute path
  • Home Directory
  • Where you started in a Unix System (upon login)
  • Change your working directory?
  • cd directory path
  • No argument changes the working directory to home
    directory
  • With argument changes the working directory to
    specified directory
  • Can be either a relative or absolute path

15
Pathnames
/
  • Every file has a pathname
  • Can be either absolute or relative
  • Absolute
  • A pathname is built by tracing a path from the
    root directory, through all intermediate
    directories, to the file
  • String all the filenames in the path together,
    separating them with slashes ( / ) and proceeding
    them with the root directory ( / )
  • Example /home/mruth/Work1.c

home
stu
mruth
research
grads
16
Relative pathnames
  • Relative
  • The pathname is built by tracing a path from the
    current working directory to where the file
    exists
  • Every directory has two intrinsic directories
  • . (this directory)
  • .. (the parent directory)
  • These make using relative pathnames easy

17
Relative Pathnames Examples
/
mruth/research/Work1.c
../mruth/research/Work1.c
home
research/Work1.c
stu
mruth
./research/Work1.c
research
grads
18
Other Useful commands (ls)
  • List (ls) list all files in directory
  • ls options names
  • If no names are given, list the files in the
    current directory
  • If names we use metacharacters and text to list
    the files that match
  • Important options
  • -a list all files (including pesty hidden files
    which begin with .
  • -i list the inode for each file
  • -l long format listing
  • Note about options if we wish to use more than
    one we simply concatenate the options like so ls
    -ai

19
Directory creation and removal
  • mkdir creates a directory with a given name
  • mkdir options directories
  • Options are -m for mode, and -p for
    autocreate things in between
  • mkdir p mycourses/2467/tests (in empty
    directory)
  • rmdir removes a directory with a given name
    (directory must be empty)
  • rmdir options directories
  • I have never ever used any of the options (rarely
    even use this command)

20
Unix Security
  • The Unix system treats everything as a file
  • The Unix System Provides security capable of
    handling
  • Group access
  • Individual access
  • System access
  • Of course, this is handled at the file level

21
Files and Owners
  • Every file has a single owner as well as a
    permissions (or mode) associated with it
  • The only person who can access everything by
    default is the root user
  • The root is generally the system administrator
  • Everyone one else can access what they have
    permission to access
  • This permission is set at the individual file
    level

22
Access Types
  • Individual Access same level of access provided
    by the login/logout scheme on a Unix System
  • Each user is given both a username and a UID to
    uniquely identify them on the system
  • Group Access there are a number of groups on
    any given system which form some sort of cohesive
    unit (all accountants on 3rd floor)
  • Eases IT management
  • Each group is given both a name and a GID to
    uniquely identify them on the system
  • Each user can be a member of several groups and
    each group can be comprised of several members

23
Three levels of Access
  • Read allows examination of a files contents
  • Directory contents of the given directory can be
    listed
  • Write allows altering or adding to the files
    contents also allows deletion
  • One can add files to the given directory
  • Execute allows execution of the file as a
    program
  • One can change their working directory to the
    given directory

24
Access levels and types
  • Each level may be selected added or removed for
    each access type for each file
  • This provides a fair amount of flexibility in
    deciding how to allow/deny access to what it is
    that you are trying to protect

25
chmod
  • chmod takes two forms
  • chmod perms filename
  • Perms is specified in octal
  • Ex chmod 0755 grants rwx-r-x-r-x
  • chmod who-what filename
  • Ex
  • chmod u-x ? removes execute for user
  • chmod x ? adds execute for everyone (all three)
  • Three types are user (u), group (g), and others
    (o)

26
chown/chgrp/su
  • chown allows one to change the individual
    ownership of the file
  • chown options newowner filename
  • chgrp allows one to change the group ownership of
    the file
  • chgrp options newgroup filename
  • Su allows one to change (temporarily) a users
    user id
  • su username
  • Switch user NOT super user
  • If no username is given, it defaults to root

27
Umask
  • Umask is the default file creation mode mask
  • Every file you create or will be created with
    have a set of default permissions associated with
    it
  • You can change that using umask command
  • umask value
  • If no value is specified it returns current value
  • If value is present, set it to that value

28
Revisiting Inodes
  • Earlier I said Unix files have neither record
    structure nor attributes
  • Unix files are said neither to have structure nor
    attributes in any normal sense
  • No a priori knowledge of
  • What kind of file it is (text/binary)
  • What kind of program opens it
  • Is this archived?
  • However, even though the inode structures in Unix
    holds information about each file they were
    designed to be extremely generic so that it can
    be used for any type of file

29
Inode properties
  • Device ID device inode resides on
  • Inode ID inode number
  • Mode permission mode
  • Link Count number of hard links to the file
  • UID user id of the owner
  • GID group id of the owner
  • Device Type the device type of the device the
    inode resides on
  • Size size in bytes of the total size of file
  • Three dates
  • Last access
  • Last modification
  • Last status change
  • Optimal block size for the system
  • Links to the device that actually holds the data

30
Links???
  • Unix provides both hard and symbolic links to
    files.
  • Hard links
  • must reside on the same filesystem. A hard link
    is
  • essentially a direct reference to the file by a
    another name.
  • Both files share the same inode and the inode
    increases the reference count of the file by one
    for each link.
  • The ln command creates hard links. The format of
    the command is ln existing-file new-file.
  • A symbolic link is a
  • file that indirectly points to another file.
  • While the affect is the same as a hard link a
    symlink does not increase the reference count of
    a file.
  • A symbolic link also can point to files on other
    file systems and files that don't even exist!
  • The ln -s command creates a symbolic link. The
    format of the command is ln -s existing-file
    new-file.

31
File types
  • Upon running ls l (or similar commands) we find
    that the system does keep track of certain system
    file types
  • The first letter of the command shows us what
    file type it is
  • Regular files have a prefix of
  • Directories have a prefix of d
  • Links have a prefix of l
  • There are a few more, but well talk about them
    as we get there

32
Important file commands
  • cp options source target
  • Most important option -r recursively copy
  • mv options source target
  • file options files
  • Tries to determine what kind of file is present
  • rm options target
  • Most important options
  • -f doesnt ask if anythings okay it just forces
    it
  • -r recursively does its job

33
Multiple Disks and UFS
/
/
home
homework
34
Mounting a drive (into the tree)
/
This is what we want
/
home
homework
35
Mount command
  • mount -t vfstype device dir
  • Do NOT use the t option unless not using it is
    NOT an option
  • Ex mount /dev/fd0 /home/meruth

36
Future Classes
  • Text/File Processing
  • Processes and Job Control
  • Shell Programming Regular Expressions
  • Introduction to C Programming

37
Questions?
Write a Comment
User Comments (0)
About PowerShow.com