SPL Lecture2
SPL Lecture2
Spring 2025
❏ Using date Every UNIX system maintains an internal clock that you can access to print the
current system date and time.
❏ If your account has a password that is already known to others, you should change it
immediately:
The UNIX File System Tree
/: root dir
/bin: commands
/dev: file
representing I/O
devices
The UNIX File System
❏ /sbin and /usr/sbin If there’s a command that you can’t execute but the system
administrator can, then it would probably be in one of these directories.
❏ /dev This directory contains all device files.
❏ /lib and /usr/lib These directories contain all library files in binary form. You need to
link your C programs with files in these directories.
❏ /usr/include This directory contains the standard header files used by C programs. The
statement #include <stdio.h> used in most C programs refers to the file stdio.h in this
directory.
❏ /usr/share/man This is where the man pages are stored. There are separate
subdirectories here (like man1, man2, etc.) that contain the pages for each section.
❏ /tmp The directories where users are allowed to create temporary files. These files are
wiped away regularly by the system.
❏ /var The variable part of the file system. Contains all of your print jobs and your outgoing
and incoming mail.
❏ /home On many systems, users are housed here. romeo would have his home directory in
/home/romeo. However, your system may use a different location for home directories.
A data structure storing metadata about files. Each file is
associated with an inode, identified by a unique inode
Basic File Attributes number (within its file system).
● The two basic attributes are: permissions and ownership – both of them are changeable
by well-defined rules.
# Listing File Attributes:
$ ls -l
● The -l option (i.e., long listing format) displays most attributes of a file, such as
permissions, size and ownership.
● The first character in this column is mostly a - (hyphen), which indicates the file is an ordinary
one. Most files here are ordinary files, but c_progs and shell_scripts are directories.
● The directories are indicated by d at the same position. A file can have 3 types of
permissions: r (read), w (write), x (execute)
Links
● The second field in file details shows the number of links associated with a file.
● UNIX lets a file have multiple names, and each name is interpreted as a link.
● Directories have a link count of at least two, but here two ordinary files (backup.sh and
restore.sh) also have two links each.
Ownership and Group Ownership
● Every file has an owner. The third field shows romeo as the owner of most of the files.
● A user also belongs to a group, and the fourth field shows metal as the group owner of
most of the files.
● The owner can tamper (create/modify/remove) with a file in every possible way—a
privilege that is also available to the root user.
File Size
● The fifth field shows the file size in bytes.
● The kernel allocates space in blocks of 1024 bytes or more, so even though backup.sh
contains 163 bytes, it could occupy 1024 bytes on this system.
Last Modification Time & File Name
● The sixth field displays the last modification time in three columns—a time stamp that is
stored to the nearest second. A file is modified only if its contents have changed in any way.
● If we change the permissions or ownership of the file, modification time remains unchanged.
● The last field displays the filename, which can be up to 255 characters long.
Listing Directory Attributes
● The -d option in ls command lists the attributes of a directory, rather than its
contents.
File Permissions
● UNIX has a simple and well-defined system of assigning permissions to files.
$ ls -l backup.sh
● We’ll consider both ways of using chmod, but just remember that only the owner of this file (romeo)
can change these permissions.
Relative Permissions
● When changing permissions in a relative manner, chmod only changes the permissions specified in
mode and leaves the other permissions unchanged.
❏ The expression can comprise multiple categories. This is how we assign execute permission to
all:
The synonym a is available for ugo, so ugo+x is the same as a+x (or even +x).
❏ chmod accepts multiple filenames in a command line. To assign same permissions to a
group of files:
❏ Permissions are removed with the ‘-’ operator. To remove the read and execute
permission from both g and o.
We need to remove the execute permission from user and assign read permission to
the other two categories. This requires two expressions, and using a comma as a
delimiter between them, we can use a single invocation of chmod:
Absolute Assignment
❏ The = operator can perform a limited form of absolute assignment. It assigns only the
specified permissions and removes other permissions. Thus, if a file is to be made read
only to all, we can simply use one of these three forms:
This technique has its limitations; you can’t just set all nine permission bits explicitly.
❏ chmod -R descends a directory hierarchy and applies the expression to every file and
subdirectory it finds in the tree-walk:
❏ So, to use chmod on your home directory tree, “cd” to it and use it in one of these ways:
❏ What is a Directory?
❏ Read permission for a directory means that the list of filenames stored in that directory is
accessible.
❏ Actually, this default is transformed by subtracting the user mask from it to remove one or
more permissions.
❏ The two commands used to change the ownership of a file/directory are $ chown
(change file owner) and $ chgrp (changing group owner)
$→#
chown: Changing File Ownership
❏ To renounce the ownership of the file date.sh to juliet, use chown in the following way:
chgrp: Changing Group Owner
❏ chgrp shares a similar syntax with chown. In the following example, romeo changes the
group ownership of a file to dba (no superuser permission required):
Inodes
Inode (Index Node): A data structure storing metadata about files. Each file is associated with an inode, identified
by a unique inode number (within its file system).
❏ File name and inode number (stored in the directory). Both attributes are stored in the directory.
Thank you!