250+ TOP MCQs on Deleting and Renaming files: rm and mv Command

Unix Multiple Choice Questions on “Deleting and Renaming files: rm and mv Command”.

1. Which command is used for removing/deleting files in UNIX?
a) rmdir
b) rm
c) del
d) mv

Answer: b
Clarification: rm command is used in UNIX to remove one or more files. It operates silently and should be used with caution. The filename of the file to be deleted is provided as an argument to rm command. For example, following command deletes abd.txt file.

2. We can delete multiple files using a single rm command.
a) True
b) False

Answer: a
Clarification: Multiple files can be deleted in a single go using rm command. All we need to do is, provides multiple filenames as arguments to the rm command.

3. To delete all files in a directory we use ______________
a) rmdir *
b) mv *
c) rm *
d) del *

Answer: c
Clarification: To delete all files in a directory, use (*) with rm command. It acts as a meta-character and delete all files without displaying any message on the terminal. So use this command cautiously.

4. Some files cannot be deleted using rm command because of the permissions associated with it.
a) True
b) False

Answer: a
Clarification: Whether we are able to remove a file depends on the permissions associated with the file/directory. So sometime it may happen that permissions of a file won’t allow us to delete it.

5. Which option is used with rm command for interactive deletion?
a) -i
b) -f
c) -r
d) -R

Answer: a
Clarification: Like in cp command, -i option is also used with rm command for interactive deletion. The prompts asks the user for confirmation before deleting the files.

$ rm  file1  file2  file3
rm: remove file1 (yes/no)? ?y
rm: remove file1 (yes/no)? ?n
rm: remove file1 (yes/no)? [Enter]       // any other response other than y/n leaves the file undeleted

6. Which option performs recursive deletion?
a) -r
b) -R
c) *
d) -r and -R

Answer: d
Clarification: With -r or -R option, rm performs a recursive walk in the file hierarchy and searches for every subdirectories and file within this directory, At each stage, it keeps on deleting everything it finds.

7. Which one of the following command can delete a directory which is not empty?
a) rm -r
b) rmdir
c) rm *
d) del *

Answer: a
Clarification: rm command normally does not remove directories but when it is used with -r option it does. So if we invoke a command like,

$ rm  -r *		// deletes all files in the current directory and all its subdirectories

8. If we wish to delete a remove a file forcefully, we can use ____ option with rm command.
a) -i
b) -r
c) -R
d) -f

Answer: d
Clarification: If a file is write-protected, we can remove it forcefully using -f option of rm command. For example,

$ rm  -f  file.txt	// removes file.txt forcefully

9. Which command is used for removing file named -file.txt?
a) rm -file.txt
b) rm file.txtrm
c) rm — -file.txt
d) rm -f file.txt

Answer: c
Clarification: To delete a file with filename beginning with a ” – “, we have to use ( — ) i.e. double-dash. ” — ” is used so that rm command does not misinterpret the filename as an option.

10. Which command is used for renaming files?
a) rename
b) mv
c) cp
d) move

Answer: b
Clarification: mv command is used for renaming files. This command does not create a copy of the file, it simply renames it. To rename file1 to file2 simply type,

11. If the destination file does not exists, then mv command creates it.
a) True
b) False

Answer: a
Clarification: If the destination file specified in the mv command does not exists it will be simply created. For example, if in the command mv file1 file2, if file2 does not exists then it will be created. Now file1 will be known as filename ‘file2’.

12. What if the destination file specified in mv command already exists?
a) it will be deleted
b) it will not be affected
c) it will be overwritten
d) an error will be produced

Answer: c
Clarification: If the destination file already exists, then the contents of this file will be overwritten with the contents of a source file. For example, mv file01 dir01. If there already exists a file named dir01, then the contents of dir01 will be overwritten with the contents of file01.

13. Apart from renaming files, mv command can also
a) move a file
b) move a group of files
c) rename a directory
d) move a group of files and rename a directory

Answer: d
Clarification: Apart from renaming files, mv command can also move a group of files to a different directory. For example,

$ mv  abd.txt  mash.txt  ryan.txt   main_dir

Above command moves three files to main_dir directory.

14. The inode number associated with a file is changed after renaming it.
a) True
b) False

Answer: b
Clarification: Every file has an inode number associated with it which is maintained by the kernel. This number is not disturbed even if we rename the file. It remains the same no matter how many times we rename the file.

15. Which option is used for backing up destination file in mv command?
a) -b
b) -f
c) -v
d) -i

Answer: a
Clarification: mv command renames the destination file if it already exists but when -b is used, it will add a suffix to the filename. This will save a copy of the original file instead of overwriting it. The default suffix is ( ~ ).

16. Which option is used with mv command so that the destination file does not get overwritten?
a) -n
b) -f
c) -b
d) -i

Answer: a
Clarification: If the destination file already exists in mv command then it will be overwritten which can be harmful. To avoid this we use -n option with mv so that the destination file does not get overwritten. -i option displays interactive messages and asks the user before overwriting the destination file.

17. -f option when used with mv command overwrites existing files without prompting any messages.
a) True
b) False

Answer: a
Clarification: When -f option is used with mv command then, the system will not display any diagnostic messages on to the terminal. It will simply replace the existing file without any warning.

Leave a Reply

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