File Attributes - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

File Attributes

Description:

... and passwords are stored in /etc/passwd or in an encrypted /etc/shadow file. ... The inode number of a file can be found using the ln -i command. ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 16
Provided by: unkn998
Category:
Tags: attributes | file | lane | shadow

less

Transcript and Presenter's Notes

Title: File Attributes


1
File Attributes
  • Brian C. Hoffman
  • CINS 142

2
Listing Files
  • ls options - lists the contents of the current
    directory
  • ls options dirname - list contents of that
    directory
  • ls options str - Lists all files that start
    with str.
  • Common Options
  • l, long format listing giving many details
  • a, list all files including those normally hidden
  • r, list files in reverse order
  • s, include size in blocks
  • S, sort by size
  • t, sort according to time
  • R, list content of subdirectories

3
Ls -l Listing File Attributes
  • The -l option provides a comprehensive look at
    the files and their attributes. Lets examine a ls
    -l listing

owner
sym link
group
links
Mod. date
name
Permissions in the order u,g,o
Size in bytes
Directory or not?
4
Permissions Users and Groups
  • Permissions and security in a Unix enviroment is
    based on the concept of users and groups.
  • Everyone who uses a Unix account is given a
    username and password that identifies them to the
    system. Usernames and passwords are stored in
    /etc/passwd or in an encrypted /etc/shadow file.
  • Every user may also belong to one or more groups.
    A group is a way of logically collecting users
    together and granting or denying permisstions to
    the entire group. Makes life easier.

5
Permissions The rwx Block
Permissions block
  • The permsions block consists of 9 spots ---------
  • The first 3 indicate the user, the next 3 the
    group, and the last 3 other
  • An r indicates read permission, a w write
    permission, and an x execute premission for that
    user, group, or other.
  • For example, rw-r--r-- indicates that the user
    can read or write the file wheras the group and
    others can only read it.

6
chmod Changing Permissions
  • The chmod command allows one to set the
    permissions for a file or directory.
  • The chmod command can be used in two ways, via a
    special options setup of using octal notation. We
    will cover the option way on this slide.
  • chmod category, command, permission,ccp,,cc
    p
  • The category can be u for owner, g for group, or
    o for other. You can also place them together.
    For example, ug will set for both user and group.
  • The command can be ,-, or . adds a
    permission, - takes it away, and sets it as
    given and may remove permissions.

7
chmod Octal Notation
  • The chmod command can work with the following
    format using octal digits (0-7) chmod fname.
  • The digits have the following meaning
  • 4 read
  • 2 write
  • 1 execute
  • To get mixed priviliges, add the numbers.
  • chmod 777 myfile grants full permissions
  • chmod 660 myfile grants read and write permission
    to the owner and group

8
Why Octal Numbers Work
  • To represent the permissions, we can use a binary
    number made of 1s and 0s. A 1 indicates that
    permission is granted and a 0 means not granted.
  • Since we have three kinds of permission, our
    binary number must be 3 digits long. They are
    given in the order read, write, execute. Thus,
    111 grants full permissions and 001 grants only
    execute permission.
  • Now, lets convert 111 to base 10. It is equal to
    141211 or 7. This agrees with what we say
    before.
  • 010 is write permission. Converting to base 10 we
    get 0412012. Once again we agree.
  • So why can we add 4, 2, and 1 in the last slide
    and have it work?

9
Default Permissions
  • On most systems the default permissions start at
  • 666 for regular files
  • 777 for directories
  • However, the final value is determined by the
    systems umask. This mask tells the value to
    subract from the above to get the real system
    defaults.
  • For example, a umask of 022 grants 644
    permissions for directories and 755 permissions
    for directories
  • The umask command will tell you the setting, but
    only an administrator can change it.

10
Directory Permissions
  • By default all users are allowed read and execute
    permissions to a directory.
  • Removing read permission from a directory will
    prevent ls from being able to list it. The
    command cannot read the directory info. You can
    still read individual files if you know their
    names.
  • You cannot create, remove, or rename files in a
    directory that is write protected.
  • Excecute permissions for a directory determine if
    you can pass through it to subdirectories or cd
    to it.

11
Changing Group and Ownership
  • As we saw in the ls-l listing files have an owner
    and belong to a group. This defines how the
    permissions apply.
  • User and group ids are specified in the
    /etc/passwd and /etc/group files.
  • In /etc/passwd, the first entry on a line is the
    user name, the third the user Id, and the 4th the
    primary group id.
  • To change the owner of a file use chown newowner
    file file
  • To change the group a file belongs to usechgrp
    newgrp file file

12
Touch Modifying Access Times
  • The access time tells the time the file was
    created or last modified.
  • The touch options expression filname(s)
    command will let you reset the access time.
  • If the file doesnt exist touch will create an
    empty file with that name.

13
Hard Links
  • In the Unix file system, files are uniuely
    identified by their inode number.
  • The inode number of a file can be found using the
    ln -i command.
  • A hard link exists when two names in the file
    system point to exact same inode. This accounts
    for the link number in the ls -l listing.
  • A hard link can be created by using the
    commandln exitingFile newName. This will
    associate two name to one file. The data exists
    only once.
  • The rm command works by deleting the name and
    reducing the link count. It only clears the inode
    when the last links has been removed.

14
Why Create Links
  • To account for other programs expectations about
    where a program resides.
  • To account for files that must be named
    differently but have the same contents.
  • To switch between versions of a program. You
    create a link to the right version in the
    expected place.
  • To gain quick access to often used files.

15
Symbolic or Soft Links
  • Hard links cannot exist across two file systems
    and you cannot link a directory.
  • However, these limitations can be overcome by
    symbolic links.
  • A soft symbolic link is a directory entry that
    points to another file. It has its own inode
    and does not show up in the number of links. It
    essesnitally behaves as its own file. Kind of
    like a shortcut in windows.
  • To create a symbolic link use the commandln -s
    exitingFile newName
Write a Comment
User Comments (0)
About PowerShow.com