Unix Questions and Answers – Locating Files: find Command

This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “Locating Files: find Command”.

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

Answer: b
Explanation: 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
View Answer

Answer: a
Explanation: 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

advertisement
advertisement

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

Answer: c
Explanation: 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:

Note: Join free Sanfoundry classes at Telegram or Youtube
$ find .  -name “*.c” -print

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

advertisement
$ 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
View Answer

Answer: a
Explanation: 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.
advertisement

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

Answer: a
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: c
Explanation: 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) !
View Answer

Answer: d
Explanation: 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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: 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.

Sanfoundry Global Education & Learning Series – Unix.

To practice all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.