rm (Unix)

From Wikipedia, the free encyclopedia

Jump to: navigation, search

rm (short for remove) is a Unix command used to delete files from a filesystem.

Contents

Common options that rm accepts include:

  • -r, which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in)
  • -i, which asks for every deletion to be confirmed
  • -f, which ignores non-existent files and overrides any confirmation prompts ("force")

rm is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).

rm -rf (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf / variant of the command, if run by an administrator, would cause the contents of every writable mounted filesystem on the computer to be deleted.

rm is often used in conjunction with xargs to supply a list of files to delete:

xargs rm < filelist

When rm is used on a symbolic link, it deletes the link, but does not affect the target of the link.

Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant.)

To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.

If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.

Sun introduced "rm -rf /" protection in to Solaris 10. Upon executing the command, the system now reports that the removal of / is not allowed.[1]

Wikibooks
Wikibooks Guide to Unix has a page on the topic of
Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.