Challenge your understanding of key Linux commands such as ls, cd, cat, and grep with practical scenarios focused on navigation, listing files, viewing content, and searching text. This quiz is ideal for users aiming to enhance their command-line proficiency and boost their knowledge of essential Linux shell operations.
Which command would list all files, including hidden ones, with detailed information in the current directory?
Explanation: The 'ls -la' command shows a detailed listing of all files, including hidden files that start with a dot. The '-l' flag provides detailed information, and '-a' includes hidden files. 'ls -c' lists files but sorts by modification time, not displaying hidden files by default. 'ls -g' omits the owner information but also doesn't include hidden files or full details. 'ls -ld' displays details only about the directory itself, not its contents.
Which cd command will move you from '/home/user/projects' to its parent directory?
Explanation: 'cd ..' moves up one directory to the parent, so from '/home/user/projects' to '/home/user'. 'cd /' takes you to the root directory, not the parent. 'cd ~' navigates to the home directory. 'cd ./' keeps you in the current directory and does not change your location.
You want to display the contents of a file named 'notes.txt' in your current directory. Which command should you use?
Explanation: 'cat notes.txt' displays the contents of the file directly in the terminal. 'cut notes.txt' is incorrect because the 'cut' command is used for extracting sections from lines, not simply viewing a file. 'cet notes.txt' and 'cap notes.txt' are typographical errors and not valid commands. Only 'cat' is correct for this task.
If you want to find all lines containing the word 'error' in the file 'logfile.log', which command is appropriate?
Explanation: 'grep error logfile.log' searches the file for lines containing the word 'error'. 'grep -d logfile.log error' is an incorrect use of flags and order. 'grap error logfile.log' is a misspelling and is not a valid command. 'grep error | logfile.log' tries to pipe output but would not read the file as input. The correct usage is without additional symbols or typos.
Which command chain would display only the lines containing 'Linux' from a file named 'systems.txt'?
Explanation: Piping 'cat systems.txt' to 'grep Linux' displays only lines with 'Linux' from the file. 'cat systems.txt | find Linux' is not valid because 'find' searches for files, not text inside files. 'grab' is a typo and not a Unix command. 'grep -n1' is not a recognized option; '-n' is to number lines, but '-n1' is incorrect in this context.