File Management and Permissions Basics in Bash Quiz

This quiz explores fundamental Bash commands for file management and permissions, helping users strengthen their grasp of file operations, permission logic, and safe command usage. Ideal for beginners, it covers essential Bash tasks like navigating directories, adjusting access rights, and managing files effectively.

  1. Understanding File Listing

    Which Bash command displays a list of all files, including hidden files, in the current directory?

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

    Explanation: The command 'ls -a' shows all files, including those starting with a dot, which are hidden by default. 'ls -l' shows a long listing but not hidden files. 'ls -h' shows file sizes in a human-readable format, and 'ls -r' reverses the listing order. Only 'ls -a' ensures hidden files are displayed.

  2. Creating a New Directory

    Which command should you use to create a new directory called 'projects' in the current location?

    1. touch projects
    2. cp projects
    3. rm projects
    4. mkdir projects

    Explanation: The 'mkdir projects' command creates a new directory named 'projects.' 'touch projects' creates a regular file, not a directory. 'cp projects' attempts to copy a file or directory, and 'rm projects' is used to remove or delete, not create. 'mkdir' is specifically for making directories.

  3. Deleting a File Safely

    How can you remove a file named 'notes.txt' from your current directory in Bash?

    1. del notes.txt
    2. rmdir notes.txt
    3. mv notes.txt
    4. rm notes.txt

    Explanation: 'rm notes.txt' deletes the file 'notes.txt.' 'mv notes.txt' is for moving or renaming files. 'rmdir notes.txt' removes empty directories, not files, and will fail on regular files. 'del notes.txt' is not a standard Bash command; it is used in other operating systems.

  4. Understanding Permission Notation

    If a file has permissions shown as 'rw-r--r--', which of these statements is correct?

    1. Only the owner can read and write and execute
    2. The owner can read and write, others can read only
    3. The file is hidden from all users
    4. All users can read, write, and execute

    Explanation: In the 'rw-r--r--' permission string, the owner has read and write access, while the group and others have only read access. The second option incorrectly adds execute permission, which is absent. Full permissions for all would be 'rwxrwxrwx,' and 'rw-' does not make a file hidden.

  5. Modifying File Permissions

    What command would you use to add execute permission for the owner on a script named 'backup.sh'?

    1. chmod u+x backup.sh
    2. chmod a+x backup.sh
    3. chmod x+u backup.sh
    4. chown u+x backup.sh

    Explanation: 'chmod u+x backup.sh' adds execute permission for the owner (user) only. 'chmod a+x backup.sh' gives execution rights to everyone, not just the owner. 'chown' changes the ownership, not permissions. 'chmod x+u' is not valid Bash syntax for permission changes.

  6. Moving Files to Another Directory

    Which command moves a file called 'report.pdf' from the current directory to a directory named 'docs'?

    1. cp report.pdf docs/
    2. rm report.pdf docs/
    3. mv report.pdf docs/
    4. cat report.pdf docs/

    Explanation: The 'mv report.pdf docs/' command moves the file to the 'docs' directory. 'cp report.pdf docs/' would copy the file instead of moving it. 'cat report.pdf docs/' attempts to concatenate and output content, and 'rm report.pdf docs/' is not a valid syntax for either moving or deleting across directories.

  7. Changing File Ownership

    Which Bash command changes the owner of a file called 'data.csv' to a user named 'alex'?

    1. chmod alex data.csv
    2. chown data.csv alex
    3. chown alex data.csv
    4. ownerchange alex data.csv

    Explanation: 'chown alex data.csv' changes the file's ownership to 'alex.' 'chmod' adjusts permissions, not ownership. Placing 'data.csv' before 'alex' is incorrect syntax. 'ownerchange' is not a standard Bash command.

  8. Copying Multiple Files at Once

    You have three files: 'a.txt', 'b.txt', and 'c.txt'. Which command copies all three to a folder named 'archive'?

    1. copy a.txt b.txt c.txt archive/
    2. mv a.txt b.txt c.txt archive/
    3. cp a.txt b.txt c.txt archive/
    4. cat a.txt b.txt c.txt archive/

    Explanation: 'cp a.txt b.txt c.txt archive/' copies all three files into 'archive.' 'mv' would move rather than copy, 'cat' is used for viewing or combining file contents and would not copy files, and 'copy' is not valid in Bash.

  9. Listing File Details

    Which Bash command lists files in a directory along with their sizes and permissions in a detailed format?

    1. ls -t
    2. ls -a
    3. ls -s
    4. ls -l

    Explanation: 'ls -l' lists detailed information including permissions and file sizes. 'ls -a' shows all files, including hidden ones, but not with details. 'ls -s' shows file sizes, but not the permissions or other details, and 'ls -t' orders files by time, not by detail.

  10. Checking Your Current Working Directory

    What command do you use in Bash to display your present working directory?

    1. pwd
    2. cd
    3. ls
    4. echo

    Explanation: 'pwd' prints the path of the current directory. 'cd' is used to change directories, not display them. 'ls' lists files, and 'echo' prints messages or variable values, but does not specifically display the current working directory.