五、删除文件
删除普通文件用rm命令,删除目录用rmdir命令,但是rmdir只能删除空目录,说很少使用,常使用rm,我们先man一下rm命令:
NAME
rm - remove files or directories
SYNOPSIS
rm [OPTION]... FILE...
DESCRIPTION
This manual page documents the GNU version of rm.
rm removes each specified file.
By default, it does not remove directories.
If the -I or --interactive=once option is given,
and there are more than three files
or the -r, -R, or --recursive are given, then rm prompts
the user for whether to pro-
ceed with the entire operation. If the response is not
affirmative, the entire com-
mand is aborted.
Otherwise, if a file is unwritable, standard input is
a terminal, and the -f or
--force option is not given, or the -i or --
interactive=always option is given, rm
prompts the user for whether to remove the file. If the
response is not affirmative,
the file is skipped.
这个命令操作比较简单
rm 选项 要删除的文件
这里要删除的文件可以是单个文件,也可以是多个文件。
重点说说选项
删除一个普通文件无需任何参数即可
rm file
如果要删除的是目录,则会提醒你这是一个目录,然后不删除,这是需要加一个参数-r或者-R,
rm -r dirname
有时候会提示你是否删除,如果你不想看提示而直接删除则加一个参数-f(force)
rm -rf dirname