0% found this document useful (0 votes)
5 views

Answers for Plattech From Self Test

The document contains a series of self-test questions and answers related to UNIX/Linux commands and scripting. It covers various topics including the role of the kernel, command-line utilities, file system navigation, and text editing in different editors. Each question is followed by the correct answer and a brief explanation of the reasoning behind it.

Uploaded by

james lacson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Answers for Plattech From Self Test

The document contains a series of self-test questions and answers related to UNIX/Linux commands and scripting. It covers various topics including the role of the kernel, command-line utilities, file system navigation, and text editing in different editors. Each question is followed by the correct answer and a brief explanation of the reasoning behind it.

Uploaded by

james lacson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

SELF TEST 1

1. What is the role of the kernel in UNIX/Linux?

○ a. To allocate resources and manage hardware

2. If a user types calm, what will the calendar display?

○ d. The current month's calendar with Monday as the first day of the

week

3. What does the GNU in "GNU/Linux" stand for?

○ c. Gnu's Not Unix

4. How can a user change the shell they are currently using?

○ d. Type the desired shell's name (e.g., bash)

5. Which command-line editing feature allows you to execute a previously

used command?

○ c. Command history

6. What is the significance of the file /etc/passwd in UNIX/Linux?

○ d. Contains user account information

7. Which command is best suited for clearing all current output in the

terminal window?

○ a. clear

8. What is the primary purpose of using the telnet command?

○ d. To establish a remote terminal session


9. Which component of UNIX/Linux is responsible for interpreting user

commands?

○ c. Shell

10. What does the man command's -K option allow you to do?

○ c. Search for a specific keyword across all man pages

11. What does the who am i command display?

○ d. The user account logged in on the terminal

12. Why is SSH considered more secure than Telnet?

○ d. SSH encrypts communications, whereas Telnet does not

13. Which system utility is responsible for providing a graphical user

interface in UNIX/Linux?

○ a. X Window System

14. What is a significant advantage of the layered structure of UNIX/Linux?

○ b. Protects hardware by restricting access to the kernel

15. What is the output of the command date -u?

○ c. UTC time and date

16. Which shell is the default for most Linux distributions and includes

features from both the Korn and Bourne shells?

○ c. Bash shell
17. Which file system feature allows multiple users to access the same

resources simultaneously?

○ d. Multiuser capability

18. What is the maximum length of a user name supported by most modern

Linux distributions?

○ c. 32 characters

19. What happens when the passwd command is run without any

arguments?

○ a. The current user is prompted to change their password

20. What is the main difference between a peer-to-peer and server-based

network?

○ c. Server-based networks rely on centralized resource management

21. What does the cd.. command do?

○ d. Moves to the parent directory

22. How do you list hidden files in a directory?

○ a. ls -a

23. What is the function of the mount command?

○ d. Connect a directory to the root hierarchy

24. Which command changes a directory's ownership?

○ a. chown
25. Which command removes an empty directory?

○ b. rmdir

26. Which of the following is NOT part of the standard Linux directory

hierarchy?

○ d. /documents

27. What does . (dot) signify in file system navigation?

○ a. Current directory

28. What does the /proc directory contain?

○ d. Information about running processes

29. The /var directory typically stores:

○ b. Log files and variable data

30. The command chmod 750 file:

○ b. Grants read, write, and execute permissions to the owner; read and

execute to the group; no access for others

31. What is the /mnt directory commonly used for?

○ b. Mounting temporary file systems

32. How can you protect a file from being modified or deleted by anyone

except the owner?

○ a. chmod 700 file

33. What is the primary role of inodes in a Linux file system?


○ b. Track file permissions and metadata

34. What type of file system structure is used in UNIX/Linux?

○ a. Tree-based hierarchical

35. What does the ls -l command display?

○ b. Files in long format with detailed information

36. What does the command pwd display?

○ b. Present working directory path

37. How does the find /home -name "*.txt" command function?

○ d. Searches for.txt files in /home and subdirectories

38. The /dev directory contains:

○ d. Device files

39. Which directory is used for system-wide configuration files?

○ a. /etc

40. What does the umask command do?

○ a. Sets default permissions for new files

SELF TEST 2

1. Which command allows you to delete a single line in the vi editor?

○ a. dd
2. How do you undo the last command in vi?

○ c. u

3. In vi, which command is used to search for the word "error"?

○ c. /error

4. What does the command :%s/foo/bar/g do in vi?

○ c. Searches for "foo" and replaces it with "bar" globally.

5. In nano, which command saves the current file?

○ d. Ctrl+O

6. Which mode must you enter in vi to start inserting text?

○ c. Insert mode

7. To move the cursor to the end of a line in vi, you use:

○ d. $

8. How do you quit vi without saving changes?

○ a.:q!

9. In nano, what does the Ctrl+K command do?

○ a. Cuts the current line.

10. In Emacs, how do you search for a specific string?

○ b. Ctrl+S

11. Which of the following commands saves and exits a file in vi?
○ a.:wq

12. How do you switch from insert mode back to command mode in vi?

○ c. ESC

13. In vi, which command yanks (copies) a single word?

○ a. yw

14. To delete from the current position to the end of the line in vi, use:

○ d. D

15. Which command in nano searches for a string?

○ a. Ctrl+S

16. What does the sort command do?

○ b. Arranges lines in alphabetical or numerical order.

17. Which command extracts specific columns from a file?

○ d. cut

18. How do you merge two files based on a common field?

○ a. join

19. The wc command is used for:

○ d. Counting the number of lines, words, and characters in a file.

20. How do you display the first 10 lines of a file?

○ a. head
21. Which option for grep ignores case sensitivity?

○ d. -i

22. Which command removes duplicate lines in a file?

○ a. uniq

23. The tail command displays:

○ c. The last few lines of a file.

24. How do you concatenate files and display the output?

○ c. cat

25. Which command displays only the differences between two files?

○ b. diff

26. Which option in awk specifies a field delimiter?

○ b. -F

27. To count the number of lines in a file, use:

○ c. wc -l

28. Which sed command appends text to the end of a line?

○ b. s/$/text/

29. What does the cut -f1,3 command do?

○ d. Extracts fields 1 and 3 from each line of a file.

30. Which command combines the contents of two files line by line?
○ a. paste

31. What does the pipe operator | do?

○ d. Passes the output of one command as input to another.

32. Which command is used to search for a specific pattern in a file?

○ d. grep

33. What does the uniq command require to work properly?

○ c. A sorted input file

34. Which option in grep displays line numbers of matches?

○ d. -n

35. What is the purpose of the tr command?

○ d. Translating or deleting characters in a file.

36. Which sed command replaces the word "error" with "fixed" in a file?

○ a. sed 's/error/fixed/'

37. What does the wc -w command display?

○ b. Number of words in a file

38. Which command is used to format file output into columns?

○ d. pr

39. What does the diff command do?

○ b. Displays the differences between two files line by line.


40. Which command combines two files horizontally (side by side)?

○ c. paste

41. How does the comm command display output?

○ a. Displays three columns: unique to file 1, unique to file 2, and

common lines.

42. Which command prints only the unique lines between two files?

○ d. comm -1

43. Which awk command prints the 2nd and 4th fields of a file?

○ b. awk '{print $2 $4}'

44. How do you delete a specific line (e.g., line 5) in a file using sed?

○ c. sed '5d'

45. What is the purpose of the cut -d: -f2 command?

○ c. Extracts the second field from a file using : as the delimiter.

SELF TEST 3

1. How would you modify the script to only display even Fibonacci

numbers?

○ f. Only choices X & Y work.

2. What happens if the input is -3?

○ f. The script outputs: Error: Input must be a positive integer.


3. If the input is 6, what is the output of the script?

○ d. 0 1 1 2 3 5

4. Which part of the script updates the Fibonacci sequence?

○ c. $temp=$((a+b)); $a=$b; $b=$temp

5. How would you modify the script to generate Fibonacci numbers until

the value exceeds 1000?

○ f. All of the methods (X, Y and Z) GIVEN work.

6. If the input is root, what does the script output on a typical Linux

system?

○ a. User root exists. Home Directory: /root, Shell: /bin/bash, Last Login:

Wed Jan 24 14:00

7. How would you modify the script to also display the user's UID and GID?

○ f. All of the above methods work(X,Y,Z).

8. How does the script handle last login information if the user has never

logged in?

○ f. Outputs: Last Login: Never

9. What happens if the input is nonexistentuser?

○ f. User nonexistentuser does not exist.

10. What command retrieves the user's home directory?

○ d. getent passwd "$username" | cut -d: -f6


11. What happens if the file /dev/null is passed to the script?

○ c. None of the choices.

12. What command retrieves the target of a symbolic link?

○ a. readlink "$file"

13. If the input is /tmp/symlink, which is a symbolic link pointing to

/var/log/messages, what is the output?

○ b. /tmp/symlink is a symbolic link pointing to /var/log/messages.

14. How can the script be modified to count files in a directory if the input is

a directory?

○ f. Only W, X and Y are valid.

15. If the input is /etc (a directory with a size of 20M), what is the output?

○ e. /etc is a directory. Size: 20M

16. What happens if the input threshold is 1018?

○ c. Error: Threshold must be a valid number between 1 and 100.

17. What happens if a partition does not exist?

○ d. Outputs: Error: Partition <partition> does not exist.

18. If the input partitions are / and /home with usage at 75 and 45%, and the

threshold is 50%, what is the output?

○ b. Warning: / usage is at 75%, exceeding threshold. /home usage is at

45%, below threshold.


19. Which part of the script validates threshold input?

○ d. All of the ABOVE ($(X,Y,Z).)

20. How would you modify the script to display free space in GB for each

partition?

○ a. CHOICE X: Add free_space=$(df -h "$partition" | tail -1 |

awk '{print $4}').

21. What happens if the user inputs abc instead of a number?

○ d. Invalid input. Please enter a numeric value.

22. What happens if the user guesses the correct number on their 4th

attempt?

○ c. Correct! The number was <target>. You guessed it in 4 attempt(s).

23. What happens if the user reaches the maximum number of attempts

without guessing the correct number?

○ f. Sorry, you've reached the maximum number of attempts. The correct

number was <target>.

24. How would you modify the script to provide a range hint after each

guess?

○ f. Implement all of the above methods (X,Y,Z) for dynamic range hints.

25. What happens if the target number is 75, the user guesses 50 on their

first attempt, and this is their 3rd overall attempt?

○ b. Too low. Hint: The number is greater than 50. Attempts remaining: 2
SELF TEST 3 ANOTHER VER

Here are the answers with explanations based on the provided document:

1. How would you modify the script to only display even Fibonacci numbers?
Answer: f. Only choices X & Y work.
Explanation:

○ Choice X: if [ $((a % 2)) -ne 0 ]; then continue; fi ensures


only even numbers are printed.
○ Choice Y: echo $a only if a is even achieves the same goal.
○ Other options are either incorrect or inefficient.
2. What happens if the input is -3?
Answer: f. The script outputs: Error: Input must be a positive integer.
Explanation: Negative numbers are invalid for Fibonacci series computation, so an
error message is expected.

3. If the input is 6, what is the output of the script?


Answer: d. 0 1 1 2 3 5
Explanation: The Fibonacci sequence starts from 0,1, and the next numbers are
computed by summing the last two, up to 6 terms.

4. Which part of the script updates the Fibonacci sequence?


Answer: a. temp=$((a + b)); b=$a; a=$temp
Explanation: This correctly updates the sequence by setting temp to the sum of a
and b, then shifting values accordingly.

5. How would you modify the script to generate Fibonacci numbers until the
value exceeds 1000?
Answer: f. All of the methods (X,Y, and Z) GIVEN work.
Explanation:

○ X: while [ $a -le 1000 ]; do ensures the loop stops at 1000.


○ Y: if [ $a -gt 1000 ]; then break; fi stops the loop when the
number exceeds 1000.
○ Z: Filtering with awk works but is post-processing.
6. If the input is root, what does the script output on a typical Linux system?
Answer: a. User root exists. Home Directory: /root Shell: /bin/bash Last Login:
Wed Jan 24 14:00
Explanation: The root user typically has /root as its home directory and
/bin/bash as its default shell.

7. How would you modify the script to also display the user's UID and GID?
Answer: f. All of the above methods work (X,Y,Z).
Explanation: Each option effectively retrieves UID and GID using different
approaches.

8. How does the script handle last login information if the user has never logged
in?
Answer: f. Outputs: Last Login: Never
Explanation: If the user has never logged in, the script displays "Never" instead of
an empty value or error.

9. What happens if the input is nonexistentuser?


Answer: f. User nonexistentuser does not exist.
Explanation: The script checks for the user's existence and prints this message if
they are not found.

10. What command retrieves the user's home directory?


Answer: d. getent passwd "$username" | cut -d: -f6
Explanation: This command extracts the home directory from /etc/passwd using
getent.

11. What happens if the file /dev/null is passed to the script?


Answer: d. Outputs: /dev/null is a special character device.
Explanation: /dev/null is a special device file used for discarding data.

12. What command retrieves the target of a symbolic link?


Answer: a. readlink "$file"
Explanation: readlink shows the actual file a symbolic link points to.

13. If the input is /tmp/symlink, which is a symbolic link pointing to


/var/log/messages, what is the output?
Answer: b. /tmp/symlink is a symbolic link pointing to /var/log/messages.
Explanation: A symlink's destination is displayed using readlink or ls -l.

14. How can the script be modified to count files in a directory if the input is a
directory?
Answer: f. Only W, X, and Y are valid.
Explanation:

○ W: find "$file" -type f | wc -l counts regular files.


○ X: ls -1 | wc -l counts all entries (not just files).
○ Y: find approach also works efficiently.
15. If the input is /etc (a directory with a size of 20M), what is the output?
Answer: e. /etc is a directory. Size: 20M
Explanation: du -sh provides the directory size.

16. What happens if the input threshold is 101%?


Answer: c. Error: Threshold must be a valid number between 1 and 100.
Explanation: A valid threshold cannot exceed 100%.

17. What happens if a partition does not exist?


Answer: d. Outputs: Error: Partition does not exist.
Explanation: The script should explicitly indicate when a partition is missing.

18. If the input partitions are / and /home with usage at 75% and 45%, and the
threshold is 50%, what is the output?
Answer: b. Warning: / usage is at 75%, exceeding threshold. /home usage is at
45%, below threshold.
Explanation: / exceeds 50%, but /home does not, so only / triggers a warning.

19. Which part of the script validates threshold input?


Answer: d. All of the ABOVE (X,Y,Z).
Explanation:

○ X & Y: Regex ensures numeric input.


○ Z: Limits input to 100 max.
20. How would you modify the script to display free space in GB for each
partition?
Answer: e. All of the choices (X,Y & Z).
Explanation: Each method effectively retrieves free space using df, lsblk, or
alternative approaches.

21. What happens if the user inputs abc instead of a number?


Answer: d. Invalid input. Please enter a numeric value.
Explanation: The script should reject non-numeric input.

22. What happens if the user guesses the correct number on their 4th attempt?
Answer: c. Correct! The number was . You guessed it in 4 attempt(s).
Explanation: A correct guess terminates the script with a success message.

23. What happens if the user reaches the maximum number of attempts without
guessing the correct number?
Answer: f. Sorry, you've reached the maximum number of attempts. The
correct number was .
Explanation: The game ends with the correct number being revealed.

24. How would you modify the script to provide a range hint after each guess?
Answer: f. Implement all of the above methods (X,Y,Z) for dynamic range hints.
Explanation: A combination of range adjustments ensures better hints.

25. What happens if the target number is 75, the user guesses 50 on their first
attempt, and this is their 3rd overall attempt?
Answer: b. Too low. Hint: The number is greater than 50. Attempts remaining:
2
Explanation: Since 50 is lower than 75, the script provides a hint.

You might also like