- 1How to Create a File in Linux
- 2How to Rename a File in Linux
- 3How to Copy a File in Linux
- 4How to Move a File in Linux
- 5How to Delete a File in Linux
- 6How to Create a Directory in Linux
- 7How to Delete a Directory in Linux
- 8How to Copy Directories Recursively in Linux
- 9Delete Directories Recursively in Linux
- 10How to View Hidden Files in Linux
- 11How to Create a Hidden File in Linux
- 12How to Create a Hidden Directory in Linux
- 13How to Find Files in Linux Using find Command
- 14Find Files in Linux Using locate Command
- 15How to View File Contents Using cat in Linux
- 16How to View File Contents Using less in Linux
- 17View File Contents Using the more Command in Linux
- 18Compare Files Using diff Command in Linux
- 19Compare Files in Linux Using cmp Command
- 20Check File Type in Linux with file Command
- 21Create Symbolic Links with ln -s in Linux
- 22How to Archive Files Using tar Command in Linux
- 23Compress Files with gzip in Linux – Beginner Tutorial
- 24How to Compress Files Using bzip2 in Linux
- 25Compress Files in Linux Using zip Command
- 26Extract Compressed Files using tar in Linux
- 27Extract ZIP Files on Linux with unzip
- 28How to Extract .gz Files using gunzip in Linux
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 filerm -i filename
– asks for confirmationsudo 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
Loading comments...