【Linux命令】每天一个Linux命令(7):rm命令

admin 2023年6月3日19:12:43评论13 views字数 2095阅读6分59秒阅读模式

每天一个Linux命令(7):rm命令

命令:
rm
描述:rm(remove)用于删除文件或目录。
语法:
rm [选项] 文件
常用选项:
  • -i:在删除文件之前进行交互式确认。
  • -r:递归地删除目录及其内容。
  • -f:强制删除,无需进行确认。
示例:

1.

删除文件:
rm file.txt
这将删除名为 file.txt 的文件。

【Linux命令】每天一个Linux命令(7):rm命令

2.
删除目录:
rm -r directory/
这将递归地删除名为 directory/ 的目录及其所有内容。

【Linux命令】每天一个Linux命令(7):rm命令

3.

删除多个文件:
rm file1.txt file2.txt
这将同时删除 file1.txt 和 file2.txt 文件。

【Linux命令】每天一个Linux命令(7):rm命令

4.

在删除文件之前进行交互式确认:
rm -i file.txt
这将在删除 file.txt 文件之前进行交互式确认。

【Linux命令】每天一个Linux命令(7):rm命令

5.

强制删除,无需进行确认:
rm -rf directory/
这将强制递归地删除名为 directory/ 的目录及其所有内容,无需进行确认。

【Linux命令】每天一个Linux命令(7):rm命令

说明:

rm 命令是一个用于删除文件或目录的强大工具。请谨慎使用,因为删除操作不可恢复。使用 rm 命令时,请确保提供正确的文件路径,并确认您真正想要删除这些文件或目录。使用 -r 选项时,将递归地删除目录及其内容。使用 -i 选项时,将在删除之前进行交互式确认,以避免意外删除。使用 -f 选项时,将强制删除文件或目录,无需进行确认。请注意,删除操作是永久性的,被删除的文件无法恢复,因此在使用 rm 命令时要谨慎操作。

[root@iZb5dlyg1ebe6oZ ~]# rm --helpUsage: 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[=all] do not remove '/' (default); with 'all', reject any command line argument on a separate device from its parent -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 recoversome of its contents, given sufficient expertise and/or time. For greaterassurance that the contents are truly unrecoverable, consider using shred.
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>Full documentation <https://www.gnu.org/software/coreutils/rm>or available locally via: info '(coreutils) rm invocation'

【Linux命令】每天一个Linux命令(7):rm命令

原文始发于微信公众号(利刃信安攻防实验室):【Linux命令】每天一个Linux命令(7):rm命令

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年6月3日19:12:43
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【Linux命令】每天一个Linux命令(7):rm命令http://cn-sec.com/archives/1782283.html

发表评论

匿名网友 填写信息