Essential Bash Commands and Shortcuts Quiz Quiz

Explore the core tools and keyboard shortcuts used in Bash within the Linux ecosystem. This quiz is designed to assess your familiarity with practical Bash commands and common keyboard shortcuts critical for efficient command-line navigation and file management.

  1. Navigating Directories

    Which Bash command would you use to move up one directory from your current location in the filesystem (e.g., from /home/user/Documents to /home/user)?

    1. cd ..
    2. cd /
    3. cd .
    4. cd ~

    Explanation: The correct command to move up one directory is 'cd ..', where '..' refers to the parent directory. 'cd /' takes you to the root directory, which is not the parent in this context. 'cd .' keeps you in the same current directory. 'cd ~' takes you to your home directory and not the immediate parent. Understanding these differences is important for effective navigation in Bash.

  2. Searching for Text within Files

    To search for the word 'error' in a file named log.txt and display matching lines, which Bash command would you use?

    1. grep 'error' log.txt
    2. find 'error' log.txt
    3. search 'error' log.txt
    4. scan 'error' log.txt

    Explanation: The 'grep' command is designed to search for patterns or text strings within files, making 'grep 'error' log.txt' the correct answer. 'find' is used for locating files and directories, not for searching inside files. 'search' and 'scan' are not standard Bash commands for this purpose, and thus would not produce the desired results.

  3. Command-Line Editing Shortcut

    While typing a command in Bash, which keyboard shortcut quickly moves the cursor to the beginning of the line?

    1. Ctrl+A
    2. Ctrl+E
    3. Ctrl+Z
    4. Ctrl+C

    Explanation: Pressing Ctrl+A moves the cursor to the start of the command line, enabling rapid editing of the beginning of a command. Ctrl+E moves the cursor to the end of the line instead. Ctrl+Z suspends the current process, and Ctrl+C cancels the running command. Only Ctrl+A serves the purpose of quickly moving to the line’s start.

  4. Listing Hidden Files

    What is the Bash command to list all files, including hidden ones, in the current directory?

    1. ls -a
    2. ls -l
    3. ls -h
    4. ls --hide

    Explanation: Using 'ls -a' displays all files in the directory, including those that start with a dot, which are considered hidden. 'ls -l' provides a long listing format but does not show hidden files unless combined with '-a'. 'ls -h' makes file sizes human-readable but does not reveal hidden files. 'ls --hide' actually suppresses specified files rather than showing hidden ones.

  5. File Content Display

    Which command would best display the first ten lines of a file called notes.txt in Bash?

    1. head notes.txt
    2. top notes.txt
    3. first notes.txt
    4. show notes.txt

    Explanation: The 'head' command by default shows the first ten lines of a given file, making 'head notes.txt' the correct answer. 'top' is a command used for monitoring system processes, unrelated to file content viewing. 'first' and 'show' are not recognized Bash commands for displaying the start of a file. Knowing the right command helps in efficiently reviewing file contents.