‘ Operating systems ’ category archive

Removing files and directories in unix using RM

May 08, 08 by the programmer

If you want to remove a file or directory in unix you should use the command rm.

The syntax of the rm command is:

rm [-options] [file|directory]

There are more options, but the most used ones are

-r or -R which means recursivly.

-f which means force (Does not ask you for confirmation)

Examples:

If you want to remove a single file you should use

rm filename.ext

if you want to remove a nempty directory you can use

rm directory_name

if you want to remove a directory that is not empty (contains files or other directories) use this command

rm -r directory_name

If you don’t want the command to ask for a confirmation then you can use the -f option in any of the above commands

rm -rf directory_name - Removes the directory “directory_name” and all of its files and other directories inside it without asking for confirmation

Good luck :)