如何在 Linux 中删除超大的（100-200GB）文件
删除
![](/data/attachment/album/201705/24/064946fqc1vu7oxi1bixos.jpg)


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


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


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


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


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


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


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


如果我们给出命令名称，如 `rm` 命令，它将使用给定的参数运行此命令。要获取或设置调度参数，请指定[进程的 PID]，如下：



```
# ionice -p PID

```

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


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



```
---- Deleting Huge Files in Linux -----
# ionice -c 3 rm /var/logs/syslog
# ionice -c 3 rm -rf /var/log/apache

```

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



```
# ionice -c 2 -n 6 rm /var/logs/syslog
# ionice -c 2 -n 6 rm -rf /var/log/apache

```

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


**建议阅读：**[3 个在 Linux 中永久/安全删除文件/文件夹的方法](/article-8123-1.html)


要获取更多信息，查阅 `ionice` 的手册页：



```
# man ionice 

```

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




---


作者简介：


Aaron Kili 是 Linux 和 F.O.S.S 爱好者，将来的 Linux 系统管理员和网络开发人员，目前是 TecMint 的内容创作者，他喜欢用电脑工作，并坚信分享知识。




---


via: <https://www.tecmint.com/delete-huge-files-in-linux/>


作者：[Aaron Kili](https://www.tecmint.com/author/aaronkili/) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
In the realm of Linux terminal operations, a range of [Linux commands](https://www.tecmint.com/most-used-linux-commands/) are at our disposal for the purpose of effectively deleting or removing files.

When it comes to the task of file elimination, we commonly rely on the [“rm” command](https://www.tecmint.com/remove-directory-linux/), which swiftly erases files from the system. For enhanced security and assurance, the “**shred**” command comes into play, ensuring the thorough and secure deletion of a file, leaving no trace behind.

Furthermore, the “**wipe**” command offers an added layer of protection, securely erasing files beyond any possibility of recovery. In more complex scenarios or for advanced file deletion needs, we can turn to the [secure deletion tools](https://www.tecmint.com/permanently-and-securely-delete-files-directories-linux/) designed to meet the highest standards of secure file deletion.

With these powerful options at our disposal, we can confidently and effectively remove files from the Linux terminal environment.

We can use any of the above utilities to deal with relatively small files. What if we want to delete/remove a huge file/directory say about **100-200GB**?

This may not be as easy as it seems, in terms of the time taken to remove the file (I/O scheduling) as well as the amount of RAM consumed while carrying out the operation.

In this tutorial, we will explain how to efficiently and reliably [delete huge files/directories](https://www.tecmint.com/delete-large-directory-linux/) in Linux.

The main aim here is to use a technique that will not slow down the system while removing a huge file, resulting to reasonable I/O. We can achieve this using the **ionice command**.

### Deleting HUGE (200GB) Files in Linux Using ionice Command

**ionice** is a useful program that sets or gets the I/O scheduling class and priority for another program. If no arguments or just `-p`

is given, ionice will query the current I/O scheduling class and priority for that process.

If we give a command name such as **rm command**, it will run this command with the given arguments. To specify the [process IDs of running processes](https://www.tecmint.com/find-linux-processes-memory-ram-cpu-usage/) for which to get or set the scheduling parameters, run this:

# ionice -p PID

To specify the name or number of the scheduling class to use (**0** for none, **1** for real-time, **2** for best-effort, **3** for idle) the command below.

This means that **rm** will belong to the idle I/O class and only uses I/O when any other process does not need it:

---- Deleting Huge Files in Linux -----# ionice -c 3 rm /var/logs/syslog # ionice -c 3 rm -rf /var/log/apache

If there won’t be much idle time on the system, then we may want to use the best-effort scheduling class and set a low priority like this:

# ionice -c 2 -n 6 rm /var/logs/syslog # ionice -c 2 -n 6 rm -rf /var/log/apache

**Note**: To delete huge files using a secure method, we may use the **shred**, **wipe** and various tools in the secure-deletion toolkit mentioned earlier on, instead of the [rm command](https://www.tecmint.com/linux-rm-command-examples/).

For more info, look through the ionice man page:

# man ionice

That’s it for now! What other methods do you have in mind for the above purpose? Use the comment section below to share with us.

This only work do you are using cfq as io scheduler

Reply@Emmanuel

We’ll check this out. Thanks for the feedback.

ReplyWhy not simply use “

Replynice” and set a low priority? Would that be sufficiently efficient? Linux will know how to handle the priorities so when the cpu is not running high, it will give more cpu time to the rm command. I don’t see any significant difference.@Lethargos

A reasonable way to accomplish the job, we’ll surely test this out. Many thanks for writing back.

Replyecho ” ” > huge_file && rm huge_file

Reply@User

Okay, don’t you think without using

Replyionice, this command will cause high I/O loads and gradually slow down the system? Thanks for sharing this.No – command like:

> huge-file

No take many I/O

This is short way to make zero size file in bash

Reply@Out

Okay, thanks for the useful tip.

Reply