CompTIA Linux+ Linux GNU and Unix Commands 1 — Questions and Answers
Question 1: Which of the following commands is used to display the current working directory in Linux?
- ls
- pwd (Correct answer)
- cd
- dir
Correct answer: pwd
The `pwd` command (print working directory) displays the full path of the current directory you are operating in. This is a fundamental command for navigating the file system, as it helps users understand their current location within the directory hierarchy. It ensures you know exactly where commands will be executed or files will be created.
Question 2: Which of the following commands is used to change the ownership of a file in Linux?
- chown (Correct answer)
- chmod
- chgrp
- ls
Correct answer: chown
The `chown` command (change owner) is used to change the user owner and/or group owner of files or directories in Linux. This command is crucial for managing file permissions and ensuring that the correct users or groups have administrative control over specific resources. Proper ownership is a key aspect of Linux security.
Question 3: Which command is used to view the contents of a text file, one page at a time?
- cat
- less (Correct answer)
- more
- head
Correct answer: less
The `less` command is used to view the contents of a text file, allowing users to scroll forward and backward through the file one page or line at a time. Unlike `cat`, `less` does not load the entire file into memory, making it efficient for large files. It also offers powerful search capabilities, making it a versatile tool for file inspection.
Question 4: Which of the following commands is used to search for a specific pattern in a file in Linux?
- grep (Correct answer)
- find
- locate
- search
Correct answer: grep
The `grep` command (global regular expression print) is used to search for specific patterns of text within files. It can filter lines that match a given regular expression, making it an indispensable tool for log analysis, code searching, and data extraction. `grep` is highly versatile and widely used for text processing in Linux.
Question 5: What does the chmod command do in Linux?
- Changes file ownership
- Changes file permissions (Correct answer)
- Creates a new file
- Changes the group of a file
Correct answer: Changes file permissions
The `chmod` command (change mode) is used to change the file permissions (read, write, execute) for the owner, group, and others on a Linux system. These permissions dictate who can access and modify files and directories. Correctly setting permissions with `chmod` is fundamental for system security and access control.
Which of the following commands is used to display the current working directory in Linux?