How to Delete a File in Linux

How to Delete a File in Linux

In this Linux tutorial, we’re going to learn how to delete a file in Linux.

Let’s say you’ve created a test file and now you want to get rid of it. Linux gives you a simple command to do this: the rm command. Let's walk through it step-by-step.

Step 1: Open the Terminal

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

Quick Recap

  • 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!


Comments

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...