Jump to content

Rmdir

From Alfawiki
rmdir
Company typeCommand
IndustryComputing / Operating systems
ProductsDirectory removal command

In the realm of computing, the rmdir command, also known as rd, serves the purpose of deleting an empty directory on a variety of operating system platforms.

Implementations

This command is available on Unix operating systems such as macOS, Solaris, AIX, and HP-UX, along with Unix-like environments including FreeBSD and Linux. It is also supported on systems like DOS, Digital Research’s FlexOS, IBM’s OS/2, Microsoft Windows, and ReactOS. Starting with MS-DOS version 2, the command has been included, and an implementation is present in DR DOS 6.0 as well.

Furthermore, the open-source MS-DOS emulator DOSBox and the minimalist operating system KolibriOS incorporate this command. Numerical computation platforms such as MATLAB and GNU Octave provide an rmdir function offering equivalent capabilities.

Unix and Unix-like systems

The fundamental syntax is:

<syntaxhighlight lang="shell-session"> $ rmdir directory_name </syntaxhighlight>

Here, directory_name specifies the directory intended for removal. Utilizing the -p flag in Unix allows for deletion of parent directories if they are empty:

<syntaxhighlight lang="shell-session"> $ rmdir -p foo/bar/baz </syntaxhighlight>

This command sequentially removes baz/, then bar/, followed by foo/, effectively deleting the entire specified directory hierarchy.

On UNIX systems, rmdir refuses to remove directories that contain files; instead, recursive deletion is performed using the <syntaxhighlight lang="text" class="" style="" inline="1">rm</syntaxhighlight> command with appropriate options:

<syntaxhighlight lang="shell-session"> $ rm -r foo/bar/baz $ rm -rf foo/bar/baz </syntaxhighlight>

DOS, OS/2, Windows, and ReactOS

The command usage resembles that of Unix-like systems:

<syntaxhighlight lang="DOScon"> >rmdir directory_name </syntaxhighlight>

In earlier versions of MS-DOS and Windows, removing directories with content was accomplished via the <syntaxhighlight lang="text" class="" style="" inline="1">deltree</syntaxhighlight> command. In more recent Windows editions, the following syntax is employed:

<syntaxhighlight lang="doscon"> >rd /s directory_name </syntaxhighlight>

Windows NT-based operating systems (from XP through Server 2008) generally treat filenames case-insensitively but can support case sensitivity when two files or folders differ solely by letter casing—this feature can be enabled through Windows Services for UNIX or specific registry configurations.

A potential security concern arises when two directories exist with names differing only in case: executing rd/rmdir might remove the legitimate folder while leaving a malicious one intact. This scenario could undermine system security by allowing execution of unauthorized programs.

See also

Further reading

External links