Site icon LinuxCommands.site

rm command tutorial in linux/unix with examples and use cases

linux rm command – remove files or directories

The linux rm command can remove each specified file. By default, the rm command cannot remove directories. if you need to remove directories, you need to use parameter.

Syntax

rm [OPTION]... [FILE]...

Options

Examples

Remove specified files

In the following example, we remove the file named test.log.

➜ rm test.log

Using regular, remove every matching file

In the following example, we remove each file that starts with the string “test”.

➜ rm test*

Remove directory

In the following example we remove the empty directory. If the directory is not empty, an error will be reported “rm: cannot remove ‘dir’: Directory not empty”

➜ rm -d dir

In the following example, we will remove a non-empty directory. Of course, you can also remove empty directories.

➜ rm -r dir

Remove files using interactive mode

In the following example, we are prompted to remove files.

➜ rm -i w-test.log

Remove files using force mode

In the following example, we use force to remove a file, even if the file does not exist, no error is reported.

➜ rm -f w.log

 

 

 

Exit mobile version