250+ TOP MCQs on Locating Files: find Command and Answers

Unix Multiple Choice Questions on “Locating Files: find Command”.

1. Which command is used for locating files?
a) search
b) find
c) loc
d) type

Answer: b
Clarification: find is one of the most powerful tools of the UNIX system. It recursively examines a directory tree to look for file matching based on some criteria and then takes some action on the selected files.

2. The syntax of the find command is ____________
a) find path_list selection_criteria action
b) find action path_list selection_criteria
c) find selection_criteria action path
d) find path action

Answer: a
Clarification: find command has a very difficult command line, however, find is easily tamed if we break up its arguments into three components. The syntax for using find command is,

$ find  path_list  selection_criteria  action

3. Which symbol is used with find command for specifying arguments?
a) +
b) –
c) + and –
d) |

Answer: c
Clarification: find command searches for a given file according to the arguments specified in the command line. Each argument is preceded by a – (hyphen). For example, to display all files in the current directory having .c extension, use the following command:

$ find .  -name “*.c” -print

4. What will be the output of the following command?

$ find /  -name  a.out  -print

a) all files having filename as a.out
b) all files in the root directory
c) undefined output
d) erroneous

Answer: a
Clarification: The path list (/) indicates that the search will begin from the root directory. Each file in the list is then matched against the selection criteria (a.out). The third section -print is the action taken on the files; i.e. t display matched files on the terminal.

5. We can use relative pathname in the path list while using find command.
a) True
b) False

Answer: a
Clarification: find command allows us to specify the relative pathname in the path list. For example, the following command will display all the .txt files in the current directory.

$ find .  -name “*.txt” -print        // single quotes can also work

6. Which one of the following option is used for locating the files by inode number?
a) -name
b) -inum
c) -inode
d) -ind

Answer: b
Clarification: find command allows us to locate files by their inode number. To do so, we’ve to use the -inum option to find all the filenames having the same inode number. For example,

$ find  /  -inum  13857  -print        // display all the files linked (having same inode number)

7. Which option is used with find command for specifying the file type?
a) -perm
b) -inum
c) -name
d) -type

Answer: d
Clarification: The -type option followed by letter f, d, or l selects files of the ordinary, directory and symbolic link type. For example,

$ find .  -type d  -print        // display all the directory files in the current directory

8. To specify permissions while using find command we have to use _____ option.
a) -perm
b) -inum
c) -name
d) -type

Answer: a
Clarification: The -perm option specifies the permissions to match. For example, -perm 666 selects those files which are having read and write permissions for all categories of users. For example,

$ find $HOME  -perm 666 -type d  -print        // select directories in the home directory having                                                                 666 (in octal) permissions.

9. Which option is used to find command to search for files based on access time?
a) -atime
b) -mtime
c) -time
d) -type

Answer: a
Clarification: find command offers an option which can be used to select files based on access time. For this purpose, we have to use -atime option with the find command. For example,

$ find . -atime -2  -print              //display those files which have been last accessed in less than 2 days

10. Which of the following command will be used to locate those files that have not been modified for more than a year?
a) find . -mtime 1
b) find . -mtime 1 year -print
c) find . -mtime +365 -print
d) find . -mtime -365 -print

Answer: c
Clarification: To select files those file that have not been modified for more than a year, a positive value has to be used with -mtime. Here +365 means more than 365 days whereas -365 is used for less than 365 days.

11. Which of the following operator is used with find command for performing the negate function?
a) -a
b) -o
c) &&
d) !

Answer: d
Clarification: There are three operators that are commonly used with the find command. The ! operator is used before an option to negate its meaning. For example,

$ find . ! -name “*.c” -print        // select all files but not the C program files.

12. Which operator is used to specify the AND condition in find command?
a) !
b) &&
c) -A
d) -a

Answer: d
Clarification: The -a operator when used with find command represents the AND condition and is implied by default when two selection criteria are placed together. For example,

$ find . (-type f  -a -mtime  +2)  -print            // -a 
 can also be omitted ( it is automatically implied by  //  default)

13. -o operator represents the OR condition.
a) True
b) False

Answer: a
Clarification: The -o operator when used with find command represents the OR condition. It is used when we need to specify two or more conditions with an option. An escaped pair of parenthesis is used whenever we use the -o or -a option.

14. Which of the following option is used with find command for taking action on selected files?
a) -exec
b) -atime
c) -mtime
d) -a

Answer: a
Clarification: The -exec option is one of the major option used with the find command. It lets us take any action by running a UNIX command on the selected files. -exec takes the command to execute as its own argument, followed by {} and ;. For example,

$ find  $HOME  -type  f  -atime +365  -exec rm {} ;

Above command will remove all ordinary files not accessed for more than a year.

15. -ok option is used with find command for seeking information before taking the action specified.
a) True
b) False

Answer: a
Clarification: find’s -ok option seeks confirmation before taking the action specified. This provides the user with a facility of giving confirmation before anything goes wrong. For example,

$ find  $HOME  -type  f  -atime +365  -ok rm {} ;

Above command will ask for the user confirmation before removing each selected file.

Leave a Reply

Your email address will not be published. Required fields are marked *