0% found this document useful (0 votes)
12 views8 pages

Types of UNIX Files and Pathnames Explained

Uploaded by

Madhushree S G
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views8 pages

Types of UNIX Files and Pathnames Explained

Uploaded by

Madhushree S G
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Module-4

[Link] the various types of UNIX files.


In UNIX, files are divided into three categories –
* Ordinary file * Directory file * Device file
• Ordinary (Regular) File
It is a most common type of file that contains only data as a stream of
characters. An ordinary file can be one among these –
* Text file * Binary file * Device file
• Directory File
• A directory contains no data, but it keeps some information
about the files and subdirectories that it contains.
• A directory actually do not contain the file itself, rather it
contains only the file name and a number.
• We cannot write into a directory file. But the actions like
creating a file, removing a file etc. makes kernel to update the
corresponding directory by creating/removing filename and
inode number associated with that file. inode number refers to
the physical file, the data stored in a particular location.
• Device File :
• Device filenames are generally found inside a single directory
structure, /dev.
• A device file is not a stream of characters. In fact it does not
contain anything.
• The operation of a device is completely managed by the
attributes of its associated file. The kernel identifies a device
from its attributes and then uses them to operate the device.
[Link] the different types of pathnames with its example.
ABSOLUTE PATHNAMES :
A path of a file (or directory) which specifies the complete hierarchy of that
file starting from the root (/) directory is called as absolute pathname of that
file (or directory).
Example: it is assumed that the file [Link] is in current directory. If you would
like to access the file in some other directory, you have to give the command
by specifying absolute pathname of that file as –
$ cat /home/john/[Link]
RELATIVE PATHNAMES :
A relative path is defined as the path related to the present working
directory.
For example, if we are currently in /home/john and would like to move to
/home/john/test, then we can just give the command as –
$cd test(Relative path usage)
We can also give the command as:
$ cd /home/john/test (Absolute path usage)
Note:-if the pathname starts with / (root), we can say that it is absolute path.
Otherwise, it is relative path.
[Link] the Relative pathnames using dot(.) and two dot(..).
Using . and .. in Relative Pathnames :
A single dot (.) – represents current directory
Two dots (..) – represents parent directory.
we can use ./(dot with slash).
For example, assume there is a file [Link] in the current directory.
And, we want to copy it into directory myDir which is within current
directory. Now we can use the command –
$cp ./[Link] ./myDirt
[Link] the working process of UNIX file system with its root
directory.
1. Root Directory (/):
o The root directory is the top-level directory in the Unix file system. It is
denoted by a forward slash (/).
o All other directories and files are descendants of the root directory.
o The root directory contains essential system files and subdirectories.
2. Hierarchical Structure:
o The Unix file system follows a hierarchical (tree-like) structure.
o Directories (folders) and files are organized into a multi-level hierarchy.
o Each directory can contain both files and other directories.
3. Subdirectories:
o Below the root directory, you’ll find several subdirectories:
▪ /bin: Contains fundamental utilities (e.g., ls, cp) needed by all users.
▪ /boot: Holds files required for the booting process.
▪ /dev: Represents devices (both physical and pseudo-devices).
▪ And many more, depending on the Unix variant.
4. File Representation:
o In Unix, everything is treated as a file, including devices.
o Device files (located in /dev) represent peripherals (e.g., disks, keyboards).
o There are two types of device files:
▪ Block Special Files: Transfer data in blocks (similar to disks).
▪ Character Special Files: Transfer data as a stream of bits (e.g., keyboard
input).
5. Unique Inodes:
o Each file in Unix has a unique identifier called an “inode.”
o Processes accesss files through a well-defined set of system calls.
o Pathnames (character strings) uniquely identify files and are converted to
inodes.
[Link] the process of removing a permission in file using ls
command and chmod command.
1. Viewing File Permissions with ls:
o The ls command allows you to list files and directories along
with their permissions. When you run ls -l [Link],
you’ll see output like this:
o -rw-r--r-- 12 linuxize users 12.0K Apr 8 20:51 [Link]
o The first character indicates the file type (e.g., - for a regular
file).
o The next nine characters represent the permissions: three
triplets for owner, group, and others.
o For example, rw-r--r-- means the owner has read and write
permissions, while the group and others have read-only
permissions1.
2. Removing Permissions with chmod:
o To remove permissions, use the chmod command.
o Suppose you want to remove read permissions for others
(everyone else) from a file named [Link]. You can do
this:
o chmod o-r [Link]
o This command removes read permissions for the “other”
category of users.
o If you want to include files in subdirectories as well, use
the -R (recursive) option2.
[Link] the differences between hard links and soft links.
Hard links :
1. Hard Links have the same inodes number.
2. ls -l command shows all the links with the link column showing the
number of links.
3. Links have actual file contents
4. Removing any link, just reduces the link count but doesn't affect
the other links.
5. You cannot create a Hard Link for a directory.
6. Even if the original file is removed, the link will still show you the
contents of the file.
Soft links :
1. Soft Links have different inodes numbers.
2. ls -l command shows all links with second column value 1 and the
link points to the original file.
3. Soft Link contains the path for original file and not the contents.
4. Removing soft link doesn't affect anything but when the original
file is removed, the link becomes a 'dangling' link that points to
nonexistent file.
5. A Soft Link can link to a directory.
[Link] the method of changing file permissions using chmod
command.
1. Basic Permissions Model:
o Each file has an owner, a group, and permissions for three
classes of users: owner, group members, and others.
o Permissions include read (r), write (w), and execute (x).
o Example: -rw-r--r-- means the owner has read and write
permissions, while the group and others have read-only
permissions1.
2. Syntax:
o To change permissions, use: chmod
[references][operator][modes] filename.
o References: u (user/owner), g (group), o (others).
o Operator: + (add), - (remove), = (set explicitly).
o Modes: r (read), w (write), x (execute)2.
3. Examples:
o Grant executable permission: chmod +x filename
o Remove executable permission: chmod -x filename
o Give owner read and write permissions: chmod u=rw
filename
o Give group read and write permissions: chmod g=rw
filename
o Give others read and write permissions: chmod o=rw
filename
[Link] the concept of file permissions using ls-l command.
When using the ls -l command in a Unix shell, the output displays
information about the file permissions. Each line represents a file or
directory, and the permissions are displayed in the first column. The
permissions are represented by a 10-character string, with the first
character indicating the type of the file (e.g. regular file, directory,
symbolic link), followed by three sets of three characters representing
the permissions for the owner, group, and others, respectively.
For example, a file with permissions rw-r--r-- means that the owner
can read and write to the file, while the group members and others
can only read it. Similarly, a directory with permissions rwxr-xr-
x allows the owner to read, write, and execute the contents of the
directory, while group members and others can only read and
execute.
[Link] the types of links in UNIX file system with its example.
A link is a connection between the file to be shared and the directory
entries of the users who want to have access to this file
2 types of links exist:
• hard links
• soft (symbolic) links
• Hard Link acts like a mirror copy of the original file.
• These links share the same inodes.
• Changes made to the original or hard-linked file will reflect in the
other.
• When you delete Hard Link nothing will happen to the other file.
Hard links can't cross file systems.

• Soft Link is an actual link to the original file also know as symbolic
link or symlinks.
• These Links will have a different Inodes value.
• The soft link points to the original file so if the original file is
deleted then the soft link fails.
• If you delete the Soft Link, nothing will happen to file.

Common questions

Powered by AI

Hard links have the same inode number as the original file and act as a mirror copy. Changes to a hard-linked file will reflect in both files, and deleting the hard link doesn't affect the original file, as they share inode numbers . Conversely, soft links (or symbolic links) have different inode numbers and point to the original file path. Deleting an original file makes the soft link a 'dangling' link. Soft links can cross file systems, unlike hard links .

Device files in UNIX are managed through attributes associated with these files, allowing the kernel to identify and operate the devices. Device files do not contain data like regular files; instead, their operation is managed through these attributes. These files are generally found within the /dev directory structure .

In UNIX, devices are represented as files within the /dev directory, underpinning the concept that everything is considered a file. The two primary types of device files are block special files, which handle data in blocks similar to disks, and character special files, which handle data streams like keyboard input. This representation abstracts the devices, allowing standard file operations to manage them .

The single dot (.) represents the current directory, while two dots (..) denote the parent directory. These symbols are used in relative pathnames to navigate the directory structure efficiently. For example, to copy a file within the current directory to a subdirectory, the command can be $cp ./file ./subdir/file, where ./ references the current directory .

An absolute pathname provides a complete file or directory path starting from the root (/), offering exact location, e.g., /home/user/file.txt. A relative pathname relates to the current working directory, useful for concise navigation. For instance, when in /home/user, using cd documents (relative path) versus cd /home/user/documents (absolute path) achieves the same outcome but with differing specificity and context .

The UNIX file system is a hierarchical structure, akin to a tree, with the root directory (denoted by /) at the top. This root directory is the starting point for all paths and holds essential system files and subdirectories. All other directories and files descend from the root, supporting organized storage and retrieval. Key subdirectories under the root include /bin for essential utilities, /boot for boot files, and /dev for device files, among others .

The ls -l command in UNIX shell provides detailed information about files, including permissions. The first character in the output indicates if the item is a file, directory, or link. The next nine characters convey permissions: the first triplet is for the owner, the second for the group, and the third for others. For example, -rw-r--r-- indicates the owner can read and write, while the group and others can only read .

Using the chmod command, you can remove a file's permissions by specifying the target category (such as others) and the permission type to remove. For example, chmod o-r file.txt removes read permissions specifically for others. This action modifies the file's access rights, ensuring only certain groups can read the file .

The chmod command changes file permissions in UNIX using a syntax that includes references (u, g, o for user, group, others), operators (+, -, = for add, remove, set), and modes (r, w, x for read, write, execute). For instance, chmod +x file grants execute permission, while chmod o-r file removes read permission for others. This method allows specific adjustments to file access rights .

To remove a permission from a file in UNIX, the chmod command is used. The procedure involves specifying the category (user, group, others) and the permission type to remove using the '-' operator. For example, chmod g-w file.txt removes the write permission for the group, adjusting the file's access control to limit writing capabilities for group members .

You might also like