<span class="z textcut" style="text-align: left; color: rgb(153, 153, 153); text-transform: none; text-indent: 0px; letter-spacing: normal; overflow: hidden; font-family: &quot;Lantinghei SC&quot;, &quot;Helvetica Neue&quot;, &quot;Microsoft YaHei&quot;, 微软雅黑, Arial, STHeiti, &quot;WenQuanYi Micro Hei&quot;, SimSun, sans-serif; font-size: 12px; font-style: normal; font-weight: normal; word-spacing: 0px; float: left; white-space: nowrap; -ms-word-wrap: break-word; -ms-text-overflow: ellipsis; max-width: 60%; orphans: 2; widows: 2; user-select: text; font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">编译自:[https://www.tecmint.com/delete-huge-files-in-linux/](https://www.tecmint.com/delete-huge-files-in-linux/)</span><span class="y" style="text-align: left; color: rgb(153, 153, 153); text-transform: none; text-indent: 0px; letter-spacing: normal; padding-left: 5px; font-family: &quot;Lantinghei SC&quot;, &quot;Helvetica Neue&quot;, &quot;Microsoft YaHei&quot;, 微软雅黑, Arial, STHeiti, &quot;WenQuanYi Micro Hei&quot;, SimSun, sans-serif; font-size: 12px; font-style: normal; font-weight: normal; word-spacing: 0px; float: right; white-space: normal; -ms-word-wrap: break-word; orphans: 2; widows: 2; user-select: text; font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">作者: Aaron Kili</span>

<span class="z" style="text-align: left; color: rgb(153, 153, 153); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: &quot;Lantinghei SC&quot;, &quot;Helvetica Neue&quot;, &quot;Microsoft YaHei&quot;, 微软雅黑, Arial, STHeiti, &quot;WenQuanYi Micro Hei&quot;, SimSun, sans-serif; font-size: 12px; font-style: normal; font-weight: normal; word-spacing: 0px; float: left; white-space: normal; -ms-word-wrap: break-word; orphans: 2; widows: 2; user-select: text; font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">原创:[LCTT](https://linux.cn/lctt/) [https://linux.cn/article-8537-1.html](https://linux.cn/article-8537-1.html)</span><span class="y" style="text-align: left; color: rgb(153, 153, 153); text-transform: none; text-indent: 0px; letter-spacing: normal; padding-left: 5px; font-family: &quot;Lantinghei SC&quot;, &quot;Helvetica Neue&quot;, &quot;Microsoft YaHei&quot;, 微软雅黑, Arial, STHeiti, &quot;WenQuanYi Micro Hei&quot;, SimSun, sans-serif; font-size: 12px; font-style: normal; font-weight: normal; word-spacing: 0px; float: right; white-space: normal; -ms-word-wrap: break-word; orphans: 2; widows: 2; user-select: text; font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">译者: [geekpi](https://linux.cn/lctt/geekpi)</span>

通常,要[在 Linux 终端删除一个文件](https://linux.cn/article-8123-1.html),我们使用 rm 命令(删除文件)、shred 命令(安全删除文件)、wipe 命令(安全擦除文件)或者 secure-deletion 工具包(一个安全文件删除工具集合)。

我们可以使用上述任意的工具来处理相对较小的文件。如果我们想要删除超大的文件/文件夹,比如大概 100-200GB,在删除文件(I/O 调度)所花费的时间以及 RAM 占用量方面,就没有你想的那么简单。

在本教程中,我们会解释如何在 Linux 中有效率并可靠地删除大文件/文件夹。

**建议阅读:** [5 个在 Linux 中清空或者删除大文件的方法](https://linux.cn/article-8024-1.html)

我们的主要目标是使用一种不会在删除大文件时拖慢系统的技术,合理地占用 I/O。我们可以用 ionice 命令实现这个目标。

###
在 Linux 中使用 ionice 命令删除超大(200GB)文件

ionice 是一个可以对另一个程序设置或获取 I/O 调度级别和优先级的有用程序。如果没有给出参数或者只有 `-p` 参数,那么 ionice 将会查询该进程的当前的 I/O 调度级别以及优先级。

如果我们给出命令名称,如 `rm` 命令,它将使用给定的参数运行此命令。要获取或设置调度参数,请指定[进程的 PID],如下:
  1. <span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word; user-select: text;">#</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> ionice </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">p PID</span>

    要指定名字或者调度的数字,使用(0 表示无、1 表示实时、2 表示尽力、3 表示空闲)下面的命令。

    以下命令表示 rm 会属于空闲 I/O 级别,并且只在其他进程不使用的时候使用 I/O:

  2. <span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">----</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="typ" style="color: rgb(137, 189, 255); -ms-word-wrap: break-word; user-select: text;">Deleting</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="typ" style="color: rgb(137, 189, 255); -ms-word-wrap: break-word; user-select: text;">Huge</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="typ" style="color: rgb(137, 189, 255); -ms-word-wrap: break-word; user-select: text;">Files</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word; user-select: text;">in</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="typ" style="color: rgb(137, 189, 255); -ms-word-wrap: break-word; user-select: text;">Linux</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">-----</span>

  3. <span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word; user-select: text;">#</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> ionice </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">c </span><span class="lit" style="color: rgb(51, 135, 204); -ms-word-wrap: break-word; user-select: text;">3</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word; user-select: text;">rm</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">/</span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word; user-select: text;">var</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">logs</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">syslog</span>
  4. <span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word; user-select: text;">#</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> ionice </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">c </span><span class="lit" style="color: rgb(51, 135, 204); -ms-word-wrap: break-word; user-select: text;">3</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word; user-select: text;">rm</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">rf </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">/</span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word; user-select: text;">var</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">log</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">apache</span>

    如果系统中没有很多空闲时间,那么我们希望使用尽力调度级别,并且使用低优先级:

  5. <span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word; user-select: text;">#</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> ionice </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">c </span><span class="lit" style="color: rgb(51, 135, 204); -ms-word-wrap: break-word; user-select: text;">2</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">n </span><span class="lit" style="color: rgb(51, 135, 204); -ms-word-wrap: break-word; user-select: text;">6</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word; user-select: text;">rm</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">/</span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word; user-select: text;">var</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">logs</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">syslog</span>

  6. <span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word; user-select: text;">#</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> ionice </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">c </span><span class="lit" style="color: rgb(51, 135, 204); -ms-word-wrap: break-word; user-select: text;">2</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">n </span><span class="lit" style="color: rgb(51, 135, 204); -ms-word-wrap: break-word; user-select: text;">6</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word; user-select: text;">rm</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">rf </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">/</span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word; user-select: text;">var</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">log</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;">apache</span>

    注意:要使用安全的方法删除大文件,我们可以使用先前提到的 shredwipe 以及 secure-deletion 工具包中的不同工具,而不是 rm 命令。

    建议阅读:3 个在 Linux 中永久/安全删除文件/文件夹的方法

    要获取更多信息,查阅 ionice 的手册页:

  7. <span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word; user-select: text;">#</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word; user-select: text;">man</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word; user-select: text;"> ionice </span>

    就是这样了!你脑海里还有其他的方法么?在评论栏中与我们分享。