Removing(Deleting) Files and Directories with rm Command on GNU/Linux

rm which is shorthand for remove, removes files and directories. But by default, it does not delete directories. For full documentation please refer to coreutils documentation of your operating system. Given below is synopsis:

rm [option]… [file]…

Typical usage is rm filenames, where filenames can be one file or many files or a regular expression. To remove a directory you use rm -r dir which will cause recursive deletion of all files and directories specified.

If the -I or --interactive=once option is given, and there are more than three files or the -r, -R, or --recursive are given, then rm prompts the user for whether to proceed with the entire operation. If the response is not affirmative, the entire command is aborted.ttps://github.com/Unvanquished/PrototypeRendererIf the -I or --interactive=once option is given, and there are more than three files or the -r, -R, or --recursive are given, then rm prompts the user for whether to proceed with the entire operation. If the response is not affirmative, the entire command is aborted.

Otherwise, if a file is unwritable, standard input is a terminal, and the -f or --force option is not given, or the -i or --interactive=always option is given, rm prompts the user for whether to remove the file. If the response is not affirmative, the file is skipped.

Any attempt to remove a file whose last file name component is . or .. is rejected without any prompting, as mandated by POSIX.

Warning: If you use rm to remove a file, it is usually possible to recover the contents of that file. If you want more assurance that the contents are truly unrecoverable, consider using shred.

Removing a directory

-d or --dir removes a directory if the directory is empty. Use it like rm -d dir

Forcing deletion

-f or --force makes rm ignore nonexistent files and never prompts user. Ignores any previous -i or --interactive option. Use it like rm -f filename or rm -rf dirname.

With this we come to an end of most important usage options of rm command.

Leave a comment

Your email address will not be published. Required fields are marked *