Rm (Unix)

Rm (Unix)

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

Options

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) ("recursive")
* -i, which asks for every deletion to be confirmed ("interactive")
* -f, which ignores non-existent files and overrides any confirmation prompts ("force")
* -v, which shows what is being removed as it happens ("verbose")

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 a superuser, 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.

Permissions

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.

Trivia

Sun introduced "rm -rf /" protection in to Solaris 10. Upon executing the command, the system now reports that the removal of / is not allowed. [ [http://blogs.sun.com/jbeck/date/20041001#rm_rf_protection Meddling in the Affairs of Wizards ] ] GNU rm refuses to execute rm -rf / if the --preserve-root option is given, which has been the default since version 6.4 of GNU Core Utilities was released.

See also

* unlink(): the underlying system call called by this user space program for its main functionality

References

External links

*man|cu|rm|SUS|remove directory entries
*man|1|rm|Linux|remove files or directories


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Unix — (officially trademarked as UNIX, sometimes also written as Unix with small caps) is a computer operating system originally developed in 1969 by a group of AT T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and… …   Wikipedia

  • UNIX — Ken Thompson und Dennis Ritchie Basisdaten Entwickler …   Deutsch Wikipedia

  • Unix — Kommandozeile (Unix Prompt) Basisdaten Entwickler Ken Thompso …   Deutsch Wikipedia

  • Unix — (registrado oficialmente como UNIX®) es un sistema operativo portable, multitarea y multiusuario; desarrollado, en principio, en 1969 por un grupo de empleados de los laboratorios Bell de AT T, entre los que figuran Ken Thompson, Dennis Ritchie y …   Wikipedia Español

  • UNIX — UNIX, parfois écrit « Unix », avec des petites capitales, est un système d exploitation multitâche et multi utilisateur créé en 1969, conceptuellement ouvert et fondé sur une approche par laquelle il offre de nombreux petits outils… …   Wikipédia en Français

  • Unix — (marque déposée officiellement comme UNIX, parfois aussi écrit comme Unix avec les petites capitalisations) est le nom d un système d exploitation multitâche et multi utilisateur créé en 1969, conceptuellement ouvert et fondé sur une approche par …   Wikipédia en Français

  • Unix time — Unix time, or POSIX time, is a system for describing points in time, defined as the number of seconds elapsed since midnight Coordinated Universal Time (UTC) of January 1 1970, not counting leap seconds. It is widely used not only on Unix like… …   Wikipedia

  • Unix-подобная операционная система — Генеалогическое дерево UNIX подобных ОС UNIX подобная операционная система (иногда сокр. *nix)  система, которая образовалась под влиянием UNIX. Термин включает свободные/открытые операционные системы, образованные от UNIX компании …   Википедия

  • UNIX — 〈[ju:nıx] EDV〉 Betriebssystem für Computer, das zum großen Teil in der Programmiersprache C geschrieben ist [engl.] * * * UNIX   [ursprünglich UNICS, Abk. für Uniplexed Information and Computing System, dt. »nicht multiplextes (vielseitiges)… …   Universal-Lexikon

  • UNIX-Kommandos — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

  • Unix-Befehle — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”