






























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!































































Question 1. Which command would you use to search recursively for the string "error" in all files within the /var/log directory? A) find /var/log - name "error" B) grep - r "error" /var/log C) sed 's/error//' /var/log/* D) cat /var/log | grep "error" Answer: B Explanation: The - r option in grep enables recursive search through all files in the specified directory. Question 2. What does the command ls - l display? A) Only filenames in the current directory B) File details including permissions, owner, size, and modification date C) The contents of files D) Hidden files only Answer: B Explanation: ls - l lists files with detailed information such as permissions, owner, size, and last modification date. Question 3. Which command is used to change a file’s owner to user “alice” and its group to “dev”? A) chmod alice:dev filename B) chown alice:dev filename C) chgrp alice:dev filename D) setowner alice:dev filename Answer: B Explanation: chown user:group filename changes the owner and group of a file. Question 4. You want to append the output of the date command to a file called logfile.txt. Which command should you use? A) date > logfile.txt B) date >> logfile.txt
C) date | logfile.txt D) date < logfile.txt Answer: B Explanation: >> appends output to the file, while > would overwrite it. Question 5. Which command is used to create a compressed archive named backup.tar.gz containing the /home/user directory? A) gzip - c /home/user > backup.tar.gz B) tar - czf backup.tar.gz /home/user C) zip backup.tar.gz /home/user D) tar - xf backup.tar.gz /home/user Answer: B Explanation: tar - czf creates a gzipped tarball; - c for create, - z for gzip, - f for filename. Question 6. Which command will display the first 10 lines of a file named data.txt? A) tail data.txt B) head data.txt C) less data.txt D) grep 10 data.txt Answer: B Explanation: The head command, by default, shows the first 10 lines of a file. Question 7. What does the command chmod 755 script.sh do? A) Gives read, write, and execute permissions to everyone B) Gives full permissions to the owner, and read/execute to group and others C) Removes all permissions from the file D) Sets the file as read-only Answer: B Explanation: 755 means owner can read/write/execute; group and others can read and execute.
D) systemctl list Answer: A Explanation: ps aux shows all processes running on the system. Question 12. How do you send the output of ls to both the screen and a file called out.txt at once? A) ls | tee out.txt B) ls > out.txt C) ls >> out.txt D) ls < out.txt Answer: A Explanation: The tee command writes output to both stdout and a file. Question 13. Which command can you use to show the last 20 lines of syslog? A) tail - n 20 /var/log/syslog B) head - n 20 /var/log/syslog C) cat /var/log/syslog | grep 20 D) less 20 /var/log/syslog Answer: A Explanation: tail - n 20 shows the last 20 lines. Question 14. Which command is used to recursively change all files in /opt/data to be owned by user “bob”? A) chown - R bob /opt/data B) chmod - R bob /opt/data C) chgrp - R bob /opt/data D) setowner - R bob /opt/data Answer: A Explanation: chown - R recursively changes ownership.
Question 15. What does the command cat file1 file2 > combined.txt do? A) Combines file1 and file2 into combined.txt B) Deletes file1 and file C) Appends file2 to file D) Sorts the contents of both files Answer: A Explanation: cat file1 file2 > combined.txt concatenates both files into one. Question 16. Which command compresses a file called report.txt using gzip? A) compress report.txt B) gzip report.txt C) tar report.txt D) zip report.txt Answer: B Explanation: gzip compresses a single file. Question 17. What is the result of the command echo $((5 + 3))? A) $((5 + 3)) B) 53 C) 8 D) 5 + 3 Answer: C Explanation: $((5 + 3)) evaluates the arithmetic operation and outputs 8. Question 18. Which command extracts the contents of an archive named photos.tar? A) tar - cvf photos.tar B) tar - xvf photos.tar C) gunzip photos.tar D) unzip photos.tar
B) ls - a C) showfiles D) ls - l Answer: B Explanation: ls - a shows all files including those starting with .. Question 23. Which command changes the permissions of file.txt to read and write for owner only? A) chmod 600 file.txt B) chmod 700 file.txt C) chmod 644 file.txt D) chmod 666 file.txt Answer: A Explanation: 600 gives read/write to owner, none to group/others. Question 24. Which command is used to install a package named “curl” using apt? A) apt install curl B) yum install curl C) zypper install curl D) pacman - S curl Answer: A Explanation: apt install is used on Debian/Ubuntu based systems. Question 25. How do you display the current working directory? A) pwd B) workdir C) lsdir D) cwd Answer: A Explanation: pwd prints the working directory.
Question 26. What does the command mv file1.txt dir1/ do? A) Copies file1.txt into dir1/ B) Moves file1.txt into dir1/ C) Deletes file1.txt D) Renames dir1 to file1.txt Answer: B Explanation: mv moves the file to the specified directory. Question 27. Which command lists the block devices available on the system? A) lsblk B) blkid C) fdisk - d D) parted Answer: A Explanation: lsblk lists all block devices in a tree format. Question 28. What is the purpose of sudo? A) Run commands as another user, typically with elevated privileges B) Switch to a different shell C) Save disk space D) Monitor system resources Answer: A Explanation: sudo executes commands with superuser privileges. Question 29. How do you view the manual page for the “tar” command? A) man tar B) help tar C) tar --help
Question 33. Which command creates an empty file named “testfile”? A) touch testfile B) mkfile testfile C) createfile testfile D) cat > testfile Answer: A Explanation: touch creates an empty file or updates its timestamp. Question 34. Which command can be used to view the content of compressed file report.txt.gz without decompressing it? A) less report.txt.gz B) gzip - d report.txt.gz C) zcat report.txt.gz D) tar - xf report.txt.gz Answer: C Explanation: zcat displays the content of a compressed file. Question 35. How do you find the difference between two files file1.txt and file2.txt? A) cmp file1.txt file2.txt B) grep file1.txt file2.txt C) diff file1.txt file2.txt D) sed file1.txt file2.txt Answer: C Explanation: diff shows line-by-line differences between two files. Question 36. What does the command sed 's/dog/cat/g' pets.txt do? A) Deletes all lines containing 'dog' B) Replaces all occurrences of 'dog' with 'cat' C) Sorts the file pets.txt
D) Counts the word 'dog' Answer: B Explanation: sed 's/dog/cat/g' replaces every occurrence of 'dog' with 'cat'. Question 37. Which command is used to extract files from a zip archive named archive.zip? A) unzip archive.zip B) tar - xvf archive.zip C) gunzip archive.zip D) extract archive.zip Answer: A Explanation: unzip extracts files from a zip archive. Question 38. How do you recursively search for the word “main” in all Python files in the current directory? A) grep - r "main" *.py B) grep "main" .py C) find. - name ".py" | xargs grep "main" D) grep - i main * Answer: C Explanation: find locates files, xargs grep searches within them recursively. Question 39. Which command lists all installed packages on a system using yum? A) yum list installed B) yum show packages C) rpm - qa D) apt list --installed Answer: A Explanation: yum list installed shows all packages installed by yum.
Answer: A Explanation: docker ps - a shows all containers, running and stopped. Question 44. How do you view logs from a running Docker container named web? A) docker logs web B) docker view web C) docker status web D) docker inspect web Answer: A Explanation: docker logs shows logs from a running container. Question 45. Which command will display the IP address assigned to the eth0 network interface? A) ip addr show eth B) ifconfig - a eth C) ip show eth D) netstat eth Answer: A Explanation: ip addr show eth0 displays the IP information for eth0. Question 46. How do you synchronize the system clock with NTP servers? A) ntpdate pool.ntp.org B) date --set C) hwclock --systohc D) setclock ntp Answer: A Explanation: ntpdate queries and sets the system time from NTP servers. Question 47. Which file would you edit to set the system’s default timezone? A) /etc/timezone
B) /etc/localtime C) /etc/clock D) /etc/time.conf Answer: A Explanation: /etc/timezone typically specifies the system timezone. Question 48. What does useradd - m alice do? A) Adds user alice without a home directory B) Adds user alice and creates a home directory C) Adds user alice with sudo privileges D) Adds a group named alice Answer: B Explanation: - m creates a home directory for the new user. Question 49. To change the password for user 'bob', which command should you use? A) passwd bob B) chpasswd bob C) setpasswd bob D) usermod - p bob Answer: A Explanation: passwd username changes the user’s password. Question 50. Which command deletes the user “eve” and removes their home directory? A) userdel eve B) userdel - r eve C) deluser eve D) deluser - r eve Answer: B Explanation: userdel - r deletes the user and their home directory.
D) apt install update Answer: A Explanation: apt-get update refreshes the local package index. Question 55. What is the effect of running yum remove httpd? A) Installs httpd B) Removes httpd and its configuration C) Removes httpd but keeps configurations D) Updates httpd Answer: B Explanation: yum remove removes the package and associated configuration files. Question 56. Which file contains the system hostname? A) /etc/hostname B) /etc/hosts C) /etc/network D) /etc/sysconfig Answer: A Explanation: /etc/hostname contains the system's hostname. Question 57. Which command displays the routing table? A) ip route B) route - n C) netstat - r D) All of the above Answer: D Explanation: All these commands can display routing information. Question 58. Which command can you use to display open network sockets?
A) netstat - tuln B) sockstat - a C) ip socket show D) lsof - i Answer: D Explanation: lsof - i lists open Internet sockets. Question 59. Which command sets the system date and time to 2024- 03 - 01 10:00:00? A) date --set="2024- 03 - 01 10:00:00" B) setdate 2024- 03 - 01 10:00: C) timedatectl set-date "2024- 03 - 01 10:00:00" D) hwclock --set="2024- 03 - 01 10:00:00" Answer: A Explanation: date --set sets the system date and time. Question 60. How do you mount the /dev/sdb1 partition to /mnt/data? A) mount /dev/sdb1 /mnt/data B) mnt /dev/sdb1 /mnt/data C) mount /mnt/data /dev/sdb D) mount - a /dev/sdb1 /mnt/data Answer: A Explanation: mount [device] [mountpoint] mounts the device. Question 61. Which command lists filesystems currently present on the system? A) cat /proc/filesystems B) mount - l C) fslist D) blkid Answer: A
C) id - g D) getent group Answer: A Explanation: groups shows all groups of the current user. Question 66. How do you display all files in /var that were modified within the last 24 hours? A) find /var - mtime - 1 B) find /var - ctime 24 C) find /var - mmin 1440 D) ls - l /var Answer: A Explanation: - mtime - 1 finds files modified in the last day. Question 67. What is the effect of the command chmod o+w file.txt? A) Adds write permission for owner B) Adds write permission for others C) Removes write permission for others D) Adds write permission for group Answer: B Explanation: o+w adds write for others. Question 68. Which command searches for the string "test" in all files in /tmp and prints filename and line number? A) grep - rn "test" /tmp B) grep - l "test" /tmp C) grep - n "test" /tmp D) grep - R "test" /tmp Answer: A Explanation: - r for recursive, - n for line number.
Question 69. To see the last login time for all users, which command should you use? A) lastlog B) who C) w D) users Answer: A Explanation: lastlog shows last login times for all users. Question 70. Which command displays the number of lines, words, and characters in a file named letter.txt? A) wc letter.txt B) count letter.txt C) lines letter.txt D) nl letter.txt Answer: A Explanation: wc (word count) displays lines, words, and bytes. Question 71. Which command is used to delete all .tmp files in the /tmp directory? A) rm /tmp/.tmp B) del /tmp/.tmp C) remove /tmp/.tmp D) rm - r /tmp/.tmp Answer: A Explanation: rm /tmp/*.tmp deletes all files ending with .tmp. Question 72. What does the command chmod 777 file.sh do? A) Makes file.sh readable and writable by owner only B) Grants all permissions to everyone