EX200 Essential Tools Practice Question
Which THREE actions will create a new empty file named 'testfile' in the current directory? (Choose three.)
⚠ Common exam trap
Many exam-takers think only `touch` creates an empty file, overlooking the shell redirection operator `>` used alone and the `cp /dev/null` technique, both of which are valid methods for creating or truncating files to empty.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
> testfile
The shell redirection operator `>` without a preceding command truncates or creates the specified file. When used alone, `> testfile` opens 'testfile' for writing, which creates an empty file if it does not exist, or truncates it to zero length if it does. This is a standard POSIX shell feature.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
> testfile
Why this is correct
This is a shell redirection with no command preceding the operator. The shell opens (or creates) the file with O_CREAT and O_TRUNC flags, and because nothing is written to stdout, the resulting regular file has zero length. This is one of the classic methods for creating an empty file, and it will also truncate an existing file to zero bytes.
- ✗
ls > testfile
Why it's wrong here
The ls command writes its directory listing output to stdout, which is redirected into the file. The redirection does create the file if it does not exist, but ls immediately populates it with filenames, permissions, and other metadata, so the final file is not empty. If the goal is a zero-byte file, this command fails because the captured output fills the file.
- ✓
touch testfile
Why this is correct
The touch utility updates the modification and access timestamps of the specified file. If the file does not exist, touch creates it as a new regular file with zero length, making it an effective and idempotent way to create an empty file. However, note that if the file already exists and contains data, touch will not erase that data; it only updates timestamps.
- ✓
cp /dev/null testfile
Why this is correct
The cp command copies the contents of /dev/null into the destination file. Since /dev/null is a special character device that reads as an endless stream of zero bytes—effectively no data at all—the copy operation results in a zero-length regular file. This approach also truncates an existing destination file, because cp opens the destination with O_CREAT and O_TRUNC before copying the zero bytes.
- ✗
echo "content" > testfile
Why it's wrong here
The echo command writes its argument followed by a newline to stdout, and the shell redirects that output into the file. The file is therefore created or truncated by the redirection, but it immediately receives the string 'content' plus a newline character. Consequently, the file is not empty; it contains eight bytes (seven characters plus the newline), so this does not satisfy the requirement of creating an empty file.
Go deeper
Related to this question
About these practice questions
This EX200 question is part of Courseiva's 427-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This EX200 practice question is part of Courseiva's free Red Hat certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the EX200 exam.