GHOUSIA COLLEGE OF ENGINEERING, RAMANAGARAM-562159
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
.Question 1: Understanding Basic File Attributes
(a) Explain the output of the ls -l command. (6 marks)
The ls -l command provides a detailed listing of files and directories. A typical output line is:
-rwxr-xr-- 1 user group 1024 Jan 1 12:00 filename
Breakdown:
● -rwxr-xr--: File type and permissions.
● 1: Number of hard links.
● user: Owner of the file.
● group: Group associated with the file.
● 1024: File size in bytes.
● Jan 1 [Link] Last modification date and time.
● filename: Name of the file.
(b) What is the purpose of the -d option in the ls command? (4 marks)
The -d option in the ls command is used to list directory entries themselves, rather than their
contents. For example, ls -ld /home/user will display information about the /home/user
directory, not its contents.
(c) Describe how file permissions are represented and their significance. (10 marks)
File permissions in UNIX are represented by a 10-character string, such as -rwxr-xr--.
Breakdown:
● First character: Indicates the file type (- for regular file, d for directory, l for symbolic
link, etc.).
● Next nine characters: Represent permissions in three sets of three:
○ User (owner): rwx
○ Group: r-x
○ Others: r--
Each set includes:
● r: Read permission.
● w: Write permission.
● x: Execute permission.
These permissions control the actions that users can perform on files and directories.
Question 2: Managing File Permissions
(a) How does the chmod command modify file permissions? Provide examples using both
symbolic and numeric modes. (10 marks)
The chmod command changes the permissions of files and directories.
● Symbolic mode: Uses symbols to represent permissions.
Example: chmod u+x [Link] adds execute permission for the user.
● Numeric mode: Uses octal numbers to set permissions.
Example: chmod 755 [Link] sets permissions to rwxr-xr-x.
(b) Explain the concept of users and groups in UNIX. (6 marks)
In UNIX, each file is owned by a user and associated with a group. Users are individual
accounts, while groups are collections of users. Permissions can be set separately for the user,
group, and others, allowing for flexible access control.
(c) What is the significance of the umask command? (4 marks)
The umask command sets the default permission mask for newly created files and directories. It
determines which permission bits will be turned off. For example, a umask of 022 results in new
files having permissions of 644 (rw-r--r--) and directories 755 (rwxr-xr-x).
Question 3: Security and File Permissions
(a) Discuss the importance of file permissions in system security. (6 marks)
File permissions are crucial for system security as they control access to files and directories.
Properly set permissions prevent unauthorized users from reading, modifying, or executing
sensitive files, thereby protecting the system from potential breaches.
(b) How can ownership and group of a file be changed? Provide examples. (6 marks)
Ownership and group of a file can be changed using the chown and chgrp commands.
● To change the owner: chown newowner [Link]
● To change the group: chgrp newgroup [Link]
● To change both: chown newowner:newgroup [Link]
(c) What are the special permission bits in UNIX? Explain their uses. (8 marks)
UNIX has three special permission bits:
● Setuid (s): When set on an executable file, users can execute the file with the
permissions of the file owner.
● Setgid (s): When set on an executable, users execute the file with the permissions of
the group owner. When set on a directory, new files inherit the group of the directory.
● Sticky bit (t): When set on a directory, only the file owner can delete or rename files
within it, commonly used in shared directories like /tmp.
Question 4: Understanding File Attributes
(a) Differentiate between hard links and symbolic links. (6 marks)
● Hard link: A direct reference to the file's data on disk. Multiple hard links to a file share
the same inode number. Deleting one hard link does not affect the others.
● Symbolic link (symlink): A separate file that points to another file's path. It has its own
inode and can span across file systems. If the target file is deleted, the symlink becomes
broken.
(b) How is the find command used to locate files? Provide examples. (6 marks)
The find command searches for files and directories based on specified criteria.
Examples:
● Find files named [Link]: find / -name [Link]
● Find files modified in the last 7 days: find /path -mtime -7
● Find files larger than 1MB: find /path -size +1M
(c) Explain how file attributes can be viewed and modified. (8 marks)
File attributes can be viewed using the lsattr command and modified with chattr.
● View attributes: lsattr [Link]
● Set the immutable attribute: chattr +i [Link] (prevents modification or deletion)
● Remove the immutable attribute: chattr -i [Link]
These attributes provide an additional layer of security and control over file behavior.
Question 5: File System Navigation and Management
(a) Describe the structure of the UNIX file system. (6 marks)
The UNIX file system is a hierarchical structure starting from the root directory /. All files and
directories branch from this root, forming a tree-like structure. Key directories include:
● /bin: Essential binary executables.
● /etc: System configuration files.
● /home: User home directories.
● /var: Variable files like logs.
(b) How do absolute and relative pathnames differ? Provide examples. (6 marks)
● Absolute pathname: Specifies the complete path from the root directory.
Example: /home/user/documents/[Link]
● Relative pathname: Specifies the path relative to the current working directory.
Example: If the current directory is /home/user, then documents/[Link] is a
relative path.
(c) Explain the use of the cd, mkdir, and rmdir commands. (8 marks)
● cd: Changes the current directory.
Example: cd /home/user
● mkdir: Creates a new directory.
Example: mkdir new_folder
● rmdir: Removes an empty directory.
Example: rmdir old_folder
These commands are fundamental for navigating and managing the file system.
Continuing from Question 6 on advanced file permissions:
Question 6: Advanced File Permissions
(a) What is the effect of the umask value on file creation? (6 marks)
The umask (user file creation mode mask) determines the default permission bits that are
disabled when new files or directories are created. It acts as a filter that removes specific
permissions from the system's default settings.
● Default permissions:
○ Files: 666 (read and write for owner, group, and others)
○ Directories: 777 (read, write, and execute for owner, group, and others)
● Calculation: Final permissions = Default permissions - umask
Example: If umask is 022:
○ Files: 666 - 022 = 644 → rw-r--r--
○ Directories: 777 - 022 = 755 → rwxr-xr-x
This ensures that new files and directories do not have more permissive settings than
intended.
(b) How can you view and set the umask value? (4 marks)
View current umask: Use the umask command without arguments:
umask
●
Set umask: Provide the desired mask value as an argument:
umask 027
●
This sets the umask to 027, which removes write permissions for group and all
permissions for others.
(c) Discuss the implications of setting a restrictive umask value. (10 marks)
Setting a restrictive umask enhances security by limiting default permissions:
● Example: A umask of 077 results in:
○ Files: 666 - 077 = 600 → rw-------
○ Directories: 777 - 077 = 700 → rwx------
This configuration ensures that only the file owner has access, preventing unintended
access by group members or others. However, overly restrictive umask settings can
hinder collaboration if group access is necessary. Therefore, it's essential to balance
security needs with usability.
Question 7: Understanding File Ownership and Group
Management
(a) Explain the significance of file ownership in UNIX. (6 marks)
In UNIX, every file and directory is associated with an owner (user) and a group. The
owner is typically the user who created the file, and the group is a collection of users.
Ownership determines the default permissions and access control for files, ensuring that
only authorized users can read, write, or execute them.
(b) How can you change the ownership and group of a file? Provide examples. (6 marks)
Change ownership: Use the chown command.
chown newowner filename
●
Change group: Use the chgrp command.
chgrp newgroup filename
●
Change both owner and group: Use chown with colon-separated values.
chown newowner:newgroup filename
●
Example:
chown alice:developers [Link]
This command changes the owner of [Link] to alice and the group to
developers.
(c) Discuss the implications of improper file ownership settings. (8 marks)
Improper file ownership can lead to security vulnerabilities and operational issues:
● Unauthorized Access: Files owned by unintended users may be accessed or
modified without proper authorization.
● Data Integrity Risks: Critical system files owned by non-administrative users can
be altered, compromising system stability.
● Audit and Compliance Issues: Incorrect ownership can hinder tracking of user
activities, affecting compliance with security policies.
● Operational Errors: Scripts or applications may fail if they lack appropriate
ownership, leading to service disruptions.
Question 8: Exploring File Links and Their Uses
(a) Differentiate between hard links and symbolic (soft) links. (6 marks)
● Hard Link:
○ Points directly to the inode of a file.
○ Cannot span across different file systems.
○ Deleting the original file does not affect the hard link.
● Symbolic (Soft) Link:
○ Points to the pathname of the target file.
○ Can span across different file systems.
○ Deleting the original file renders the symbolic link broken.
(b) How do you create hard and symbolic links? Provide examples. (6 marks)
Create a hard link:
ln [Link] [Link]
●
Create a symbolic link:
ln -s [Link] [Link]
●
Example:
ln [Link] report_hardlink.doc
ln -s [Link] report_symlink.doc
(c) Discuss scenarios where symbolic links are preferred over hard links. (8 marks)
Symbolic links are preferred in the following scenarios:
● Cross-File System Linking: When linking files across different file systems.
● Directory Linking: Hard links cannot be created for directories (to prevent circular
references), but symbolic links can.
● Ease of Identification: Symbolic links are easily identifiable and can be managed
separately.
● Dynamic Linking: Symbolic links can point to files that may not exist at the time of
link creation, allowing for flexible file management.
Question 9: Utilizing the find Command for File
Management
(a) Explain the purpose of the find command in UNIX. (6 marks)
The find command is used to search for files and directories within a directory hierarchy
based on various criteria such as name, size, type, modification time, and permissions. It
is a powerful tool for locating files and performing actions on them.
(b) Provide examples of using find with different options. (6 marks)
Find files by name:
find /home/user -name "[Link]"
●
Find files by type:
find /var/log -type f
●
Find files modified in the last 7 days:
find /etc -mtime -7
●
Find files larger than 10MB:
find /home/user -size +10M
●
(c) How can find be combined with other commands for advanced operations? (8 marks)
The find command can be combined with other commands using the -exec option or by
piping its output to other commands:
Delete files:
find /tmp -type f -name "*.log" -exec rm {} \;
●
Change permissions:
find /var/www -type f -exec chmod 644 {} \;
●
List files and count them:
find /home/user -type f | wc -l
●
These combinations allow for efficient file management and automation of repetitive
tasks.