rmdir
rmdir deliberately only removes empty directories — that's a safety net.
For a non-empty one you need rm -r (irreversible, double-check the path).
Creating directories: -p (with parents), -m (permissions right away), brace expansion, rmdir.
mkdir -p a/b/c
a chain of directories
mkdir -p site/{css,js,img}
several at once
mkdir -m 700 ~/.secrets
with permissions right away
rmdir empty
remove an empty one
mkdir (make directory) creates directories. An empty directory is removed
with rmdir, a non-empty one with rm -r (careful, see files-basics).
The key option for beginners is -p: it creates the whole chain of
parent directories and doesn't complain if the directory already exists.
Main options:
| Option | What it does |
|---|---|
-p, --parents |
create parent directories along the path; not an error if it already exists |
-m, --mode=MODE |
set permissions right at creation time (instead of umask) |
-v, --verbose |
print the name of every directory created |
| Option | What it does | Example |
|---|---|---|
-p --parents |
Create the full chain of parent directories; not an error if it already exists. | mkdir -p proj/src/api |
-m --mode ПРАВА |
Set the mode of the created directory immediately, bypassing umask. | mkdir -m 700 ~/.secrets |
-v --verbose |
Print the name of each created directory. | mkdir -v new |
Nothing found. Try a shorter query.
rmdir deliberately only removes empty directories — that's a safety net.
For a non-empty one you need rm -r (irreversible, double-check the path).
mkdir: cannot create directory 'x': File existsThe directory already exists. In scripts, use mkdir -p — it skips
silently.
mkdir: cannot create directory 'a/b/c': No such file or directoryThe intermediate directories (a, a/b) don't exist. Add -p.
Permission deniedNo w+x permission on the parent directory. Check ls -ld . and the
permissions — see chmod-chown.
-m specified-m sets the resulting directory's permissions directly (umask doesn't
apply to it), but the intermediate directories created by -p still get the
regular umask.
Found an inaccuracy? Report an error in the article