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.
Which Bash command displays a list of all files, including hidden files, in the current directory?
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.
Which command should you use to create a new directory called 'projects' in the current location?
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.
How can you remove a file named 'notes.txt' from your current directory in Bash?
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.
If a file has permissions shown as 'rw-r--r--', which of these statements is correct?
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.
What command would you use to add execute permission for the owner on a script named '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.
Which command moves a file called 'report.pdf' from the current directory to a directory named '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.
Which Bash command changes the owner of a file called 'data.csv' to a user named 'alex'?
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.
You have three files: 'a.txt', 'b.txt', and 'c.txt'. Which command copies all three to a folder named '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.
Which Bash command lists files in a directory along with their sizes and permissions in a detailed format?
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.
What command do you use in Bash to display your present working directory?
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.