In today’s article I will tell you how to Delete Files In Linux with (rm command).
We use the rm command to delete a file or directory. We need to think carefully when using this command because when it is deleted, it can be a little difficult to restore. For this, you should think carefully before deleting something.
General usage:
rm directory or file
Example Usage:
1 |
rm /home/farukerdem/text2 |
In the above example, we used it to delete the text file under the /home/farukerdem directory.
How do we do when we want to delete a file in the directory?
1 |
rm /home/farukerdem/d1 |
If you do as above, you will receive an error message like the one below. This is because you didn’t use the -r parameter when you wanted to delete the files.
We use the -r parameter to delete the file in the directory.
1 |
rm -r /home/farukerdem/d1 |
At the beginning of my article, I said that you should think carefully before deleting. I recommend using the rm command with the -i parameter until you know the Linux commands and the linux file structure well.
What does the “-i” parameter do? Before doing a deletion, it asks you if you want to delete this file, you can think of it as your last chance to check before deleting and before you go wrong.
Let’s delete our text file named textfile in the directory below.
1 |
rm -i textdosyasi |
When we run the command it asks as follows.
To delete, we type “y” and press enter to perform the deletion process. If you don’t want to delete it, typing “n” and pressing enter will cancel the deletion. If you want to delete in the directory, you can delete it using two parameters as follows.
1 |
rm -ri /home/farukerdem/d1 |
-f parameter : -f parameter means force. It is used to mean force to delete.
Example usage:
1 |
rm -f /home/farukerdem/textdosyasi.txt |
To delete a file
1 |
rm -rf /home/farukerdem/d1 |