Unix Basics for Beginners


📚 Table of Contents

  1. Unix Basics for Beginners
  2. Unix Users
  3. Using Unix Commands
  4. Working with Files
  5. Unix Directories
  6. Wildcards and File Handling
  7. Unix File Permission Setup
  8. Unix Environment
  9. The vi Editor
  10. Unix Pipes and Filters
  11. Question & Answer

1: Unix Getting Started

What is Unix?

  • Unix is an operating system created in 1969.
  • It allows many users to work on the computer at the same time and run multiple programs.

Unix Structure

  • Kernel: The main part that controls the computer’s hardware.
  • Shell: The interface where users type commands.
  • Commands: A set of instructions that users can run to perform tasks.
  • Files and Directories: Information is stored in files, organized in folders.

Starting Up Unix

  • When you turn on a Unix computer, it loads the kernel and asks you to log in.

What is a Shell?

  • The shell is how you interact with Unix. You type commands, and it runs them.
  • There are different types of shells, like the Bourne shell and C shell.

Shell Prompt

  • The shell prompt shows that the system is ready for you to enter commands. It usually looks like $ for regular users and # for the superuser.

Shell Scripts

  • Shell scripts are groups of commands that run together. They can include comments and loops to make tasks easier.

Shells Types

  1. Bourne Shell (sh): The original shell developed for UNIX. It provides a command-line interface and scripting capabilities.
  2. C Shell (csh): Introduced features like command history and job control. It uses a syntax similar to the C programming language.
  3. Korn Shell (ksh): Combines features of the Bourne and C shells, offering advanced scripting capabilities and improved performance.
  4. Bash (Bourne Again SHell): An enhanced version of the Bourne Shell, it includes features from the C Shell and Korn Shell, and is widely used in Linux systems.
  5. Z Shell (zsh): Incorporates features from other shells and offers advanced customization options, including themes and plugins.

MCQs

1. What is the primary function of the UNIX operating system?
A. To manage hardware resources
B. To provide a graphical user interface
C. To act as a link between the computer and the user
D. To run only one program at a time

Answer: C

2. Which of the following is a component of the UNIX architecture?
A. User Interface
B. Kernel
C. Application Software
D. All of the above

Answer: B

3. What is the role of the shell in UNIX?
A. To manage hardware
B. To interpret user commands
C. To store files
D. To provide a graphical interface

Answer: B

4. Which command is used to display the current date and time in UNIX?
A. time
B. date
C. now
D. current

Answer: B

5. Which of the following shells is the first shell to appear on UNIX systems?
A. C Shell
B. Korn Shell
C. Bourne Shell
D. Bash Shell

Answer: C

6 What is the purpose of a shell script?
A. To create graphical applications
B. To execute a list of commands in order
C. To manage system resources
D. To provide a user interface

Answer: B

7. Which of the following is NOT a type of shell in UNIX?
A. Bourne Shell
B. C Shell
C. Python Shell
D. Korn Shell

Answer: C

8. What is the core of the UNIX operating system called?
A. Shell
B. Kernel
C. Command Line
D. User Interface

Answer: B


2: Unix Users

  1. Logging In and Out of UNIX:
    • Users are assigned a unique username and password for system access.
    • The login process involves entering these credentials, while logging out is done using the exit command.
  2. The Superuser:
    • The root user has full administrative privileges, allowing for system maintenance tasks like adding or deleting users.
    • The root user is often referred to as the superuser.
  3. Shell Prompts:
    • Upon logging in, the shell prompt appears, indicating the user type: $ for common users and # for the superuser.
  4. Home Directory:
    • Each user has a predefined home directory, typically located in /home, which is the default working directory upon login.
  5. Changing Your Password:
    • Users should change their initial password using the passwd command to secure their account.
  6. Shell Startup Files:
    • System Startup File/etc/profile is managed by the system administrator and sets global environment variables.
    • User Startup File.profile in the user’s home directory allows for user-specific configurations and customizations.
  7. Environment Variables:
    • Variables like PATHHOME, and TERM are set during login to configure the user environment.

MCQ

1. What command is used to log out of a UNIX session?
A. exit
B. logout
C. quit
D. close

Answer: A

2. Which user has full administrative privileges in a UNIX system?
A. Regular user
B. Guest user
C. Superuser
D. System user

Answer: C

3. What symbol indicates a superuser prompt in UNIX?
A. $
B. #
C. %
D. &

Answer: B

4. Where is a user’s home directory typically located?
A. /usr
B. /etc
C. /home
D. /var

Answer: C

5. What is the purpose of the /etc/profile file?
A. To store user-specific configurations
B. To manage user passwords
C. To set global environment variables
D. To log user activities

Answer: C

6. Which file allows users to customize their environment settings?
A. /etc/profile
B. .bashrc
C. .profile
D. .login

Answer: C

7. What does the PATH environment variable specify?
A. The current working directory
B. The location of user files
C. The directories to search for executable commands
D. The user’s home directory

Answer: C

8. What is the significance of the HOME environment variable?
A. It indicates the current shell type.
B. It specifies the user’s home directory.
C. It sets the command prompt style.
D. It defines the system’s root directory.

Answer: B

9. Which of the following is true about the superuser in UNIX?
A. The superuser can only read files.
B. The superuser has limited access to system files.
C. The superuser can perform any administrative task.
D. The superuser cannot change system settings.

Answer: C


3: Using UNIX Commands

  1. Basic Command Usage:
    • To execute a command, type its name and press Enter. For example, date shows the current date and time.
  2. Types of Commands:
    • Intrinsic Commands: Built into the shell (e.g., cd to change directories).
    • Extrinsic Commands: Separate files (e.g., ls to list files).
  3. Common Commands:
    • pwd: Displays the current directory.
    • whoami: Shows the current user’s name.
    • who: Lists all users currently logged in.
    • uname: Displays system information.
  4. Manual Pages:
    • Use the man command to get help on any command (e.g., man ls for information about the ls command).
  5. Executing Multiple Commands:
    • You can run several commands on one line by separating them with a semicolon (e.g., cal; date).
  6. Options and Arguments:
    • Options (starting with -) modify command behavior, while arguments provide additional information (e.g., ls -l lists files in detail).

MCQ

1.Which command is used to display the current working directory in UNIX?
A. ls
B. pwd
C. cd
D. dir

Answer: B

2. What does the whoami command do?
A. Displays the current date and time
B. Lists all users currently logged in
C. Shows the name of the current user
D. Changes the current user

Answer: C

3. Which command would you use to get help on the ls command?
A. help ls
B. ls –help
C. man ls
D. info ls

Answer: C

4. What is the purpose of the man command in UNIX?
A. To execute a command
B. To display manual pages for commands
C. To list files in a directory
D. To change the current directory

Answer: B

5. How can you execute multiple commands in one line?
A. By using a comma (,)
B. By using a semicolon (;)
C. By using a colon (:)
D. By using a space

Answer: B

6. Which command is used to list all files in the current directory?
A. list
B. ls
C. dir
D. show

Answer: B

7. What does the -l option do when used with the ls command?
A. Lists files in reverse order
B. Lists files with detailed information
C. Lists only hidden files
D. Lists files in a long format

Answer: B

8. Which command would you use to find out how many lines are in a file?
A. count
B. wc -l
C. ls -l
D. grep -c

Answer: B

9. What is the function of the cd command?
A. To display the contents of a directory
B. To change the current directory
C. To create a new directory
D. To delete a directory

Answer: B

10. Which command shows the system information, including the kernel version?
A. uname
B. version
C. sysinfo
D. info

Answer: A


4: Working with Files

  1. File Operations:
    • Creating Files: Use cat > filename to create a new file.
    • Listing Files: Use ls to list files in the current directory.
    • Deleting Files: Use rm filename to delete a file.
  2. Displaying File Contents:
    • Use cat filename to display the contents of a file.
    • The more command can be used to view one page at a time (e.g., more filename).
  3. File Naming Rules:
    • File names can be up to 256 characters long.
    • Use letters, numbers, and special characters.
    • UNIX is case-sensitive.
  4. Hidden Files:
    • Files starting with a dot (e.g., .hiddenfile) are hidden.
  5. File Permissions:
    • Use ls -l to view file permissions.
    • Permissions determine who can read, write, or execute a file.

MCQ

1. Which command is used to create a new file in UNIX?
A. touch
B. cat > filename
C. mkdir
D. newfile

Answer: B

2. What does the command ls -l display?
A. Only the file names
B. Detailed information about files including permissions
C. Only hidden files
D. The current directory path

Answer: B

3. Which command is used to delete a file in UNIX?
A. remove filename
B. delete filename
C. rm filename
D. del filename

Answer: C

4. How can you view the contents of a file named example.txt?
A. view example.txt
B. cat example.txt
C. show example.txt
D. open example.txt

Answer: B

5. What is the maximum length of a file name in UNIX?
A. 128 characters
B. 256 characters
C. 512 characters
D. 64 characters

Answer: B

6. Which command will display hidden files in the current directory?
A. ls
B. ls -a
C. ls -l
D. ls -h

Answer: B

7. What does the rm command do?
A. Renames a file
B. Moves a file
C. Deletes a file
D. Copies a file

Answer: C

8. Which of the following is true about file permissions in UNIX?
A. Permissions are not important.
B. Permissions determine who can read, write, or execute a file.
C. All files have the same permissions by default.
D. Only the root user can change file permissions.

Answer: B

9. What does the command cat > newfile do?
A. Displays the contents of newfile
B. Creates a new file named newfile and allows you to enter text
C. Deletes the file newfile
D. Copies the contents of newfile

Answer: B

10. Which command is used to display the contents of a file one page at a time?
A. cat
B. more
C. less
D. view

Answer: B


5: Unix Directories

  1. Definition of Directories:
    • A directory is a special file that stores file names and related information.
    • UNIX uses a hierarchical structure for organizing files, known as a directory tree.
  2. Home Directory:
    • The directory you start in after logging in is called your home directory.
    • You can navigate to your home directory using the command: cd ~.
  3. Pathnames:
    • Absolute Pathname: Starts from the root directory (e.g., /etc/passwd).
    • Relative Pathname: Starts from the current directory (e.g., docs/notes).
  4. Listing Directories:
    • Use ls dirname to list files in a specific directory.
  5. Creating Directories:
    • Use mkdir dirname to create a new directory.
    • Use mkdir -p /path/to/dir to create parent directories if they do not exist.
  6. Removing Directories:
    • Use rmdir dirname to remove an empty directory.
    • To delete a non-empty directory, use rm -rf dirname (be cautious with this command).
  7. Changing Directories:
    • Use cd dirname to change to a specified directory.
    • Use cd .. to go up one level in the directory structure.
  8. Renaming Directories:
    • Use mv olddir newdir to rename a directory.
  9. Special Directories:
    • . (dot) represents the current directory.
    • .. (dot dot) represents the parent directory.

MCQ

1. What is the command to change to your home directory in UNIX?
A. cd ~
B. cd /home
C. cd ..
D. cd /

Answer: A

2. Which command is used to create a new directory?
A. mkdir dirname
B. newdir dirname
C. create dirname
D. dircreate dirname

Answer: A

3. What does the command rmdir dirname do?
A. Removes a directory and its contents
B. Removes an empty directory
C. Renames a directory
D. Lists the contents of a directory

Answer: B

4. Which of the following represents the parent directory?
A. .
B. ..
C. /
D. ~

Answer: B

5. How can you view the contents of a directory?
A. ls
B. dir
C. list
D. show

Answer: A

6. What is the command to move up one level in the directory structure?
A. cd ..
B. cd /
C. cd ~
D. cd .

Answer: A

7. Which command is used to rename a directory?
A. rename olddir newdir
B. mv olddir newdir
C. change olddir newdir
D. edit olddir newdir

Answer: B

8. What does the command mkdir -p /tmp/dir1/dir2 do?
A. Creates only dir1
B. Creates dir1 and dir2, including any necessary parent directories
C. Removes dir1 and dir2
D. Lists the contents of dir1 and dir2

Answer: B

9. Which command will display the current working directory?
A. pwd
B. ls
C. dir
D. cd

Answer: A

10. What does the ls -d command do?
A. Lists all files in the directory
B. Displays the attributes of the directory itself
C. Deletes the directory
D. Changes to the specified directory

Answer: B



6: Wildcards and File Handling

  1. Wildcards:
    • Wildcards are special characters used to represent one or more files in commands.
    • Asterisk (*): Matches zero or more characters. For example, myfile* matches myfilemyfile1myfile2, etc.
    • Question Mark (?): Matches exactly one character. For example, myfile0? matches myfile00 and myfile01, but not myfile010.
    • Square Brackets ([ ]): Matches a range of characters. For example, [a-c] matches ab, or c.
  2. Searching File Contents:
    • The grep command is used to search for specific text within files.
    • Example: grep "text" filename searches for “text” in the specified file.
    • Options:
      • -i: Case-insensitive search.
      • -c: Counts the number of matches.
      • -v: Displays lines that do not match the pattern.
  3. Searching Multiple Files:
    • You can search for a string in multiple files by specifying the file names.
    • Example: grep "text" file1 file2.
  4. Finding Files:
    • The find command is used to locate files in a directory hierarchy.
    • Example: find /etc -name "my*" finds all files starting with “my” in the /etc directory.
  5. Miscellaneous File Handling Commands:
    • Head and Tail:
      • head filename: Displays the first 10 lines of a file.
      • tail filename: Displays the last 10 lines of a file.
    • Word Count:
      • wc filename: Counts lines, words, and characters in a file.
      • Options: -l for lines, -w for words, -c for characters.
    • Linking Files:
      • ln filename linkname: Creates a hard link to a file.
      • ln -s filename linkname: Creates a soft (symbolic) link to a file.

MCQ

1. What does the asterisk (*) wildcard represent in UNIX?
A. Matches exactly one character
B. Matches zero or more characters
C. Matches a specific character
D. Matches a range of characters

Answer: B

2. Which command is used to search for a specific text string in a file?
A. find
B. grep
C. search
D. locate

Answer: B

3. What does the question mark (?) wildcard match?
A. Zero or more characters
B. Any single character
C. A specific character
D. A range of characters

Answer: B

4. Which command would you use to find all files starting with “my” in the /etc directory?
A. grep my /etc/*
B. find /etc -name “my*”
C. ls /etc/my*
D. search /etc my*

Answer: B

5. What does the -i option do when used with the grep command?
A. Counts the number of matches
B. Displays lines that do not match
C. Makes the search case-insensitive
D. Searches for multiple files

Answer: C

6. Which command displays the last 10 lines of a file?
A. head filename
B. tail filename
C. cat filename
D. more filename

Answer: B

7.What is the purpose of the wc command?
A. To count the number of files in a directory
B. To display the contents of a file
C. To count lines, words, and characters in a file
D. To search for a string in a file

Answer: C

8. Which wildcard matches a range of characters specified inside square brackets?
A. *
B. ?
C. [ ]
D. #

Answer: C

9. What does the command ln -s filename linkname do?
A. Creates a hard link to a file
B. Creates a soft (symbolic) link to a file
C. Deletes a file
D. Renames a file

Answer: B

10. Which command would you use to count only the number of lines in a file?
A. wc -w filename
B. wc -c filename
C. wc -l filename
D. wc filename

Answer: C



7: Unix File Permission Setup

  1. File Ownership:
    • Every file in UNIX has an owner and belongs to a group.
    • The owner has specific permissions to manage the file.
  2. Permission Types:
    • Owner Permissions: Actions the file owner can perform (read, write, execute).
    • Group Permissions: Actions users in the same group can perform.
    • Other Permissions: Actions all other users can perform.
  3. Permission Indicators:
    • Permissions are displayed using symbols:
      • r (read) – 4,
      • w (write) -2 ,
      • x (execute) -1.
    • Example: -rwxr-xr-- means:
      • Owner: read, write, execute
      • Group: read, execute
      • Others: read only
  4. Changing Permissions:
    • Use the chmod command to change file permissions.
    • Symbolic Mode: Use + to add, - to remove, and = to set permissions.
      • Example: chmod g+w filename adds write permission for the group.
    • Absolute Mode: Use numbers to set permissions (0-7).
      • Example: chmod 755 filename sets full permissions for the owner and read/execute for group and others.
  5. Changing Ownership:
    • Use chown to change the owner of a file.
    • Use chgrp to change the group of a file.
  6. SUID and SGID:
    • SUID (Set User ID): Allows users to run an executable with the permissions of the file owner.
    • SGID (Set Group ID): Allows users to run an executable with the permissions of the group owner.
  7. Sticky Bit:
    • A special permission that allows only the file owner, directory owner, or root to delete or rename files within a directory.

MCQ

1. What does the ‘r’ permission allow a user to do?
A. Write to the file
B. Read the contents of the file
C. Execute the file
D. Change the file permissions

Answer: B

2. Which command is used to change the owner of a file?
A. chgrp
B. chmod
C. chown
D. mv

Answer: C

3. What does the numeric value ‘7’ represent in file permissions?
A. Read and execute only
B. Read, write, and execute
C. Read only
D. Write only

Answer: B

4. Which permission allows a user to delete a file?
A. Read
B. Write
C. Execute
D. None of the above

Answer: B

5. What does the ‘x’ permission allow for a directory?
A. Read the contents of the directory
B. Write new files to the directory
C. Traverse into the directory
D. Change the directory permissions

Answer: C

6. Which command is used to change the group ownership of a file?
A. chown
B. chmod
C. chgrp
D. mv

Answer: C

7. What does the SUID permission do?
A. Allows users to read the file
B. Allows users to execute the file with the owner’s permissions
C. Allows users to write to the file
D. Allows users to change the file’s group

Answer: B

8. Which of the following represents no permissions in numeric format?
A. 1
B. 0
C. 4
D. 2

Answer: B

10. What does the sticky bit do in a directory?
A. Allows anyone to delete files
B. Restricts file deletion to the file owner, directory owner, or root
C. Grants execute permission
D. Allows read access to all users

Answer: B

11. Which command would you use to set read and write permissions for the owner and read-only for the group and others?
A. chmod 644 filename
B. chmod 755 filename
C. chmod 600 filename
D. chmod 444 filename

Answer: A



8: Unix Environment

  1. Environment Variables:
    • Variables that store information about the system and user settings.
    • Examples include HOMEPATHTERM, and USER.
  2. Setting Environment Variables:
    • Use the syntax VARIABLE_NAME=value to set a variable.
    • Access the value using $VARIABLE_NAME.
  3. Shell Initialization:
    • When you log in, the shell reads configuration files to set up the environment.
    • Common files include /etc/profile (system-wide) and ~/.profile (user-specific).
  4. Terminal Type:
    • The TERM variable defines the type of terminal being used.
    • It can affect how commands display output.
  5. PATH Variable:
    • Specifies directories where the shell looks for executable commands.
    • Example: PATH=/bin:/usr/bin.
  6. PS1 and PS2 Variables:
    • PS1: Defines the primary command prompt.
    • PS2: Defines the secondary prompt (used for multi-line commands).
  7. Common Environment Variables:
    • HOME: User’s home directory.
    • PWD: Current working directory.
    • LANG: Language settings for the system.
  8. Using the env Command:
    • Displays all current environment variables and their values.

MCQ

1. What does the HOME environment variable represent?

A. The current working directory

B. The user’s home directory

C. The path for executable files

D. The terminal type

Answer: B

2. Which command is used to display all current environment variables?

A. showenv

B. env

C. set

D. printenv

Answer: B

3. What is the purpose of the PATH variable?

A. To set the terminal type

B. To define the user’s home directory

C. To specify directories for executable commands

D. To store user preferences

Answer: C

4. Which file is typically used for user-specific shell initialization?

A. /etc/profile

B. ~/.bashrc

C. ~/.profile

D. /etc/bash.bashrc

Answer: C

5. What does the PS1 variable control?

A. The secondary command prompt

B. The primary command prompt

C. The terminal type

D. The user’s home directory

Answer: B

6. Which of the following is NOT a common environment variable?

A. TERM

B. USER

C. SHELL

D. CONFIG

Answer: D

7. How do you set an environment variable in the shell?

A. set VARIABLE=value

B. VARIABLE=value

C. export VARIABLE=value

D. Both B and C

Answer: D

8. What does the PWD variable indicate?

A. The path to the user’s home directory

B. The current working directory

C. The path for executable files

D. The user’s login name

Answer: B

9. Which command would you use to check the current terminal type?

A. echo $TERM

B. show terminal

C. get terminal

D. print $TERM

Answer: A

10. What happens when you log into a Unix system?

A. The system automatically sets the PATH variable

B. The shell reads the profile files to set up the environment

C. The user is prompted to enter environment variables

D. The system displays the current date and time

Answer: B



9: The vi Editor

  1. Introduction to vi:
    • vi is a powerful text editor used in Unix systems.
    • It operates in two main modes: Command mode and Insert mode.
  2. Starting vi:
    • Use vi filename to open or create a file.
    • Use view filename to open a file in read-only mode.
  3. Modes of vi:
    • Command Mode: For executing commands (e.g., saving, quitting).
    • Insert Mode: For entering text. Switch to this mode by pressing ia, or o.
  4. Exiting vi:
    • :q to quit.
    • :q! to quit without saving changes.
    • :w to save changes.
    • :wq or ZZ to save and quit.
  5. Moving within a file:
    • Use keys like hjkl to move left, down, up, and right.
    • Use 0 to go to the beginning of a line and $ to go to the end.
  6. Editing text:
    • x to delete a character under the cursor.
    • dd to delete a whole line.
    • u to undo the last action.
  7. Copying and Pasting:
    • yy to copy a line (yank).
    • p to paste the copied line after the cursor.
  8. Searching:
    • Use /search_term to search forward and ?search_term to search backward.
    • Use n to repeat the last search.
  9. Replacing text:
    • Use :s/old/new/g to replace all occurrences of “old” with “new” in the current line.
  10. Advanced Commands:
    • J to join lines.
    • R to replace multiple characters.
    • :set nu to display line numbers.

MCQ

1. Which command is used to start the vi editor with a file?

A. edit filename

B. vi filename

C. open filename

D. start filename

Answer: B

2. What mode do you enter when you press i in vi?

A. Command mode

B. Insert mode

C. Visual mode

D. Read-only mode

Answer: B

3. How do you save changes and exit vi?

A. :q!

B. :wq

C. :exit

D. ZZ

Answer: B

4. Which command deletes the character under the cursor in vi?

A. d

B. x

C. del

D. remove

Answer: B

5. What does the command dd do in vi?

A. Deletes the current line

B. Duplicates the current line

C. Displays the current line

D. Does nothing

Answer: A

6. Which command is used to search for a term in vi?

A. find term

B. /term

C. search term

D. locate term

Answer: B

7. What is the purpose of the command :s/old/new/g in vi?

A. To save the file

B. To search for a term

C. To replace all occurrences of “old” with “new”

D. To delete a line

Answer: C

8. How do you copy a line in vi?

A. cp

B. yy

C. copy

D. duplicate

Answer: B

9. Which command moves the cursor to the end of the line in vi?

A. 0

B. ^

C. $

D. G

Answer: C

10. What does the command u do in vi?

A. Redoes the last action

B. Undoes the last action

C. Saves the file

D. Exits the editor

Answer: B



Chapter 10: Unix Pipes and Filters – Exam Summary

  1. Pipes:
    • A pipe connects two commands, allowing the output of one command to be used as the input for another.
    • Syntax: Use the vertical bar | to create a pipe between commands.
    • Example: command1 | command2
  2. Filters:
    • Filters are commands that process data and output the result.
    • Common filters include grepsort, and more.
  3. The grep Command:
    • Used to search for specific patterns in files.
    • Syntax: grep pattern filename
    • Options:
      • -i: Case-insensitive search.
      • -v: Invert match (show lines that do not match).
      • -n: Show line numbers with output.
  4. The sort Command:
    • Arranges lines of text in a specified order.
    • Syntax: sort filename
    • Options:
      • -n: Sort numerically.
      • -r: Sort in reverse order.
  5. The more and pg Commands:
    • Used to view long output one screen at a time.
    • more allows forward navigation.
    •  pg allows backward navigation as well.
  6. Combining Commands:
    • You can combine multiple commands using pipes to create complex data processing tasks.
      • Ex: ls -l | grep "Aug" | sort +4n | more lists files modified in August, sorts them by size, and displays them page by page.
  7. Shell Scripts:
    • You can write shell scripts to automate tasks using pipes and filters.
    • A shell script starts with a shebang (#!/bin/sh) and contains a list of commands.


1. What is the purpose of a pipe in Unix?

A. To connect two commands

B. To create a file

C. To delete a file

D. To display help

Answer: A

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

A. find

B. grep

C. search

D. locate

Answer: B

3. How do you sort the contents of a file in reverse order?

A. sort -r filename

B. sort filename -r

C. sort filename –reverse

D. sort -reverse filename

Answer: A

4. What does the -i option do in the grep command?

A. Inverts the match

B. Ignores case sensitivity

C. Shows line numbers

D. Displays the matched line only

Answer: B

5. Which command allows you to view the output one screen at a time?

A. cat

B. more

C. head

D. tail

Answer: B

6. What is the correct syntax to combine two commands using a pipe?

A. command1; command2

B. command1 | command2

C. command1 & command2

D. command1 > command2

Answer: B

7. Which command would you use to sort a list of files by size?

A. ls -s

B. sort -n

C. sort -s

D. ls -l

Answer: B

8. What does the -v option do in the grep command?

A. Displays the matched lines

B. Displays the line numbers

C. Inverts the match to show non-matching lines

D. Ignores case sensitivity

Answer: C

9. Which command is used to display the first few lines of a file?

A. tail

B. head

C. more

D. cat

Answer: B

10. What is the purpose of a shell script in Unix?

A. To create a new user

B. To automate a series of commands

C. To manage files

D. To display system information

Answer: B