Basic Unix Quiz - 1

Description: Basic Unix Quiz - 1
Number of Questions: 10
Created by:
Tags: unix
Attempted 0/10 Correct 0 Score 0

Which symbol will be used with grep command to match the pattern pat at the beginning of a line?

  1. ^pat

  2. $pat

  3. pat$

  4. pat^


Correct Option: A
Explanation:

To match the pattern "pat" at the beginning of a line using the grep command, the symbol ^ will be used.

Now let's go through each option and explain why it is right or wrong:

A. ^pat: This option is correct. The ^ symbol in a regular expression is used to match the pattern at the beginning of a line. Therefore, ^pat will match the pattern "pat" at the beginning of a line.

B. $pat: This option is incorrect. The $ symbol in a regular expression is used to match the pattern at the end of a line. Therefore, $pat will match the pattern "pat" at the end of a line, not at the beginning.

C. pat$: This option is incorrect. The $ symbol in a regular expression is used to match the pattern at the end of a line. Therefore, pat$ will match the pattern "pat" at the end of a line, not at the beginning.

D. pat^: This option is incorrect. The symbol ^ does not have any special meaning when it appears after the pattern. Therefore, pat^ will match the literal string "pat^" rather than the pattern "pat" at the beginning of a line.

The Answer is: A. ^pat

Which command is used to display the top of the file?

  1. cat

  2. head

  3. more

  4. grep


Correct Option: B

Which command is used to copy all files having the string chap and any two characters after that to the progs directory?

  1. cp chap?? progs

  2. cp chap* progs

  3. cp chap[12] /progs/.

  4. cp chap?? /progs/*


Correct Option: A

AI Explanation

To copy all files having the string "chap" and any two characters after that to the "progs" directory, the correct command is:

A. cp chap?? progs

Explanation: Option A) cp chap?? progs - This option is correct because the command "cp chap??" will copy all files that have the string "chap" followed by any two characters. The copied files will be placed in the "progs" directory.

Option B) cp chap* progs - This option is incorrect because the "*" wildcard symbol matches any number of characters, not just two characters. Therefore, it will copy all files that have the string "chap" followed by any number of characters, not specifically two characters.

Option C) cp chap[12] /progs/. - This option is incorrect because the "[12]" wildcard specifies that either the character "1" or "2" should be present at that position. It does not specify any two characters. Additionally, the "/progs/." path is not needed as the "progs" directory is already specified in the command.

Option D) cp chap?? /progs/* - This option is incorrect because the "/progs/*" path is not needed as the "progs" directory is already specified in the command. Additionally, the "?" wildcard matches any single character, not specifically two characters.

The correct answer is A) cp chap?? progs. This option is correct because it uses the correct wildcard symbol "?" to specify any two characters after the string "chap" and copies the files to the "progs" directory.

Which command is used to change protection mode of files starting with the string emp and ending with 1,2, or 3?

  1. chmod u x emp[l-3]

  2. chmod 777 emp*

  3. chmod u r ??? emp

  4. chmod 222 emp?


Correct Option: A

Which command is used to remove a directory?

  1. rd

  2. rmdir

  3. dldir

  4. rdir


Correct Option: B

Which command is used to extract specific columns from the file?

  1. cat

  2. cut

  3. grep

  4. paste


Correct Option: B
  1. wc infile >newfile

  2. wc newfile

  3. wc infile - newfile

  4. wc infile | newfile


Correct Option: A

Which command is used to remove the read permission of the file 'note' from both the group and others?

  1. chmod go r note

  2. chmod go rw note

  3. chmod go-x note

  4. chmod go-r, 4-x note


Correct Option: D

AI Explanation

To answer this question, we need to understand the chmod command and its options.

The chmod command is used to change the permissions of a file or directory. The permissions include read, write, and execute permissions for the owner, group, and others.

In this question, we want to remove the read permission for both the group and others from the file 'note'.

Let's go through each option to determine the correct command:

Option A) chmod go r note - This option sets the read permission for both the group and others. It does not remove the read permission. Therefore, this option is incorrect.

Option B) chmod go rw note - This option sets both the read and write permissions for both the group and others. It does not remove the read permission. Therefore, this option is incorrect.

Option C) chmod go-x note - This option removes the execute permission for both the group and others from the file 'note'. It does not remove the read permission. Therefore, this option is incorrect.

Option D) chmod go-r, 4-x note - This option removes the read permission for both the group and others from the file 'note'. It uses the symbolic mode of the chmod command. The 'go-r' part removes the read permission, and the '4-x' part is invalid syntax. Therefore, this option is incorrect.

The correct answer is A. chmod go r note. This option is correct because it removes the read permission for both the group and others from the file 'note'.

- Hide questions