wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz 1: Commands for Searching and Working with Files

Total questions: 67

Worksheet time: 36mins

Name
Class
Date
1.

To search for text inside files:

a)

search

b)

locate

c)

find

d)

grep

2.

How do you search only for directories with find?

a)

find / -type d

b)

find / -type f

c)

find / -folder

d)

find / -dir

3.

You need to count how many times "Failed" appears in /var/log/syslog. Which command is correct?

a)

wc -l /var/log/syslog

b)

grep "Failed" /var/log/syslog

c)

grep -c "Failed" /var/log/syslog

d)

cat /var/log/syslog | wc -c

4.

How do you search all .txt files in Assignment3_Ann?

a)

grep "*.txt"

b)

find . -name "*.txt"

c)

ls *.txt

d)

locate .txt

5.

How do you search for a file named "file1.txt" in /home directory using find?

a)

find / -name file1.txt

b)

find /home -name file1.txt

c)

locate file1.txt

6.

You want to search recursively for the string “ERROR” in all .log files inside /var/log. Which command is correct?

a)

grep ERROR /var/log/*.log

b)

grep -r --include="*.log" "ERROR" /var/log

c)

find /var/log --name "*.log" --exec grep ERROR

d)

Both B and C

7.

To search for a specific word in a file, you use:

a)

grep

b)

wc

c)

cut

d)

sort

8.

How do you search for a specific string in a file?

a)

locate string

b)

find filename string

c)

grep "string" filename

d)

cat filename | string

9.

The difference between local and environment variables is that:

a)

Local variables can only be used by root

b)

Environment variables cannot be exported

c)

Environment variables are global to all shells

d)

Local variables persist after logout

10.

Using a pair of back quotes (`) will cause a shell to execute the back-quoted text as a command and substitute the output back into the original command.

a)

True

b)

False

11.

What does . at the beginning of a filename indicate?

a)

Script file

b)

Directory

c)

Hidden file

d)

Executable file

12.

What does a single dot . represent?

a)

Home directory

b)

Parent directory

c)

Root directory

d)

Current directory

13.

The tilde (~) is used to represent:

a)

The directory above the current working directory

b)

Nothing, it has no special meaning

c)

Any two single characters

d)

A user’s home directory

14.

Which symbol is used in commands to execute a file from the current directory?

a)

/

b)

~

c)

./

d)

...

15.

The command echo $HOME > /home/user/docs/homepath.txt will:

4 lines
16.

The primary difference between the > and >> redirection operators is:

a)

> overwrites a file, while >> appends output to it.

b)

>> redirects standard error, while > redirects standard output.

c)

> creates a binary file, while >> creates a text file.

d)

Both are identical in function.

17.

How do you append the current date to file3.txt?

a)

cat date > file3.txt

b)

echo date > file3.txt

c)

touch file3.txt

d)

date >> file3.txt

18.

You are in /home/user and want to switch to /home/user/Documents using a relative path. Which command works?

a)

cd Documents

b)

cd ./Documents

c)

Both A and B

d)

cd ~/Documents

19.

If you type cd -, which directory will you go to?

a)

/home

b)

Root directory

c)

/tmp

d)

The previous directory you were in

20.

The cd command by itself will take you to what directory?

a)

All are correct

b)

Your home directory

c)

The system root directory

d)

The directory above the current working directory

21.

Where is the root user’s home directory located by default?

a)

/etc/root

b)

/home/root

c)

/root

d)

/usr/root

22.

The root directory in Linux is represented by:

a)

C:\

b)

/

c)

~/

d)

/root

23.

You are in /home/user/Documents/Projects and want to navigate to /home/user/Downloads. Which command is correct?

a)

cd ~/Downloads

b)

cd ./Downloads

c)

cd /Downloads

d)

cd ././Downloads

24.

Which command will allow you to change to a directory located in the root directory?

a)

cd /

b)

cd ...

c)

cd ~

d)

cd /

25.

The cp command is used to:

a)

Compile code

b)

Compare files

c)

Compress a file

d)

Copy files

26.

The command that creates a new directory is:

a)

mkfile

b)

createdir

c)

mkdir

d)

make

27.

Which command removes a file permanently?

a)

rm

b)

erase

c)

del

d)

delete

28.

Executing rmdir -p empty/inner/ removes:

a)

Nothing — command requires -r

b)

Both inner/ and its parent empty/ if they are empty

c)

None of the above

d)

Only inner/

29.

Which command is used to create a new file in Linux?

a)

cp

b)

mv

c)

touch

d)

mkdir

30.

How do you open file1.txt in a text editor and write your info?

a)

nano file1.txt

b)

cat file1.txt

c)

touch file1.txt

d)

ls file1.txt

31.

Which command displays the contents of a file on the terminal?

a)

rm filename

b)

ls filename

c)

touch filename

d)

cat filename

32.

Which command combines and displays the contents of files sequentially?

a)

paste

b)

join

c)

merge

d)

cat

33.

To view the first 10 lines of a file:

a)

view

b)

start

c)

tail

d)

head

34.

What is the command used to display the contents of a file in reverse order in Linux?

a)

head

b)

cat

c)

less

d)

tac

35.

How do you copy about_me.txt to backup.txt inside docs?

a)

nano docs/backup.txt

b)

touch docs/backup.txt

c)

mv about_me.txt docs/backup.txt

d)

cp about_me.txt docs/backup.txt

36.

You want to move file3.txt into docs and then copy about_me.txt into docs as backup.txt, all in one line. Which command is correct?

a)

mv file3.txt docs/backup.txt && cp about_me.txt docs/

b)

cp file3.txt docs/; mv about_me.txt docs/backup.txt

c)

mv file3.txt docs/ && cp about_me.txt docs/backup.txt

d)

touch docs/file3.txt docs/backup.txt

37.

Which command is used to copy a file from one directory to another in Linux?

a)

cp

b)

rm

c)

mkdir

d)

mv

38.

Which command is used to move a file in Linux?

a)

move

b)

rename

c)

cp

d)

mv

39.

You want to create a hidden file .config in your home directory. Which command works?

a)

touch config

b)

touch /config

c)

touch ./config

40.

Where is the root user’s home directory located by default?

a)

/etc/root

b)

/home/root

c)

/root

d)

/usr/root

41.

Which command displays the current username?

a)

logname

b)

id

c)

who

d)

whoami

42.

To see current logged-in users:

a)

log

b)

id

c)

who

d)

users

43.

Which command displays memory usage?

a)

top

b)

free -h

c)

df -h

d)

uname -r

44.

Which command shows environment variables?

a)

getenv

b)

showenv

c)

env

45.

Which command displays the system hostname?

a)

host

b)

iphost

c)

dnsname

d)

hostname

46.

Which command is used to display the IP address of the computer?

a)

netstat

b)

ipconfig

c)

ifconfig

d)

netconfig

47.

Which command displays the file and directory permissions in octal format?

a)

chmod

b)

ls -l

c)

chown

d)

stat

48.

Which command displays file type, size, permissions, and modification date?

a)

file

b)

ls

c)

ls -lh

d)

stat

49.

To display permissions of all files in a directory:

a)

ls -a

b)

ls

c)

ls -l

50.

What is the command to list all the hidden files in a directory?

a)

ls -a

b)

ls -l

c)

ls -h

d)

ls -R

51.

What does ~/Documents refer to?

a)

/Documents directory in root

b)

Documents folder in /tmp

c)

Documents folder inside the current user's home directory

d)

Documents folder in current directory

52.

The file /etc/passwd contains:

a)

User passwords

b)

Group permissions

c)

User account information

d)

System logs

53.

Which option generally works to get quick usage information for most Linux commands?

a)

--help

b)

man

c)

guide

d)

info

54.

To get basic help for shell built-in commands, you can use:

a)

guide

b)

man

55.

The ‘man’ command is used to:

a)

Run a program as another user

b)

Display manual pages for a command

c)

Display a file’s contents

d)

Create a new user

56.

Which command displays the manual page for a command in Linux?

a)

info

b)

man

c)

guide

d)

help

57.

What does whatis command do?

a)

Shows a short description of a command

b)

Opens a manual page

c)

Shows all options for a command

d)

Searches online Linux documentation

58.

The whatis command is the same as man -w.

a)

False

b)

True

59.

Select the command that can report the location of a command:

a)

where

b)

what

c)

which

d)

sudo

60.

This command is normally executed to search for a command or man page:

a)

man -k

b)

updatedb

c)

find

d)

wheres

61.

Which command compresses a file using gzip?

a)

tar file

b)

gzip file

c)

zip file

d)

compress file

62.

Which tar command correctly creates a compressed archive using gzip?

a)

gzip -cvf archive.tar dir/

b)

tar -czvf archive.tar.gz dir/

c)

tar -xvf archive.tar dir/

d)

tar -cvf archive.tar.gz dir/

63.

The command to extract contents of a .tar archive:

a)

untar archive.tar

b)

tar -xvf archive.tar

c)

unzip archive.tar

d)

xz -d archive.tar

64.

What command can be used to compress a file using the LZMA algorithm?

a)

lzma

b)

zip

c)

gzip

65.

The 'grep' command is used for:

a)

Searching for patterns in text

b)

Editing text files

c)

Displaying system processes

d)

Compressing data

66.

What does the "grep" command do?

a)

It creates a new directory.

b)

It removes a file or directory.

c)

It compresses files and directories.

d)

It searches for a specific text within a file.

67.

Which command shows the PID, CPU%, MEM%, and COMMAND columns for all processes?

a)

http

b)

ps aux

c)

top -b

d)

pstree