rm command – delete files and directories in Linux?

Spread the love

rm command in Linux –

The rm command stands for remove. The rm command delete files and directories.

Let’s use ls command to see all the files and directories in our current working directories.

Here, we have 3 test files. Let’s say that I want to delete the test1.py file.

rm test1.py

We can see that test1.py has been deleted. Let’s go one step back and list all the files and directories.

cd ..

Here we have one file factorial.py and a directory test which contains the test2.py and test3.py file.

Let’s say we want to delete the test directory along with all the files inside of it.

To do that we use the -r flag. The -r stands for “recursive,” and it’s used to delete a directory and all of its child directories.

rm -r test/

We can see that test directory has been deleted from the current working directory.

Rating: 1 out of 5.

Leave a Reply