Explore fundamental Bash concepts with this quiz on file management commands and permissions. Practice identifying correct commands and understanding permission settings to strengthen your command-line skills.
Which Bash command is used to display a list of files and directories in the current working directory?
Explanation: The 'ls' command is used to list the contents of a directory, showing files and subdirectories. While 'cd' is used to change directories, 'mv' moves or renames files and directories, and 'pwd' prints the current directory path. Only 'ls' directly displays a list of files and directories present.
What is the correct Bash command to give the owner write permission on the file 'document.txt'?
Explanation: 'chmod u+w document.txt' correctly adds write permission for the file owner where 'u' stands for user (owner) and '+w' adds write permission. 'chmod g+w' would add write permission to the group, not the owner. 'chown' changes the owner of a file, not permissions, and 'chperm' is not a valid Bash command.
Which command will create an empty file named 'notes.txt' if it does not already exist?
Explanation: 'touch notes.txt' creates a new empty file if it doesn't exist or updates its timestamp if it does. 'make', 'mkfile', and 'addfile' are not standard Bash commands for file creation. While 'mkfile' exists in some environments, it is not commonly used in Bash systems.
What is the standard Bash command to remove a file named 'old_data.csv' from the current directory?
Explanation: 'rm old_data.csv' is the correct command in Bash for deleting a file. 'del' and 'delfile' are not standard commands in Bash, and 'remove' does not exist as a file removal command. Only 'rm' should be used for this purpose.
How would you move a file named 'photo.jpg' to a directory called 'images' in Bash?
Explanation: 'mv photo.jpg images/' moves the file to the 'images' directory. 'cp' would copy the file instead of moving it. 'move' and 'chmv' are not standard Bash commands for this operation. Only 'mv' directly moves files or directories in Bash.
In the permission string '-rw-r--r--', what does the first character '-' indicate about the file 'report.txt'?
Explanation: A leading '-' in a permission string means the entry is a regular file. A 'd' would indicate a directory, 'l' a symbolic link, and an 'x' in the permissions shows executability, but the first character itself doesn't signal executable status. Thus, only '-' represents a regular file.
If a user does not have read permission for a file, which action will be prevented?
Explanation: Read permission allows users to view file content. Lacking it will prevent viewing the file, but changing ownership and deletion depend on other permissions or user roles. Renaming the file also typically requires write permission on the directory. Only viewing the file's contents directly depends on read permission.
Which Bash command would you use to go from your current directory to the parent directory?
Explanation: 'cd ..' changes the current directory to its parent. 'cd /' goes to the root directory, 'cd ~' moves to the home directory, and 'cd parent' would only work if a folder named 'parent' existed. Only '..' is the shorthand for a parent directory in Bash.
What permissions does the numeric code '644' set for a file in Bash?
Explanation: '644' sets owner permissions to read/write (6), and group and others to read (4 each). 'rw-r--r--' accurately reflects this. The other options either flip owner/group roles, add execute permissions, or specify incorrect access. Only the correct answer outlines the permission breakdown matching '644'.
What is the correct Bash command to rename a file from 'draft.txt' to 'final.txt'?
Explanation: 'mv draft.txt final.txt' will rename the file by moving it to a new name in the same directory. 'rn', 'rename', and 'mvname' are not standard Bash commands for renaming in this simple context. Only 'mv' should be used for renaming files in Bash.