CompTIA Linux+ (XK0-004) — Question 37
An administrator needs to create a file named hello in the home directory that contains the following text: it's me!
Which of the following commands would accomplish this goal?
Answer options
- A. mkdir ~/hello touch ~/"it's me!"
- B. touch ~/hello echo "it's me!" > ~/hello
- C. mv ~/hello cp "it's me!" > ~/hello
- D. type ~/hello print "it's me!"
Correct answer: B
Explanation
Option B is correct because it first creates an empty file named hello and then writes the specified text into that file. Option A is incorrect because it attempts to create a directory instead of a file. Option C is not valid as it combines commands incorrectly and does not create the intended file. Option D is also incorrect since it uses the wrong command to print text into a file.