This set of Unix MCQs focuses on “Using test and [ ] to Evaluate Expressions – 2”.
1. Which one of the following option is used for checking that the string is NULL string?
a) -a
b) -o
c) -z
d) -n
View Answer
Explanation: test can be used to compare strings with another set of operators. -z is used for checking if the string is null. For example,
If [ -z “$fname ] ; then echo “NULL string”
2. We can use a test to test various file attributes.
a) True
b) False
View Answer
Explanation: test can also be used to test the various file attributes like its type (ordinary, regular or symbolic link) or its permissions (read, write, execute, etc).
3. Which option is used for checking if the file exists or not?
a) -e
b) -a
c) -n
d) -f
View Answer
Explanation: test can also be used to test the various file attributes like its type (ordinary, regular or symbolic link). To check whether the file exists or not, we can use the -e option. For example,
If [ -e $1 ]; then echo “ file exists”
4. Which of the following option is used for checking if the file is readable or not?
a) -r
b) -f
c) -n
d) -z
View Answer
Explanation: To check if the file exists and is readable we can use -r option. The syntax is -r filename.
5. Which of the following option is used for checking if the file is writable or not?
a) -e
b) -f
c) -n
d) -w
View Answer
Explanation: To check if the file exists and is writable we can use -w option. The syntax is -w filename.
6. To check if the file exists and is executable we have to use ___ option with test.
a) -e
b) -f
c) -x
d) -w
View Answer
Explanation: If we want to check whether the file exists and is executable we have to use the -x option. The syntax is -x filename.
7. -d option is used for checking if the file exists and is a directory.
a) True
b) False
View Answer
Explanation: If we want to check whether the file exists and is a directory we have to use the -d option. The syntax is -d filename.
8. ____ option is used for checking whether a particular file is older than a specified file.
a) -ef
b) -old
c) -nt
d) -ot
View Answer
Explanation: If we have two file namely file01 and file02 and we want to check if file01 is older than file02, we have to use -ot option with test. The syntax is file01 -ot file02. Similarly, to check whether file01 is newer than file02 we’ve to use -nt option. These commands work in korn and bash shell only.
9. To check if two files are linked to each other, we can use -ef option.
a) True
b) False
View Answer
Explanation: If we have two files namely file01 and file02 and we want to check if file01 is linked with file02, we have to use -ef option with test. The syntax is file01 -ef file02.
Sanfoundry Global Education & Learning Series – Unix.
To practice all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check Computer Science Books
- Check MCA Books
- Apply for Computer Science Internship
- Practice MCA MCQs
- Practice Computer Science MCQs