Linux 常用命令3-- 目录操作rmdir 和 rm

时间:2022-05-10 17:45:56

rmdir 删除文件或目录 全称: Remove Directory
使用方式 : rmdir [-p] 目录名称
参数:
-p:递归的删除目录(目录必须为空)

[root@localhost mail]# rmdir --help
Usage: rmdir [OPTION]... DIRECTORY...
Remove the DIRECTORY(ies), if they are empty.

--ignore-fail-on-non-empty
ignore each failure that is solely because a directory
is non-empty
-p, --parents remove DIRECTORY and its ancestors; e.g., `rmdir -p a/b/c' is
similar to `rmdir a/b/c a/b a'

-v, --verbose output a diagnostic for every directory processed
--help display this help and exit
--version output version information and exit

rm 删除文件或目录 全称: Remove
使用方式 : rm [-pr] 目录名称
参数:
-f:忽略不存在的文件,不出先警告信息
-i:互动模式,在删除前询问是否操作
-r:递归删除,常用在目录删除,相当危险

[root@localhost mail]# rm --help
Usage: rm [OPTION]... FILE...
Remove (unlink) the FILE(s).

-f, --force ignore nonexistent files, never prompt
-i prompt before every removal
-I prompt once before removing more than three files, or
when removing recursively. Less intrusive than -i,
while still giving protection against most mistakes
--interactive[=WHEN] prompt according to WHEN: never, once (-I), or
always (-i). Without WHEN, prompt always
--one-file-system when removing a hierarchy recursively, skip any
directory that is on a file system different from
that of the corresponding command line argument
--no-preserve-root do not treat `/' specially
--preserve-root do not remove `/' (default)
-r, -R, --recursive remove directories and their contents recursively
-v, --verbose explain what is being done
--help display this help and exit
--version output version information and exit

By default, rm does not remove directories. Use the --recursive (-r or -R)
option to remove each listed directory, too, along with all of its contents.

To remove a file whose name starts with a `-', for example `-foo',
use one of these commands:
rm -- -foo

rm ./-foo

Note that if you use rm to remove a file, it is usually possible to recover
the contents of that file. If you want more assurance that the contents are
truly unrecoverable, consider using shred.