wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Linux Basics Worksheet

Total questions: 150

Worksheet time: 1hrs 15mins

Name
Class
Date
1.

What is a terminal and a shell in Linux?

a)

A terminal is a command interpreter; a shell is a window manager

b)

A terminal is a text interface; a shell is the command interpreter that runs inside it

c)

A terminal is the Linux kernel; a shell is the file system

d)

A terminal is a graphical desktop; a shell is a text editor

2.

How can you check which shell is being used?

a)

echo $SHELL

b)

uname -s

c)

which shell

d)

cat /etc/passwd

3.

What is the difference between an absolute path and a relative path?

a)

An absolute path starts from /, while a relative path starts from the current directory

b)

An absolute path is shorter than a relative path

c)

A relative path always includes the home directory, an absolute path does not

d)

They are the same; both start from the current directory

4.

How can you create a directory test inside the current directory?

a)

mkdir test

b)

touch test

c)

mkfs test

d)

cp test

5.

How can you create multiple nested directories using a single command?

a)

mkdir -p parent/child/grandchild

b)

mkdir parent; mkdir child; mkdir grandchild

c)

mkdir -r parent/child/grandchild

d)

md -p parent/child/grandchild

6.

How can you create an empty file example.txt?

a)

touch example.txt

b)

mkdir example.txt

c)

rm example.txt

d)

cp example.txt /tmp/

7.

How can you copy the file source.txt to backup.txt?

a)

cp source.txt backup.txt

b)

mv source.txt backup.txt

c)

cat source.txt > backup.txt && rm source.txt

d)

ln -s source.txt backup.txt

8.

How can you move a file from the home directory to /tmp?

a)

mv ~/file /tmp/

b)

cp ~/file /tmp/

c)

rm ~/file /tmp/

d)

cd ~/file /tmp/

9.

How can you rename the file old.txt to new.txt?

a)

mv old.txt new.txt

b)

cp old.txt new.txt && rm old.txt

c)

rename new.txt old.txt

d)

ln -s old.txt new.txt

10.

How can you delete a file without confirmation?

a)

rm -f file

b)

rm -i file

c)

rm -r file

d)

delete file

11.

How can you delete a directory along with all its contents?

a)

rm -rf dir

b)

rmdir dir

c)

del dir

d)

chmod -R 000 dir

12.

What are hidden files and how can you view them?

a)

Files starting with a dot; view with ls -a

b)

Encrypted files; view with cat -e

c)

System-only files; view with sudo ls

d)

Backup files; view with ls -b

13.

How can you display the current directory?

a)

pwd

b)

whoami

c)

ls -l

d)

. /etc/profile

14.

How can you navigate to the home directory?

a)

cd ~

b)

cd /

c)

cd ..

d)

cd -

15.

How can you move two levels up from the current directory?

a)

cd ../..

b)

cd ..

c)

cd ../../..

d)

cd ./..

16.

How can you list directory contents with detailed information?

a)

ls -l

b)

ls

c)

ls -a

d)

du -h

17.

How can you display only directories in the current folder?

a)

ls -d */

b)

ls -lR

c)

find / -type d

d)

ls -a

18.

How can you find a file by name in the system?

a)

find / -name "filename"

b)

ps aux | grep filename

c)

cat /etc/shells

d)

df -h

19.

How can you find files modified in the last 24 hours?

a)

find . -type f -mtime -1

b)

grep -r "24h" .

c)

ls -l --today

d)

. -mtime 1

20.

How can you view the size of files in a directory?

a)

ls -lh

b)

free -h

c)

du -s

d)

stat -c %s *

21.

What are UID and GID?

a)

Numeric identifiers for users and groups

b)

Usernames and group names

c)

Kernel and GPU IDs

d)

Unique IDs for files and directories

22.

What is the difference between the root user and a regular user?

a)

Root has unrestricted administrative privileges; a regular user has limited permissions

b)

Root is a normal user with a different home directory

c)

A regular user manages the system; root is for everyday tasks

d)

Root can only read files; a regular user can write files

23.

How can you view your UID and GID?

a)

id

b)

whoami

c)

groups

d)

passwd -S

24.

How can you add a new user?

a)

useradd username

b)

addgroup username

c)

newuser --create

d)

usermod -aG username

25.

How can you delete a user along with their home directory?

a)

userdel -r username

b)

deluser username

c)

rm -rf /home/username

d)

groupdel username

26.

How can you create a new group?

a)

groupadd groupname

b)

addgroup --user groupname

c)

mkgroup groupname

d)

usermod -G groupname

27.

How can you add a user to a group?

a)

usermod -aG groupname username

b)

groupadd -a username groupname

c)

useradd -G groupname

d)

chgrp username groupname

28.

How can you see which groups a user belongs to?

a)

groups username

b)

whoami -g

c)

getenforce username

d)

chgrp -l username

29.

How can you change the owner of a file?

a)

chown newowner file

b)

chmod newowner file

c)

chgrp newowner file

d)

owner file newowner

30.

How can you change the group of a file?

a)

Use chgrp newgroup filename

b)

Use chown newgroup filename

c)

Use chmod g+ filename

d)

Move the file into a directory named after the group

31.

What do the numbers in chmod 755 mean?

a)

Owner has rwx, group has r-x, others have r-x

b)

Owner has r-x, group has rwx, others have ---

c)

Owner has rw, group has r, others have r

d)

Owner has ---, group has ---, others have rwx

32.

How can you give the owner execute permission on a file?

a)

Run chmod u+x filename

b)

Run chmod g+x filename

c)

Run chown +x filename

d)

Run setfacl -m o:x filename

33.

How can you remove write permission for the group?

a)

Run chmod g-w filename

b)

Run chmod g+w filename

c)

Run chgrp -w filename

d)

Run chmod o-w filename

34.

How can you set permissions rw-r--r-- using numeric notation?

a)

Use chmod 644 filename

b)

Use chmod 664 filename

c)

Use chmod 744 filename

d)

Use chmod 600 filename

35.

What is the sticky bit and where is it used?

a)

A directory setting where only the file owner (or root) can delete or rename files, commonly on /tmp

b)

A flag that lets scripts run with root privileges by default

c)

A bit that prevents any file from being executed

d)

A memory feature that compresses inactive pages

36.

How can you set the sticky bit on a directory?

a)

Run chmod +t directory

b)

Run chown +t directory

c)

Run chmod 644 directory

d)

Sticky bit applies only to files with chmod g+t

37.

How can you view file permissions using ls -l?

a)

Run ls -l to list long format showing permissions, owner, group, and size

b)

Run ls -a to show only permissions

c)

Run stat -c %A to show only ACL entries

d)

Use cat filename to display permissions at the top

38.

How can you change a user’s password?

a)

Run passwd username

b)

Run chpasswd username directly on the prompt

c)

Run usermod -p username

d)

Run chage -l username

39.

How can you lock a user account?

a)

Run usermod -L username

b)

Run passwd -u username

c)

Run useradd -l username

d)

Run chsh -s /sbin/nologin username

40.

How can you view the last login of a user?

a)

Run lastlog -u username

b)

Run whoami

c)

Run last with no options only

d)

Run users

41.

What is a process in Linux?

a)

An instance of a running program

b)

A file stored on disk

c)

A user’s terminal session

d)

A kernel module loaded but not running

42.

How can you view all running processes?

a)

Run ps aux

b)

List /proc with ls -l

c)

Run top -n 1 only shows one user

d)

Run who

43.

How can you view processes of a specific user?

a)

Run ps -u username

b)

Run ps -p username

c)

Run ps aux | grep username is the standard command

d)

Run killall -u username to list then kill

44.

How can you find a process by name?

a)

Use pgrep name

b)

Use pidofall name

c)

Use grep name /etc/passwd

d)

Use which name

45.

How can you display a process tree?

a)

Run pstree

b)

Run pmap

c)

Run ps -q

d)

Run tree /proc to show processes

46.

What are PID and PPID?

a)

Process ID and parent process ID

b)

Permissions identifier and process privilege ID

c)

Packet identifier and parent descriptor

d)

Processor index and process device

47.

How can you terminate a process by PID?

a)

Run kill PID

b)

Run stop PID

c)

Delete /proc/PID with rm -f

d)

Run exit PID from the shell

48.

How can you forcefully terminate a process?

a)

Run kill -9 PID

b)

Run killall -1 PID

c)

Run pkill -STOP name

d)

Run systemctl stop -f process

49.

How can you send the HUP signal to a process?

a)

Run kill -HUP PID

b)

Run pkill -9 name

c)

Run killall -KILL process

d)

Run kill -CONT PID

50.

How can you suspend a process?

a)

Send SIGSTOP, for example kill -STOP PID

b)

Send SIGKILL with kill -9 PID

c)

Run bg to stop it

d)

Run renice +5 PID

51.

How can you resume a suspended process?

a)

Send SIGCONT, for example kill -CONT PID

b)

Send SIGSTOP to the process

c)

Run renice 0 PID

d)

Exit and restart the shell

52.

How can you run a process in the background?

a)

Append & to the command

b)

Prefix the command with sudo

c)

Use nohup as the only requirement

d)

Set a higher ulimit value first

53.

How can you bring a background process to the foreground?

a)

Use fg %job

b)

Use bg %job

c)

Use jobs -f to attach

d)

Press Ctrl+C in the terminal

54.

What is the jobs command used for?

a)

Listing active jobs in the current shell

b)

Viewing system services

c)

Editing crontab entries

d)

Compiling source code

55.

How can you monitor CPU and memory usage in real time?

a)

Run top

b)

Run who

c)

Run ls

d)

Run passwd

56.

How can you sort processes by memory usage?

a)

In top, press M to sort by memory

b)

In top, press P to sort by memory

c)

With ps, use --sort +pid to show memory first

d)

In free, press m to sort

57.

How can you change a process priority at startup?

a)

Start the command with nice -n 10 command

b)

Use renice -n 10 PID before starting

c)

Use kill -n 10 PID

d)

Use chrt -p command without options

58.

How can you change the priority of a running process?

a)

Run renice -n 5 -p PID

b)

Run nice -n 5 PID on an already running process

c)

Run chmod +x PID to grant priority

d)

Run fg -n PID to raise priority

59.

What is a zombie process?

a)

A process that has exited but remains in the process table until its parent reads its status

b)

A process stuck in uninterruptible sleep waiting for I/O

c)

An orphaned running process with no parent

d)

A hidden malware process masquerading as init

60.

How can you find and eliminate a zombie process?

a)

Use ps to identify processes with state Z and terminate or restart their parent process

b)

Run kill -9 on the zombie process ID to remove it directly

c)

Use nice -n 19 on the zombie to lower priority until it disappears

d)

Run top and kill the child process with SIGSTOP

61.

How can you open a file in Nano?

a)

nano filename

b)

open filename with nano

c)

nano --edit filename

d)

edit filename -n

62.

How can you save a file and exit Nano?

a)

Press Ctrl+O, Enter to write, then Ctrl+X to exit

b)

Press Ctrl+S to save and Ctrl+Q to quit

c)

Type :wq and press Enter

d)

Press F10 to save and exit

63.

How can you exit Nano without saving?

a)

Press Ctrl+X and answer N when prompted

b)

Type :q! and press Enter

c)

Press Ctrl+Q twice

d)

Press Esc Esc and Enter

64.

How can you start text selection in Nano?

a)

Press Ctrl+^ (Ctrl+6) to set the mark

b)

Press Shift+Arrow to start selection

c)

Press Ctrl+A to begin selecting

d)

Press Alt+S to start selection

65.

How can you copy selected text in Nano?

a)

Press Alt+6 to copy the marked region

b)

Press Ctrl+C to copy

c)

Press Ctrl+Insert to copy

d)

Press Alt+C to copy selection

66.

How can you paste text in Nano?

a)

Press Ctrl+U to paste

b)

Press Ctrl+V to paste

c)

Press Shift+Insert to paste

d)

Press Alt+P to paste

67.

How can you search for text in Nano?

a)

Press Ctrl+W and type the search term

b)

Type /pattern and press Enter

c)

Press Ctrl+F to find

d)

Press Alt+F and type the term

68.

How can you replace text in Nano?

a)

Press Ctrl+\ to start replace

b)

Type :%s/old/new/g

c)

Press Ctrl+R to replace

d)

Press Alt+R and enter terms

69.

How can you open Vim from the command line?

a)

vim filename

b)

open -e vim filename

c)

vi --open filename

d)

vim --start filename

70.

How can you exit Vim without saving?

a)

:q! in normal mode

b)

:quit! in insert mode

c)

ZZ

d)

ZQ then Enter

71.

How can you save a file in Vim?

a)

:w in normal mode

b)

:save in any mode

c)

:write! only in insert mode

d)

:wq! only

72.

How can you switch to insert mode in Vim?

a)

Press i in normal mode

b)

Press s in command-line mode

c)

Type :insert

d)

Press Ctrl+I

73.

How can you delete a line in Vim?

a)

dd in normal mode

b)

dl in insert mode

c)

D in insert mode

d)

:delete line

74.

How can you undo the last action in Vim?

a)

Press u in normal mode

b)

Press Ctrl+Z

c)

Type :undo!

d)

Press U twice in insert mode

75.

How can you copy a line in Vim?

a)

yy in normal mode

b)

cc in normal mode

c)

y$ in insert mode

d)

:copyline

76.

How can you paste copied text in Vim?

a)

p in normal mode

b)

Ctrl+V in insert mode

c)

Shift+Insert in any mode

d)

:paste!

77.

How can you search for a word in Vim?

a)

/word in normal mode

b)

Ctrl+F and type word

c)

?word in insert mode

d)

:find word from command-line mode

78.

How can you replace a word throughout the entire file in Vim?

a)

:%s/old/new/g

b)

:s/old/new

c)

:g/old/replace/new

d)

:A/old/new/all

79.

How can you jump to line 50 in Vim?

a)

:50

b)

gg50

c)

G50

d)

/50

80.

How can you display line numbers in Vim?

a)

:set number

b)

:show numbers

c)

:lineno on

d)

:set nu! off

81.

How can you find the string "error" in a log file?

a)

grep "error" logfile.log

b)

find "error" logfile.log

c)

awk "error" logfile.log

d)

sed -n "error" logfile.log

82.

How can you search for a string without case sensitivity?

a)

grep -i "pattern" file

b)

grep --nocase-only "pattern" file

c)

grep -c "pattern" file

d)

grep -I "pattern" file

83.

How can you display line numbers in grep output?

a)

grep -n "pattern" file

b)

grep --lines "pattern" file

c)

grep -l "pattern" file

d)

grep --show-numbers "pattern" file

84.

How can you invert a grep search (show lines without the pattern)?

a)

grep -v "pattern" file

b)

grep --no-match "pattern" file

c)

grep -x "pattern" file

d)

grep --invert-only file

85.

How can you search for text recursively in a directory?

a)

grep -R "pattern" directory

b)

grep --deep "pattern" directory

c)

grep -d "pattern" directory

d)

grep -P "pattern" directory

86.

How can you replace "foo" with "bar" in a file using sed?

a)

sed -i 's/foo/bar/g' file

b)

sed 'find foo replace bar' file

c)

sed -r 'foo->bar' file

d)

sed --swap foo bar file

87.

How can you delete line 5 from a file using sed?

a)

sed -i '5d' file

b)

sed 'd5' file

c)

sed --delete 5 file

d)

sed -n '5p' file

88.

How can you append text to the end of each line using sed?

a)

sed -i 's/$/text/' file

b)

sed -i '$a text' file to every line

c)

sed 'append text' file

d)

sed -A 'text$' file

89.

How can you print the second column of a file using awk?

a)

awk '{print $2}' file.txt

b)

awk '{print 1,1, 2}' file.txt

c)

awk -F: '{print $1}' file.txt

d)

sed -n '2p' file.txt

90.

How can you print lines where the third column is greater than 100 using awk?

a)

awk '$3>100' file.txt

b)

awk '{if ($3>=100) print}' file.txt

c)

grep -E '3>100' file.txt

d)

cut -d' ' -f3 file.txt

91.

How can you calculate the sum of numbers in the first column using awk?

a)

awk '{s+=$1} END{print s}' file.txt

b)

awk 'END{print $1}' file.txt

c)

awk '{sum=$1} END{print sum}' file.txt

d)

sed 's/\n/+/' file.txt | bc

92.

How can you sort a file alphabetically?

a)

sort file.txt

b)

sort -n file.txt

c)

uniq file.txt

d)

grep sort file.txt

93.

How can you sort a file numerically?

a)

sort -n file.txt

b)

sort -r file.txt

c)

uniq -c file.txt

d)

sort -h file.txt

94.

How can you remove duplicate lines from a file?

a)

sort -u file.txt

b)

uniq -d file.txt

c)

grep -v duplicate file.txt

d)

awk '!seen[$0]++' file.txt | head -n 1

95.

How can you count occurrences of each line in a file?

a)

sort file.txt | uniq -c

b)

wc -l file.txt

c)

awk '{print NR,$0}' file.txt

d)

cat file.txt | nl

96.

How can you find all .conf files in /etc?

a)

find /etc -type f -name "*.conf"

b)

grep -R ".conf" /etc

c)

ls /etc/*.conf -R

d)

locate /etc/*.conf

97.

How can you find files larger than 100 MB?

a)

find / -type f -size +100M

b)

du -sh * | grep 100M

c)

ls -lh | awk '$5>100M'

d)

df -h | grep +100M

98.

How can you find and delete all .tmp files in /tmp?

a)

find /tmp -type f -name "*.tmp" -delete

b)

rm -rf /tmp/*.tmp /s

c)

find /tmp -type d -name "*.tmp" -prune -delete

d)

xargs -0 rm -f /tmp/*.tmp

99.

How can you use xargs to delete found files?

a)

find . -type f -name "*.tmp" -print0 | xargs -0 rm -f

b)

ls *.tmp | xargs rm -rf --preserve-root

c)

grep -R tmp . | xargs rm -f

d)

xargs find . -name "*.tmp" -delete

100.

How can you pass the output of one command as arguments to another?

a)

command1 | xargs command2

b)

command1 > command2

c)

command2 <(command1) without xargs

d)

command1 && command2

101.

How can you check internet connectivity?

a)

ping -c 4 google.com

b)

traceroute -n 8.8.8.8

c)

nc -zv google.com 80

d)

curl -O google.com

102.

How can you find the IP address of your network interface?

a)

ip addr show

b)

ip route show

c)

ss -tuln

d)

dig +short myip.opendns.com @resolver1.opendns.com

103.

How can you view the routing table?

a)

ip route show

b)

ip link show

c)

route add default gw 192.168.1.1

d)

ss -s

104.

How can you check port availability on a remote host?

a)

nc -zv example.com 80

b)

ss -tuln | grep 80

c)

ip route get example.com

d)

ping -f example.com

105.

How can you view open ports on the local machine?

a)

ss -tuln

b)

nc -zv localhost 1-65535

c)

lsof /proc/net/tcp

d)

ip addr

106.

How can you find which process is using port 80?

a)

sudo lsof -i :80

b)

ip route show | grep 80

c)

ps aux | grep 80

d)

netstat -r | grep 80

107.

How can you use traceroute?

a)

traceroute example.com

b)

tracepath -p 80

c)

ping -R example.com

d)

route -n traceroute

108.

What does the ss command do?

a)

Displays socket statistics and network connections

b)

Shows disk usage by directory

c)

Scans remote hosts for open vulnerabilities

d)

Manages software packages and repositories

109.

How can you connect to a remote server via SSH?

a)

ssh user@server.example.com

b)

telnet user@server.example.com

c)

nc -zv server.example.com 22

d)

scp user@server.example.com

110.

How can you copy a file to a remote server using SCP?

a)

scp file.txt user@server:/path/

b)

cp file.txt user@server:/path/

c)

rsync --delete user@server:/path/ file.txt

d)

ssh user@server:/path/ file.txt

111.

How can you generate SSH keys?

a)

ssh-keygen

b)

ssh-copy-id

c)

openssl rsa -in ~/.ssh/id_rsa

d)

gpg --gen-key

112.

How can you copy a public SSH key to a server?

a)

ssh-copy-id user@server

b)

ssh-keygen -t rsa

c)

scp ~/.ssh/id_rsa.pub user@server:/authorized_keys

d)

ssh-add -L user@server

113.

How can you configure the SSH client using a config file?

a)

Create or edit ~/.ssh/config with Host entries

b)

Modify /etc/hosts for SSH shortcuts

c)

Place keys in /usr/local/ssh/config

d)

Run ssh --configure to generate settings

114.

How can you check DNS name resolution?

a)

dig example.com

b)

ip route show example.com

c)

ss -s

d)

arp -a example.com

115.

How can you view network interfaces?

a)

ip link show

b)

ip route list table all

c)

ss -tuln

d)

route -n

116.

How can you restart the network service?

a)

sudo systemctl restart NetworkManager

b)

sudo systemctl start sshd

c)

sudo ifconfig restart

d)

sudo service cron restart

117.

How can you add a static route?

a)

sudo ip route add 10.0.0.0/24 via 192.168.1.1

b)

sudo ifconfig eth0 add 10.0.0.0/24 gw 192.168.1.1

c)

sudo netstat -r add 10.0.0.0/24 via 192.168.1.1

d)

sudo route show add 10.0.0.0/24 gw 192.168.1.1

118.

How can you test network download speed?

a)

Run speedtest-cli

b)

Run ping -f

c)

Run netstat -s

d)

Run traceroute -d

119.

How can you view network interface statistics?

a)

ip -s link

b)

ip addr flush

c)

route -n

d)

ping -c 1 1.1.1.1

120.

How can you configure port forwarding using SSH?

a)

ssh -L 8080:remote.host:80 user@remote.host

b)

ssh -X 8080:remote.host:80 user@remote.host

c)

ssh --forward 8080 80 user@remote.host

d)

ssh -R 8080:remote.host:80 user@remote.host

121.

What is a shebang?

a)

The first line like #!/bin/bash that tells the OS which interpreter to use

b)

A Bash comment used to disable a script

c)

A special variable that stores the script name

d)

A file permission that makes a script executable

122.

How can you make a script executable?

a)

chmod +x script.sh

b)

chown +x script.sh

c)

exec script.sh

d)

bash --make-exec script.sh

123.

How can you declare a variable in Bash?

a)

NAME="value"

b)

let NAME = value

c)

var NAME = "value"

d)

declare NAME := "value"

124.

How can you output the value of a variable?

a)

echo "$NAME"

b)

printf NAME

c)

cat $NAME

d)

display ${NAME} without quotes

125.

How can you request user input?

a)

read NAME

b)

input NAME

c)

ask NAME

d)

gets NAME

126.

How can you pass arguments to a script?

a)

Provide them after the script name, for example ./script.sh arg1 arg2

b)

Write them into the script header with #ARGS=...

c)

Export them as environment variables only

d)

Use sudo to supply arguments interactively

127.

How can you check the number of passed arguments?

a)

Echo the special parameter $#

b)

Count words in $@ using wc

c)

Use ${#1} to get the total

d)

Check the variable $ARGC

128.

How can you reference the first script argument?

a)

$1

b)

$0

c)

$@

d)

$#

129.

How can you check if a file exists?

a)

if [ -f "file.txt" ]; then ... fi

b)

if [ -eql file.txt ]; then ... fi

c)

if test -d file.txt; then ... fi

d)

if [ file.txt ]; then ... fi

130.

How can you check if a file is a directory?

a)

if [ -d "/path" ]; then ... fi

b)

if [ -f "/path" ]; then ... fi

c)

if [ -x "/path" ]; then ... fi

d)

if [ -s "/path" ]; then ... fi

131.

How can you write an if conditional statement?

a)

if [ condition ]; then commands; fi

b)

if (condition) { commands }

c)

if condition: commands fi

d)

if: condition then commands end

132.

How can you compare strings in Bash?

a)

[[ " aa b" ]]

b)

[ aeqa -eq b ]

c)

a=a =* b in test

d)

compare " aa b" using -gt

133.

How can you compare numbers in Bash?

a)

[ " aa b" ]

b)

[[ " aa b" ]]

c)

[ " aa b" ]

d)

[ " aa b" ]

134.

How can you write a for loop?

a)

for i in 1 2 3; do echo "$i"; done

b)

for (i=1; i<=3; i++) echo $i

c)

foreach i (1 2 3) { print $i }

d)

loop i in 1..3 -> echo i

135.

How can you write a while loop?

a)

while condition; do commands; done

b)

while (condition) { commands }

c)

while: condition then commands end

d)

do while condition: commands done

136.

How can you process each line of a file in a loop?

a)

while IFS= read -r line; do commands; done < file.txt

b)

for line in file.txt; do commands; done

c)

cat file.txt | for each line; do commands; done

d)

read -f file.txt while true; do commands; done

137.

How can you create a function in Bash?

a)

greet() { echo "hi"; }

b)

function greet: echo "hi" end

c)

def greet(): echo "hi"

d)

func greet { echo "hi" }

138.

How can you call a function?

a)

Write its name, for example greet

b)

Use call greet()

c)

bash run greet

d)

exec function greet

139.

How can you return a value from a function?

a)

Echo the value and capture it with command substitution, for example result=$(myfunc)

b)

Use return 42 to pass a string result

c)

Assign to $1 inside the function to set the caller's variable

d)

Write to /proc/return

140.

How can you handle errors in a script?

a)

Enable strict mode, for example set -euo pipefail, and check exit statuses

b)

Ignore nonzero exit codes to keep running

c)

Redirect all errors to /dev/null to avoid failures

d)

Use sleep to delay failures until the end

141.

How can you view the status of a service?

a)

systemctl status nginx

b)

service nginx runlevel

c)

systemctl watch nginx

d)

chkconfig --state nginx

142.

How can you start a service?

a)

systemctl start nginx

b)

service nginx enable

c)

systemctl up nginx

d)

systemctl on nginx

143.

How can you stop a service?

a)

systemctl stop nginx

b)

systemctl killall

c)

systemctl disable nginx

d)

service nginx down-now

144.

How can you restart a service?

a)

systemctl restart nginx

b)

systemctl reload --all

c)

service nginx reset

d)

systemctl bounce nginx

145.

How can you enable a service at boot?

a)

systemctl enable nginx

b)

systemctl autostart nginx now

c)

service nginx boot-on

d)

systemctl start nginx --onboot

146.

How can you disable a service from startup?

a)

systemctl disable nginx

b)

systemctl stop-on-boot nginx

c)

service nginx boot-off

d)

systemctl mask-once nginx

147.

How can you view all running services?

a)

systemctl list-units --type=service --state=running

b)

systemctl list-unit-files --type=service

c)

journalctl -u sshd

d)

service --status-all

148.

How can you list all available services?

a)

systemctl list-unit-files --type=service

b)

systemctl list-units --type=service --state=running

c)

journalctl -xe

d)

systemctl status

149.

How can you view service dependencies?

a)

systemctl list-dependencies sshd

b)

journalctl -u sshd -p info

c)

systemctl cat sshd

d)

systemctl show -p Requires

150.

How can you check if a service is enabled?

a)

systemctl is-enabled sshd

b)

systemctl is-active sshd

c)

systemctl enable sshd --check

d)

systemctl status sshd | grep enabled