Write shell commands to perform the following tasks: Search for a specific word or pattern in a text file. Change the ownership of a file or…

Write shell commands to perform the following tasks:

  1. Search for a specific word or pattern in a text file.
  2. Change the ownership of a file or directory.
  3. Terminate a running process.
  4. Display the first 10 lines of a text file.

From the BUET MSC (CSE) October 2026 – Written exam, question 3 of 14.

Answers (1)

  1. Search for a word or pattern: grep "word" file.txt (add -i to ignore case, -n for line numbers).
  2. Change ownership: chown user:group file (add -R for a directory and its contents).
  3. Terminate a process: kill PID (kill -9 PID to force; pkill name by name).
  4. First 10 lines: head -n 10 file.txt (10 is head’s default, so head file.txt also works).

— rhs

More from this paper