Prepare for your Linux certification with these command practice questions. This guide covers file management, permissions, system administration, and bash scripting.
Q: In Bash, which of the following commands can you use to view the contents of a document. Check all that apply.
Answer: ls -la /home; You can use the ls command with the -la flags to show a long list of all files in a directory.ls -l -a/home
Q: In Bash, which of the following commands can you use to remove a directory named: “Miscellaneous Directory?”
Answer: rm -r Miscellaneous\ Directory; To remove a directory you have recursively remove the files with -r. Don’t forget that folders with spaces in the name have to be escaped with an \.
Q: In Bash, which of the following commands can you use to view the contents of a document.
Answer: cat; You can use the cat and less command to view the contents of a file.less
Q: In a Linux machine, you have the following files:apple.txtbanana.jpgchocolate.txtorange.txtWhat command can you use to search for the word “fruit” in the text files in the above directory? Check all that apply.
Answer: grep fruit apple.txt chocholate.txt orange.txt; You can use the grep command to search files for certain words. You can also use the * wildcard command to filter by a specific pattern.grep fruit *.txt
Q: In a Linux machine, you have a file named “types_of_fish.txt” and you want to append the word “trout” to the file contents. Which of the following commands can you use?
Answer: echo trout >> types_of_fish.txt; The >> is used as an append redirector.
Q: In a Linux machine, you want to list through a directory called /home/ben/Documents and search for the word “important” in the filenames in that directory. Which of the following commands can you use?
Answer: ls /home/ben/Documents | grep important; You can use the | command to pipe the output of one command into another.