Delete a Chosen File

Delete a Chosen File

The teacher has a disposable draft that she no longer needs. Linux can remove that file with rm, but this is worth understanding before you use it on real work. A command-line removal normally does not send the file to your desktop's trash folder or provide a convenient undo button.

The useful habit is to identify the exact path first, then decide whether you want a confirmation. We will practice with a file created just for this example, and learn why a quiet result needs a check afterward.

What you’ll learn

  • Remove a disposable draft with an explicit confirmation.
  • Check the exact path and distinguish removal from an undoable trash operation.

Removing an entry is different from emptying its content

  1. Exists

    The disposable draft has a pathname and saved text.

    draft.txt: Draft
  2. Remove

    rm removes the directory entry; it does not move it to a desktop trash folder.

    rm draft.txt
  3. Check

    Test whether that pathname still exists rather than treating silence as proof.

    draft.txt absent
Treat removal as a decision about a specific directory entry.

Remove a disposable draft and check its absence

Prepare the example

Choose a fresh practice directory. The first line creates the only file we intend to remove. Do not replace its filename with a real report while learning the command. The simple demonstration removes that disposable file without a prompt; use rm -i when practicing the confirmation form.

Bash · Linux terminal

printf 'Draft\n' > draft.txt
rm draft.txt
test ! -e draft.txt && printf 'Draft removed\n'

Expected result

Draft removed

After printf prepares draft.txt, rm draft.txt removes that pathname. The last line uses test ! -e draft.txt: the exclamation mark negates the existence check, so the message prints when the path is absent.

That check is more informative than 'nothing appeared after rm.' A successful removal is often quiet, and a diagnostic or exit status is needed when something goes wrong. The -i option asks before removing, whereas -f suppresses certain prompts and missing-file diagnostics. Neither option substitutes for reading the path carefully. Ordinary removal also is not a promise of secure erasure from storage or backups.

Locate the draft before removing its entry

The rm command removes files directly from the filesystem. In a normal terminal session, the file does not go to a desktop Trash folder, so checking the filename before you run the command matters.

Open a terminal in the directory containing the file

First, open your terminal. You can usually do this by pressing Ctrl + Alt + T or searching for "Terminal" in your application menu.

Step 2: Go to the Directory Where Your File Is

You need to navigate to the folder where your file is located. Use the cd command:

cd ~/Documents

Step 3: Use rm to Delete the File

Now, to delete a file named test.txt, just type:

rm test.txt

If the file is deleted successfully, you won’t see any message — and that’s normal! Linux assumes you want silence unless there’s an error.

Example

ls
rm test.txt
ls
test.txt
# (after rm command)
# file is gone

Important Tips

  • Make sure you spell the file name correctly—there’s no "undo" for rm unless you're using a trash/recycle-bin setup.
  • To get a confirmation before deleting, use -i flag:
rm -i test.txt
rm: remove regular file 'test.txt'? y

Type y and press Enter to confirm deletion.

Permission Errors?

If you get a permission denied error, try using sudo:

sudo rm protected.txt

Use rm carefully when removing files

  • rm filename – deletes a file
  • rm -i filename – asks for confirmation
  • sudo rm filename – use with caution for protected files

And that’s it! You’ve learned how to delete files in Linux.

In the next lesson, we’ll look at how to delete directories. Until then, keep experimenting safely!

Try it, then check the worked answer

Your task: Ask for confirmation before deleting a draft.

Choose a fresh practice directory. The first line creates the only file we intend to remove. Do not replace its filename with a real report while learning the command. The simple demonstration removes that disposable file without a prompt; use rm -i when practicing the confirmation form.

Bash · complete example for this question

printf 'Draft\n' > draft.txt
rm draft.txt
test ! -e draft.txt && printf 'Draft removed\n'

Expected result

Draft removed

Worked answer

rm -i draft.txt

Use rm -i draft.txt to request confirmation. Read the prompt and the path before approving it. A plain rm does not guarantee a prompt, and -f is the opposite of the deliberate confirmation you are trying to add.

Check your decision

Ask for confirmation before deleting a draft.
Choose one answer. You can try again.

Answer and explanation

rm -i draft.txt

Use rm -i draft.txt to request confirmation. Read the prompt and the path before approving it. A plain rm does not guarantee a prompt, and -f is the opposite of the deliberate confirmation you are trying to add.

Removal needs the exact target, not a guess

Treat removal as a decision about a specific directory entry. Confirm the path, use a disposable practice file, and inspect the result. If you need a recoverable workflow for important reports, arrange that before deletion rather than expecting rm to create one for you.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Create a Directory Structure →