Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

Which command is used for comparing two files?(a) cmp(b) comp(c) diff(d) commThe question was asked in an online interview.I want to ask this question from Comparing Files:comm, cmp and diff Command in section Handling Ordinary Files of Unix

Answer»

The correct option is (a) cmp

The BEST explanation: cmp command is used for comparing two files byte by byte. It displays the first mismatch and its location on the terminal. It does not bother about subsequent mismatches but displays only the first mismatch. As soon as the first DIFFERENCE is found, the command terminates and outputs the LINE and byte in which there is a difference. For example,

52.

Which option is used for backing up destination file in mv command?(a) -b(b) -f(c) -v(d) -iI had been asked this question during an online exam.I would like to ask this question from Deleting and Renaming files: rm and mv Command topic in portion Handling Ordinary Files of Unix

Answer»

The correct choice is (a) -b

The best explanation: 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( ~ ).

53.

The inode number associated with a file is changed after renaming it.(a) True(b) FalseThe question was posed to me in unit test.This intriguing question comes from Deleting and Renaming files: rm and mv Command in section Handling Ordinary Files of Unix

Answer»

Right option is (b) False

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

54.

Which command is used for renaming files?(a) rename(b) mv(c) cp(d) moveI had been asked this question in a national level competition.The above asked question is from Deleting and Renaming files: rm and mv Command in portion Handling Ordinary Files of Unix

Answer»

The CORRECT CHOICE is (B) mv

Explanation: 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,

55.

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 filesand rename a directoryThis question was addressed to me during an internship interview.The above asked question is from Deleting and Renaming files: rm and mv Command topic in division Handling Ordinary Files of Unix

Answer»

The CORRECT answer is (d) move a group of filesand rename a directory

Best EXPLANATION: Apart from RENAMING files, mv command can also move a group of files to a different directory. For EXAMPLE,

56.

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 producedThe question was posed to me in class test.This intriguing question comes from Deleting and Renaming files: rm and mv Command in chapter Handling Ordinary Files of Unix

Answer»

The correct option is (c) it will be overwritten

Easy explanation: If the destination file already EXISTS, then the contents of this file will be overwritten with the contents of a source file. For EXAMPLE, mvfile01dir01. If there already exists a file NAMED dir01, then the contents of dir01 will be overwritten with the contents of file01.

57.

If the destination file does not exists, then mv command creates it.(a) True(b) FalseI have been asked this question at a job interview.My enquiry is from Deleting and Renaming files: rm and mv Command topic in portion Handling Ordinary Files of Unix

Answer»

Right answer is (a) True

To elaborate: If the destination FILE specified in the mv COMMAND does not EXISTS it will be simply created. For EXAMPLE, if in the command mvfile1file2, if file2 does not exists then it will be created. Now file1 will be KNOWN as filename ‘file2’.

58.

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.txtI had been asked this question in an interview.I need to ask this question from Deleting and Renaming files: rm and mv Command topic in portion Handling Ordinary Files of Unix

Answer»

Correct ANSWER is (C) rm — -file.txt

Easy explanation: 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.

59.

If we wish to delete a remove a file forcefully, we can use ____ option with rm command.(a) -i(b) -r(c) -R(d) -fThis question was posed to me in a job interview.My enquiry is from Deleting and Renaming files: rm and mv Command topic in chapter Handling Ordinary Files of Unix

Answer»

The CORRECT option is (d) -F

The best I can explain: If a file is write-protected, we can REMOVE it forcefully using -f option of rm command. For example,

60.

Which one of the following command can delete a directory which is not empty?(a) rm-r(b) rmdir(c) rm *(d) del *This question was addressed to me in final exam.My doubt is from Deleting and Renaming files: rm and mv Command topic in section Handling Ordinary Files of Unix

Answer»

Correct answer is (a) RM-r

The EXPLANATION: rm COMMAND normally does not REMOVE directories but when it is USED with -r option it does. So if we invoke a command like,

61.

Which option performs recursive deletion?(a) -r(b) -R(c) *(d) -r and -RThe question was asked during an interview.Origin of the question is Deleting and Renaming files: rm and mv Command topic in chapter Handling Ordinary Files of Unix

Answer»

Correct answer is (d) -R and -R

Easy explanation: 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.

62.

Which option is used with rm command for interactive deletion?(a) -i(b) -f(c) -r(d) -RThis question was addressed to me by my college professor while I was bunking the class.My question is taken from Deleting and Renaming files: rm and mv Command in portion Handling Ordinary Files of Unix

Answer»

The CORRECT choice is (a) -i

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

63.

Some files cannot be deleted using rm command because of the permissions associated with it.(a) True(b) FalseI got this question in exam.Asked question is from Deleting and Renaming files: rm and mv Command topic in section Handling Ordinary Files of Unix

Answer»

The correct answer is (a) True

The best explanation: 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.

64.

-v option is used with cp command for displaying _____(a) errors(b) informative messages(c) diagnostic messages(d) file contentsI have been asked this question by my school principal while I was bunking the class.This interesting question is from Copying a File: cp Command in division Handling Ordinary Files of Unix

Answer»

Correct option is (B) INFORMATIVE messages

Easiest explanation: CP -v DISPLAYS the informative messages while copying files about what is HAPPENING. For example,

65.

To delete all files in a directory we use ______________(a) rmdir *(b) mv *(c) rm *(d) del *This question was addressed to me in class test.The query is from Deleting and Renaming files: rm and mv Command in chapter Handling Ordinary Files of Unix

Answer»

Correct choice is (c) rm *

To explain: 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.

66.

We can delete multiple files using a single rm command.(a) True(b) FalseThis question was posed to me during an interview.My question is taken from Deleting and Renaming files: rm and mv Command in section Handling Ordinary Files of Unix

Answer»

Correct option is (a) True

For EXPLANATION: 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.

67.

Which command is used for removing/deleting files in UNIX?(a) rmdir(b) rm(c) del(d) mvThe question was asked during a job interview.This intriguing question originated from Deleting and Renaming files: rm and mv Command topic in chapter Handling Ordinary Files of Unix

Answer»

Correct option is (b) rm

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

68.

$ cp-fcopies forcefully.(a) True(b) FalseThe question was posed to me during an interview.My question is based upon Copying a File: cp Command topic in division Handling Ordinary Files of Unix

Answer»

The correct CHOICE is (a) True

The best I can explain: -f option COPIES forcefully when the permissions ASSOCIATED with a file does not allow PERFORMING the operation.

69.

Which option is used with cp command for linking files instead of copying?(a) -v(b) -l(c) -f(d) -xI had been asked this question in an internship interview.My question is taken from Copying a File: cp Command topic in division Handling Ordinary Files of Unix

Answer»

The correct option is (b) -l

Easy explanation: -l option is USED with cp command for LINKING FILES INSTEAD of copying. When one file has more than one FILENAMES, we say that the file has more than one link. This file can be accessed by more than one filename.

70.

-n option is used with cp command for what purpose?(a) existing file should not be overwritten(b) to update file(c) interactive copying(d) recursive copyingThis question was posed to me in exam.My enquiry is from Copying a File: cp Command topic in section Handling Ordinary Files of Unix

Answer»

Correct OPTION is (a) existing file should not be overwritten

For explanation I would SAY: -n option is used with cp command when we do not WANT to want to overwrite the existing file. It MEANS that if the destination file already EXISTS, then it should not be overwritten.

71.

To copy multiple files, the last destination file should be a directory.(a) False(b) TrueThis question was posed to me in an interview for internship.This interesting question is from Copying a File: cp Command in chapter Handling Ordinary Files of Unix

Answer»

Right answer is (b) True

The EXPLANATION: We can copy multiple files using a single INVOCATION of cp command. To do so, the LAST name SPECIFIED should be a DIRECTORY. For example,cp file1file2file3dir_one. It will copy all the three files to the directory named dir_one.

72.

What does -i option do?(a) interactive copying(b) recursively copying(c) updating(d) none of the mentionedI got this question in semester exam.My question comes from Copying a File: cp Command in chapter Handling Ordinary Files of Unix

Answer» RIGHT option is (a) interactive copying

The explanation is: (-i) option is used for interactive copying. It means that suppose if we invoke a command like cp file1file2 and if file2 already EXISTS then it will be overwritten which can be a nightmare for many USERS. To AVOID this, we use -i option. It provides us with a warning before OVERWRITING a file. It asks the user whether to overwrite the file or not. The syntax is cp-i source_filedest_file.
73.

Sometimes it is not possible to copy a file.(a) True(b) FalseThis question was posed to me in my homework.My query is from Copying a File: cp Command topic in chapter Handling Ordinary Files of Unix

Answer»

Correct option is (a) True

The explanation is: Sometimes it may HAPPEN that we cannot copy a FILE because of the permissions associated with it. For EXAMPLE, If the permissions associated with a file are read-protected then we cannot copy the file.

74.

How can we copy an entire directory under another directory?(a) using -R option(b) using -a option(c) using -u option(d) none of the mentionedThe question was posed to me by my school teacher while I was bunking the class.Asked question is from Copying a File: cp Command in section Handling Ordinary Files of Unix

Answer»

The CORRECT CHOICE is (a) using -R option

Easy explanation: -R option is used to copy an entire directory structure into another one recursively. Here recursively means that the command can DESCEND a directory and examine all the files in its subdirectories and then it will copy the entire structure. For example,cp-R prog_onenew_prog. It will create a copy of contents of entire directory prog_one to new_prog if new_prog does not exist. OTHERWISE, if new_prog EXISTS as a directory,then the whole structure of prog_one will be copied under new_prog as a subdirectory.

75.

How can we copy a file into our current directory?(a) cp file1(b) cp file1(c) cp file*(d) none of the mentionedI have been asked this question by my college professor while I was bunking the class.My doubt stems from Copying a File: cp Command topic in chapter Handling Ordinary Files of Unix

Answer»

Right option is (b) cp file1

For EXPLANATION: For creating a copy of a file into our CURRENT WORKING directory we use the shorthand NOTATION (.). For example,cp file1.will create a copy of file1 into our current working directory with the same NAME.

76.

What is the correct syntax for copying multiple files with a filename starting as ‘file’ into another file named as‘directory_one’?(a) cp -i filedirectory_one(b) cp -R filedirectory/directory_one(c) cp file*directory_one(d) none of the mentionedI have been asked this question in an internship interview.Origin of the question is Copying a File: cp Command topic in chapter Handling Ordinary Files of Unix

Answer»

The correct ANSWER is (c) cp FILE*directory_one

Easy explanation: For copying multiple files with a common starting name such as (file, FILE001, file.txt, fileone.jpg, file-archive.zip) we use (“*”). An asterisk (“*”) is a wildcard – a special CHARACTER which EXPANDS to match other characters.For example,cp file*directory_one will copy all the files whose name will be starting with ‘file’into‘directory_one’ file.

77.

Which of the following is not an option of cp command?(a) -z(b) -i(c) -R(d) -uThe question was asked in exam.Asked question is from Copying a File: cp Command in portion Handling Ordinary Files of Unix

Answer» CORRECT choice is (a) -z

For explanation: cp command has MANY options available, each of which performs a unique task. (-i)is used for interactive copying (i.e.) it warns the USER before overwriting the DESTINATION file.(-R) is used for copying the entire directory structure into another directory structure. (-u) copies only when the source file is newer than the destination file.
78.

What happens if the destination file specified in cp command does not exist?(a) file will not be copied(b) an error will be produced(c) destination file will be automatically created(d) none of the mentionedThis question was posed to me in quiz.This is a very interesting question from Copying a File: cp Command in chapter Handling Ordinary Files of Unix

Answer» RIGHT choice is (c) destination FILE will be automatically created

For explanation: If the destination file does not exist, then cp command will automatically create a file with the same NAME and then it copies the contents of the source file to the file which is created.If the destination file already EXISTS, then it will be overwritten with the contents of the source file.
79.

What is the function of cp command in UNIX?(a) list all the available files in the current directory(b) delete a given file(c) cp is a command used for copying files and directories(d) change the directoryI got this question in homework.My question is based upon Copying a File: cp Command topic in portion Handling Ordinary Files of Unix

Answer» RIGHT option is (c) cp is a command used for COPYING files and directories

Explanation: cp command is BASICALLY used for CREATING a copy of source file or a group of files. The syntax of the command requires at least two filenames to be SPECIFIED. If both the files specified are ordinary files, the first file will be copied to the second file. The syntax of cp command is cp source_filenamedestination_filename. The contents of the source file will be copied to the destination file in the same directory.
80.

Which option is used with touch command which forces the command not to create file, if it does not exists.(a) -h(b) -c(c) -t(d) -fI got this question by my college professor while I was bunking the class.The above asked question is from Displaying and Creating Files: cat Command in section Handling Ordinary Files of Unix

Answer»

Correct OPTION is (b) -c

Explanation: In case if there is a strict REQUIREMENT that touch command should not create a new file, we can use the -c option with it. Else if the file already exists then it will do nothing.

81.

Which one of the following commands is incorrect?(a) catfile01(b) cat > file01(c) cat >> file1(d) cat-a file01The question was asked in final exam.This intriguing question originated from Displaying and Creating Files: cat Command topic in portion Handling Ordinary Files of Unix

Answer»
82.

Which command is used to create empty files?(a) cp(b) cat(c) touch(d) createThe question was posed to me in unit test.My question is taken from Displaying and Creating Files: cat Command in section Handling Ordinary Files of Unix

Answer»

The correct choice is (d) create

To explain I would SAY: Touch command changes timestamps. It is ALSO an easy way to create empty files.

The only argument required to be specified with touch command is the filename of the FILE to be CREATED.

83.

Which of the following cannot be performed by cat command?(a) displaying files(b) creating files(c) appending files(d) deleting filesThe question was asked by my school teacher while I was bunking the class.Question is from Displaying and Creating Files: cat Command in division Handling Ordinary Files of Unix

Answer»

Right option is (d) deleting files

For explanation I would SAY: CAT command cannot delete files. It can only be used for viewing file contents, creating a file or appending to an existing file.

84.

What does cat file01file01file01 display?(a) error(b) blank terminal(c) contents of file01 three times successively(d) contents of file01 single timeThis question was posed to me in final exam.Origin of the question is Displaying and Creating Files: cat Command topic in division Handling Ordinary Files of Unix

Answer»

Correct choice is (C) CONTENTS of file01 three times successively

For explanation: When multiple filenames are SPECIFIED as arguments with cat COMMAND, it concatenates the contents of all the files specified as arguments and displays the OUTPUT on the terminal.

85.

Which option is used with the cat command for displaying file with line numbers?(a) -n(b) -v(c) -a(d) -xI have been asked this question in homework.My doubt is from Displaying and Creating Files: cat Command in division Handling Ordinary Files of Unix

Answer»

Right choice is (a) -n

For explanation: cat command SUPPORTS -n option which is USED for displaying FILE CONTENTS along with line number while -v is used for displaying nonprintable ASCII CHARACTERS in the file.

86.

Which symbol is used to append an existing file?(a) >(b) >(d) $I have been asked this question during an online exam.Query is from Displaying and Creating Files: cat Command in chapter Handling Ordinary Files of Unix

Answer»

Right ANSWER is (c) >>

To EXPLAIN I WOULD say: cat command overwrites the existing file if we try to create another file with a similar filename as an existing file. To avoid this we can use the >> operator. For EXAMPLE, if file01 already exists and we want to append it, then use the following command:

87.

Which option is used with cat command for displaying non-printable characters?(a) -v(b) -n(c) -x(d) -aI had been asked this question in an online quiz.My doubt stems from Displaying and Creating Files: cat Command in portion Handling Ordinary Files of Unix

Answer»

Correct answer is (a) -v

To elaborate: If the FILE that we WANT to display CONTAINS nonprintable ASCII characters, then to display those characters we use -v option with the cat command. -n option is used for displaying the contents of the file along with line numbers.

88.

If we create a file using cat command with the same filename which already exists in the current directory then,(a) existing file is deleted(b) new file will be created separately(c) existing file will be overwritten(d) an error will be producedI had been asked this question in an online interview.This key question is from Displaying and Creating Files: cat Command in division Handling Ordinary Files of Unix

Answer»

Right choice is (c) EXISTING file will be overwritten

For EXPLANATION I WOULD say: As cat command is ALSO used to create files, so if we want to create a file with the same filename which already exists in the DIRECTORY then the existing file will be overwritten.

89.

Which symbol is used with cat command for creating files?(a) >(b)

Answer»

Right OPTION is (a) >

Explanation: > symbol acts as a redirection symbol and RECORDS the input ENTERED by the user in the specified file. For EXAMPLE,

90.

Multiple arguments as filenames can be specified in cat command.(a) True(b) FalseThe question was posed to me in exam.Question is from Displaying and Creating Files: cat Command in portion Handling Ordinary Files of Unix

Answer»

Right OPTION is (a) True

For explanation: cat, like several other UNIX commands can accept more than ONE FILENAME as arguments. For EXAMPLE,

91.

Which command is used for displaying contents of a file?(a) cp(b) rm(c) cat(d) mkdirI had been asked this question in my homework.Question is taken from Displaying and Creating Files: cat Command topic in portion Handling Ordinary Files of Unix

Answer»

The correct option is (c) cat

For explanation: cat command is used to DISPLAY the contents of a file. For displaying the contents, simply invoke the cat command with the filename (whose contents are to be DISPLAYED) as an ARGUMENT. For EXAMPLE, if abd.txt file contains “HELLO WORLD” then,

92.

Apart from displaying file contents, cat command is also used for _____ files.(a) displaying(b) deleting(c) copying(d) creatingThe question was posed to me in an interview for job.My enquiry is from Displaying and Creating Files: cat Command topic in section Handling Ordinary Files of Unix

Answer» RIGHT CHOICE is (d) creating

For explanation: cat command is one of the most well-known commands of the UNIX system. It is generally used to DISPLAY the contents of a file on the terminal but can also be used for creating files. SUPPOSE to create a file abd.txt, type the following command