This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “Advanced File Handling Commands”.
1. Every file system has a directory structure headed by ____
a) parent
b) child
c) root
d) kernel
View Answer
Explanation: Every file system comprises of a file hierarchy which consists of files and directories held together. Every file system has a directory structure headed by root.
2. Every file is associated with a table which contains all possible information about a file, that table is called as _________
a) info table
b) file table
c) inode
d) ps table
View Answer
Explanation: Every file is associated with a table that contains all the necessary possible information we need to know about a file. This table is called the inode ( shorthand from index node) and this table is accessible using an inode number.
3. Which of the following is not a content of inode?
a) file type
b) file permission
c) file size and links
d) file name
View Answer
Explanation: Every file is associated with a table that contains all the necessary possible information we need to know about a file. This table contains the following attributes of a file:
• file type
• file permissions
• an array of pointers that keeps track of all disk blocks used by the file
• file size and links
• The UID of owner and GID of a group owner
• Date and time of:
o Last access
o Last modification
o Last change of inode
4. Which of the following is not stored in inode?
a) file name
b) inode number
c) file size
d) file name and inode number
View Answer
Explanation: Neither the name of the file nor the inode number associated with it is stored in the inode. It is the directory which stores the inode number along with the filename.
5. Which option is used with ls command for knowing the inode number of the file?
a) -l
b) -i
c) -a
d) -o
View Answer
Explanation: The ls command reads the inode to fetch a file’s attributes. One option i.e. -i tells us the inode number of a file. For example,
$ ls -il abd.txt 9059 -rw-r--r-- 1 kumar metallone 52626 Jan 21 11:54 abd.txt
6. Two files can have a same inode number in the same file system.
a) True
b) False
View Answer
Explanation: No two files in the same file system can have the same inode number unless one of the file is removed. When that happens, the kernel will allocate this inode number to a new file.
7. When we can access a file with multiple filenames, it is said that the file has multiple _____
a) names
b) inode number
c) links
d) uid
View Answer
Explanation: A filename is not stored in the inode because a file can have multiple filenames. When this happens, we say that the file has more than one link, which means that we can access this file using multiple filenames. The number of links associated with a file can be viewed using ls command.
8. Which command is used to link a file with multiple filenames?
a) ln
b) link
c) hl
d) sl
View Answer
Explanation: A file is linked with the ln (link) command, which takes two filenames as arguments. The command can create both hard and soft links. The syntax for creating a hard link is as follows:
$ ln original_filename link_name $ ln emp.lst employee //employee must not exist
9. Which option is used with ln command to create a soft link?
a) -a
b) -l
c) -s
d) -e
View Answer
Explanation: We can also create soft links using ln command. All we have to do is to use -s option along with ln command. For example,
$ ln -s original_filename link_name $ ln -s emp.lst employee
10. A hard-linked file is assigned the same inode number as the original value.
a) True
b) False
View Answer
Explanation: Each hard linked file is assigned the same inode number as the original one, hence they refer to the same physical location. Hard links are more flexible as compared to soft links, as they remain linked even after the original file is removed.
11. If we want to link files across the file systems, we have to use only soft links.
a) True
b) False
View Answer
Explanation: A symbolic link or soft link is same as a shortcut feature in Windows OS. Each soft linked file contains a separate inode number which points to the original file. Soft links are used when we want to link files across the file systems. Soft Link contains the path for original file and not the contents of the file.
12. The default permissions for a regular file are ____ and for directories are ____
a) 777, 666
b) 666, 777
c) 000, 000
d) 777, 777
View Answer
Explanation: When we create a file or a directory, the permissions assigned to them depend on the system’s default settings. The default permissions for regular files in UNIX system are 666 (in octal) or rw-rw-rw- and for directories are 777 (in octal) or rwxrwxrwx.
13. We can change the default permission set for files and directories using ______
a) umask
b) um
c) perm
d) touch
View Answer
Explanation: The permissions of a file/ directory are managed at the time when we create these. The permissions are transformed by subtracting the user mask from it to remove one or more permissions. For example,
$ umask 022
This is an octal number which is subtracted from the system default to obtain the actual default. Hence it will become 644 for ordinary files and 755 for directories. Now if we create any file or directory, the permissions associated will be 644 and 755 respectively.
14. Which command is used to change timestamps associated with a file?
a) touch
b) time
c) umask
d) ls
View Answer
Explanation: A UNIX file has three time stamps associated with it which are:
1. time of last file modification
2. time of last access
3. time of last inode modification
These timestamps are changed using the touch command.
15. When touch command is used without any options or expression, both times are set to current time and the file is created if it doesn’t exist.
a) True
b) False
View Answer
Explanation: When we use the touch command without any options or expression, both modification and access times are set to the current time. The file specified is created if it doesn’t exist. For example,
$ touch emp.txt
16. Which option is used with touch command to change the time of last file modification?
a) -a
b) -m
c) -r
d) -i
View Answer
Explanation: Touch command when used with -m option and an expression will change the modification time of the file. For example,
$ touch -m 02281030 emp.txt ; ls -l emp.txt rw-rw-rw 1 abd metal 870 Feb 28 10:30 emp.txt
17. -a option is used with touch command to alter the time of last access.
a) True
b) False
View Answer
Explanation: Touch command when used with -a option and an expression will change the last access time of the file. For example,
$ touch -a 01261650 emp.txt ; ls -l emp.txt rw-rw-rw 1 abd metal 870 Jan 26 16:50 emp.txt
18. When touch command is used without any option but with an expression, which of the following timestamps are changed?
a) modification time
b) last access time
c) last inode modification
d) modification time and last access time
View Answer
Explanation: When touch command is used without options but with an expression, it changes both access and modification times. The expression is an eight number using the format MMDDhhmm (month, day, hour and minute). For example,
$ touch 03161430 emp.txt ; ls -l emp.txt rw-rw-rw- 1 kumar metal 870 Mar 16 14:30 emp.txt
Sanfoundry Global Education & Learning Series – Unix.
To practice all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Practice Computer Science MCQs
- Practice MCA MCQs
- Check Computer Science Books
- Apply for Computer Science Internship
- Check Unix Books