如何在RHEL(Red Hat)Linux上删除和删除文件
时间:2020-01-09 10:38:06 来源:igfitidea点击:
如何在基于RHEL(Red Hat)Linux的系统上删除和删除文件?
您需要使用rm命令。
它尝试删除命令行上指定的文件。
使用rm命令删除RHEL(Red Hat)Linux上的文件和目录。
在本教程中我们学习了如何在RHEL(Red Hat)Linux上删除和删除文件。
在RHEL(Red Hat)Linux上删除和删除文件的命令
rm和unlink命令在RHEL(Red Hat)Linux上删除文件的语法如下:
- 打开RHEL(Red Hat)终端应用程序(bash shell)
- 执行以下任一命令以删除当前目录中的名为rhel7.demo.txt的文件
- rm rhel7.demo.txt或取消链接rhel7.demo.txt
让我们使用see all rm命令选项来删除和删除RHEL(Red Hat)Linux上的文件。
删除多个文件
执行以下命令以删除位于当前目录中的名为tom.txt,tom.txt和dance.jpg的文件:
[Hyman@theitroad-rhel:~]$ rm tom.txt tom.txt dance.jpg
您也可以指定路径。
如果位于/tmp /目录中的名为tom.txt的文件,则可以运行:
[Hyman@theitroad-rhel:~]$ rm /tmp/tom.txt [Hyman@theitroad-rhel:~]$ rm /tmp/tom.txt /home/Hyman/dance.jpg /home/Hyman/data/tom.txt
RHEL(Red Hat)Linux删除文件并在每次删除前提示
要在尝试删除每个文件之前获得确认,请将-i选项传递给RHEL(Red Hat)Linux上的rm命令:
[Hyman@theitroad-rhel:~]$ rm -i my-file-name-here [Hyman@theitroad-rhel:~]$ rm -i tom.txt
在RHEL(Red Hat)Linux上强制执行rm命令以说明文件正在执行的操作
如下传递-v选项,以在RHEL(Red Hat)Linux机器上获得详细的输出:
[Hyman@theitroad-rhel:~]$ rm -v my-file-name-here [Hyman@theitroad-rhel:~]$ rm -v cake-day.jpg
红帽企业Linux删除文件夹或目录中的所有文件
您需要传递以下选项:
[Hyman@theitroad-rhel:~]$ rm -rf dir1 [Hyman@theitroad-rhel:~]$ rm -rf /path/to/dir/ [Hyman@theitroad-rhel:~]$ rm -rf /home/Hyman/oldschoolpics/
它将从目录中删除所有文件和子目录。
所以要小心始终在RHEL(Red Hat)Linux上保留所有重要数据的备份。
RHEL(Red Hat)Linux删除文件以连字符或连字符开头
如果文件或目录或文件夹的名称以短划线开头("-"或连字符"-"),请使用以下语法:
[Hyman@theitroad-rhel:~]$ rm -- -my-file-name-here [Hyman@theitroad-rhel:~]$ rm -- --my-file-name-here [Hyman@theitroad-rhel:~]$ rm -rf --my-directory-name-here [Hyman@theitroad-rhel:~]$ rm ./-file [Hyman@theitroad-rhel:~]$ rm -rf ./--my-directory-name-here
不要以管理员/root或普通RHEL(Red Hat)Linux用户身份运行rm -rf /命令
rm -rf(或rm -rf /,rm -rf *等)经常用于有关RHEL(Red Hat)Linux灾难的笑话和轶事中。
如果命令的rm -rf /变体由管理员运行,将导致删除计算机上每个可写挂载文件系统的内容。
`不要在RHEL(Red Hat)Linux上尝试以下命令:
[Hyman@theitroad-rhel:~]$ rm -rf / [Hyman@theitroad-rhel:~]$ rm -rf *
rm命令手册
有关更多信息,请执行以下man命令,以查看RHEL(Red Hat)上的rm命令手册页:
$ man rm
或者
rm --help
输出示例:
Usage: rm [OPTION]... FILE...
Remove (unlink) the FILE(s).
-f, --force ignore nonexistent files and arguments, 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
-d, --dir remove empty directories
-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 might be possible to recover
some of its contents, given sufficient expertise and/or time. For greater
assurance that the contents are truly unrecoverable, consider using shred.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'rm invocation'

