Tag: unix

Questions Related to unix

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 sort the lines of data in a file in reverse order

  1. sort

  2. sh

  3. st

  4. sort -r


Correct Option: D

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.

  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 of the following keys is used to replace a single character with new text?

  1. S

  2. s

  3. r

  4. C


Correct Option: B
  1. wc infile >newfile

  2. wc newfile

  3. wc infile - newfile

  4. wc infile | newfile


Correct Option: A
  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