←  linux commands

Views:

rm command

The rm command is used to remove the file(s).

Syntax: rm [options] file

Example:

rm main.js
rm-output

Options:

-r To remove directories and its content recursively

Example

rm -r folder
rm-recursive-output
-f To ignore non existent files

Example

rm -f file{1..5}.txt

In below example, we have taken four files - file{1,2,4,5}.txt and we tried to remove it using loop from 1 to 5 with and without -f flag. We can see if we don't use the force flag i.e. -f, we get a message saying No such file or directory. And when we added -f flag it ignored all non-existent files.

rm-force-output
-i Ask before removing files

Example

rm -ri ./*

Note: Added recursive flag (r) also to remove directories recursively.

rm-prompt-output