Rmdir

Last updated
rmdir / rd
Original author(s) Ken Thompson, Dennis Ritchie
(AT&T Bell Laboratories)
Developer(s) Various open-source and commercial developers
Operating system Unix, Unix-like, DOS, MSX-DOS, FlexOS, OS/2, Windows, ReactOS, KolibriOS
Platform Cross-platform
Type Command

In computing, rmdir (or rd) is a command which will remove an empty directory on various operating systems.

Contents

Implementations

The command is available in Unix (e.g. macOS, Solaris, AIX, HP-UX), Unix-like (e.g. FreeBSD, Linux), DOS, Digital Research FlexOS, [1] IBM OS/2, [2] Microsoft Windows [3] or ReactOS [4] operating systems. On MS-DOS, the command is available in versions 2 and later. [5] DR DOS 6.0 also includes an implementation of the rmdir command. [6]

It is also available in the open source MS-DOS emulator DOSBox and in KolibriOS. [7] The numerical computing environments MATLAB and GNU Octave include an rmdir function with similar functionality. [8] [9]

Usage

Unix, Unix-like

Normal usage is straightforward:

$ rmdirname_of_directory 

where name_of_directory corresponds with the name of the directory one wishes to delete. There are options to this command such as -p in Unix which removes parent directories if they are also empty.

For example:

$ rmdir-pfoo/bar/baz 

will first remove baz/, then bar/ and finally foo/ thus removing the entire directory tree specified in the command argument.

rmdir will not remove a directory if it is not empty in UNIX. The rm command will remove a directory and all its contents recursively. For example:

$ rm-rfoo/bar/baz $ rm-rffoo/bar/baz 

DOS, OS/2, Windows, ReactOS

The ReactOS rmdir command ReactOS-0.4.13 rmdir command 667x434.png
The ReactOS rmdir command

Normal usage is identical to Unix-like operating systems:

>rmdir name_of_directory 

The equivalent command in MS-DOS and earlier (non-NT-based) versions of Microsoft Windows for deleting non-empty directories is deltree.

In later version of Windows:

>rd /s directory_name 

Windows based on the NT kernel (XP, Vista, 7, 8, Server 2003/2008) are case insensitive, just like their earlier predecessors, unless two files of the same name and different case exist. Then case sensitivity applies when selecting which file to use, or if the case does not match either file, one may be chosen by Windows.

Having two files named the same with different case sensitivity is allowed either when Windows Services for Unix is installed or when the Windows Registry settings are set to allow it.

An example of the security risk is:

Using rd/rmdir and two directories with the same name and different case sensitivities exist, one of which contains valid data and/or programs, and the other contains incriminating materials and/or malware. If rd/rmdir gets executed without regard to case sensitivity and Windows chooses the legitimate folder to delete, the only folder left is the undesired one. Windows then uses this folder instead of the previously legitimate one to execute programs, and one may be led to believe it contains legitimate data.

See also

Related Research Articles

cd (command) Computer command in various operating systems

The cd command, also known as chdir, is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.

dir (command) Directory information command on various operating systems

In computing, dir (directory) is a command in various computer operating systems used for computer file and directory listing. It is one of the basic commands to help navigate the file system. The command is usually implemented as an internal command in the command-line interpreter (shell). On some systems, a more graphical representation of the directory structure can be displayed using the tree command.

mkdir Directory creation command on various operating systems

The mkdir command in the Unix, DOS, DR FlexOS, IBM OS/2, Microsoft Windows, and ReactOS operating systems is used to make a new directory. It is also available in the EFI shell and in the PHP scripting language. In DOS, OS/2, Windows and ReactOS, the command is often abbreviated to md.

pwd Directory information command on various operating systems

In Unix-like and some other operating systems, the pwd command writes the full pathname of the current working directory to the standard output.

at (command) Task scheduling command on various operating systems

In computing, at is a command in Unix-like operating systems, Microsoft Windows, and ReactOS used to schedule commands to be executed once, at a particular time in the future.

In computing, touch is a command used to update the access date and/or modification date of a computer file or directory. It is included in Unix and Unix-like operating systems, TSC's FLEX, Digital Research/Novell DR DOS, the AROS shell, the Microware OS-9 shell, and ReactOS. The command is also available for FreeDOS and Microsoft Windows.

In computing, echo is a command that outputs the strings that are passed to it as arguments. It is a command available in various operating system shells and typically used in shell scripts and batch files to output status text to the screen or a computer file, or as a source part of a pipeline.

cmd.exe Command prompt program

Command Prompt, also known as cmd.exe or cmd, is the default command-line interpreter for the OS/2, eComStation, ArcaOS, Microsoft Windows, and ReactOS operating systems. On Windows CE .NET 4.2, Windows CE 5.0 and Windows Embedded CE 6.0 it is referred to as the Command Processor Shell. Its implementations differ between operating systems, but the behavior and basic set of commands are consistent. cmd.exe is the counterpart of COMMAND.COM in DOS and Windows 9x systems, and analogous to the Unix shells used on Unix-like systems. The initial version of cmd.exe for Windows NT was developed by Therese Stowell. Windows CE 2.11 was the first embedded Windows release to support a console and a Windows CE version of cmd.exe. The ReactOS implementation of cmd.exe is derived from FreeCOM, the FreeDOS command line interpreter.

rm (Unix) Unix command utility

rm is a basic command on Unix and Unix-like operating systems used to remove objects such as computer files, directories and symbolic links from file systems and also special files such as device nodes, pipes and sockets, similar to the del command in MS-DOS, OS/2, and Microsoft Windows. The command is also available in the EFI shell.

exit (command) Command of many operating system command line interpreters and scripting languages

In computing, exit is a command used in many operating system command-line shells and scripting languages.

more (command) Terminal pager available on various operating systems

In computing, more is a command to view the contents of a text file one screen at a time. It is available on Unix and Unix-like systems, DOS, Digital Research FlexOS, IBM/Toshiba 4690 OS, IBM OS/2, Microsoft Windows and ReactOS. Programs of this sort are called pagers. more is a very basic pager, originally allowing only forward navigation through a file, though newer implementations do allow for limited backward movement.

In computing, SUBST is a command on the DOS, IBM OS/2, Microsoft Windows and ReactOS operating systems used for substituting paths on physical and logical drives as virtual drives.

The NTFS file system defines various ways to redirect files and folders, e.g., to make a file point to another file or its contents without making a copy of it. The object being pointed to is called the target. Such file is called a hard or symbolic link depending on a way it's stored on the filesystem.

In computing, DELTREE is a command line command in some Microsoft operating systems, SpartaDOS X and FreeDOS that recursively deletes an entire subdirectory of files.

A batch file is a script file in DOS, OS/2 and Microsoft Windows. It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. A batch file may contain any command the interpreter accepts interactively and use constructs that enable conditional branching and looping within the batch file, such as IF, FOR, and GOTO labels. The term "batch" is from batch processing, meaning "non-interactive execution", though a batch file might not process a batch of multiple data.

del (command) Command in various operating systems

In computing, del is a command in command-line interpreters (shells) such as COMMAND.COM, cmd.exe, 4DOS, NDOS, 4OS2, 4NT and Windows PowerShell. It is used to delete one or more files or directories from a file system.

In computing, label is a command included with some operating systems. It is used to create, change, or delete a volume label on a logical drive, such as a hard disk partition or a floppy disk. Used without parameters, label changes the current volume label or deletes the existing label.

help (command) Command in various command line shells

In computing, help is a command in various command line shells such as COMMAND.COM, cmd.exe, Bash, qshell, 4DOS/4NT, Windows PowerShell, Singularity shell, Python, MATLAB and GNU Octave. It provides online information about available commands and the shell environment.

replace (command)

In computing, replace is a command that is used to replace one or more existing computer files or add new files to a target directory. Files with a hidden or system attribute set cannot be replaced using replace. The command lists all files that are replaced.

References

  1. "Manual" (PDF). www.bitsavers.org. 1986. Archived from the original (PDF) on 2010-08-08. Retrieved 2020-09-12.
  2. "Help page". www.jatomes.com. Retrieved 2020-09-12.
  3. "Microsoft TechNet Rmdir article". 31 August 2016.
  4. "reactos/reactos". GitHub. 3 January 2022.
  5. Wolverton, Van (2003). Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition. Microsoft Press. ISBN   0-7356-1812-7.
  6. DR DOS 6.0 User Guide Optimisation and Configuration Tips
  7. "Shell - KolibriOS wiki". wiki.kolibrios.org.
  8. "Remove folder - MATLAB rmdir". www.mathworks.com.
  9. "Function Reference: rmdir". octave.sourceforge.io.

Further reading