如何在 Linux CentOS 系统上清除主系统驱动器上的空间?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11316664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 07:13:42  来源:igfitidea点击:

How do I clear space on my main system drive on a Linux CentOS system?

linuxcentos

提问by T. Brian Jones

Sorry if this sounds dumb, but I'm not sure what to do.

对不起,如果这听起来很愚蠢,但我不知道该怎么做。

I've got an Amazon EC2 instance with a completely full Ephemeral drive ( the main drive with all the system files ). Almost all the directories where I've installed things like Apache, MySQL, Sphinx, my applications, etc. are on a separate physical drive and have symlinks from the ephemeral drive. As far as I am aware, none of thier data or logs write to the ephemeral drive, so I'm not sure what happened to the space.

我有一个 Amazon EC2 实例,它有一个完整的 Ephemeral 驱动器(包含所有系统文件的主驱动器)。我安装了 Apache、MySQL、Sphinx、我的应用程序等的几乎所有目录都在一个单独的物理驱动器上,并且具有来自临时驱动器的符号链接。据我所知,他们的数据或日志都没有写入临时驱动器,所以我不确定空间发生了什么。

Obviously lots of system stuff is still on the ephemeral drive, but I'm not sure how to clear things off to make space. My best guess is that amazon filled the drive when it did some auto updates to the system. I'm trying to install some new packages, and update all my system packages via YUM, but the drive has no space.

显然,许多系统内容仍在临时驱动器上,但我不确定如何清除这些内容以腾出空间。我最好的猜测是亚马逊在对系统进行一些自动更新时填满了驱动器。我正在尝试安装一些新软件包,并通过 YUM 更新我所有的系统软件包,但驱动器没有空间。

What should I do?

我该怎么办?

采纳答案by T. Brian Jones

This works great. Can take a few minutes on bigger drives ( over a few hundred GB ):

这很好用。在更大的驱动器(超过几百 GB)上可能需要几分钟:

find /directory/to/scan/ -type f -exec du -a {} + | sort -n -r | less

The output will be the biggest files first. You can page through the results with normal "less" commands ... space bar ( next page ) and b ( previous page ).

输出将首先是最大的文件。您可以使用普通的“less”命令翻阅结果……空格键(下一页)和 b(上一页)。

回答by Conner

You can use the unix disk utility command duto see what's taking up all the space for starters.

您可以使用 unix disk 实用程序命令du查看什么占用了初学者的所有空间。

回答by Harald Brinkhof

du --max-depth=1 -h /

where /can be any directory starting from root will show you the size in human readable form (-h) without further recursing further down.

其中/可以从根开始将告诉你在人类可读的形式(-H)不经进一步递归进一步向下尺寸的任何目录。

Once you find something big that you want to remove you can do it via

一旦你发现你想要删除的大东西,你可以通过

rm <thing you want to remove>

this accepts shell expansion, so for instance to remove all mp3 files:

这接受 shell 扩展,例如删除所有 mp3 文件:

rm *.mp3      

if it's a directory then you need to add -r

如果它是一个目录,那么你需要添加 -r

rm -r /dir/to/remove

to protect yourself it would be advisable to add the -iswitch to every rmcall, this forces you to acknowledge that you want the files removed.

为了保护自己,建议将-i开关添加到每次rm调用中,这会迫使您确认您希望删除文件。

if there are a lot of readonly files you want to remove then you could add the -fswitch to force deletion, be very careful with this.

如果您想删除很多只读文件,那么您可以添加-f强制删除的开关,对此要非常小心。

Be careful that rmaccepts multiple parameters so when you specify an absolute path make sure to do it within quotes or not to have any spaces, especially should you execute it as rootand superespecially with the -rand -foptions. (otherwise you'll join the group of people that did rm -rf / some/directory/*and killed their /inadvertantly)

要小心,rm接受多个参数,所以当你指定一个绝对路径一定要做到这一点引号内或不具有任何的空间,特别是你应该为执行它root,并super特别与-r-f选项。(否则你会加入rm -rf / some/directory/*那些/无意中杀死他们的人)

If you just want to look for big files and delete those then you could also use find

如果您只想查找大文件并删除它们,那么您也可以使用 find

find / -type f -size +100M

would search for files only (-type f) with a size > 100MB (-size +100M)

将仅搜索 ( -type f) 大小 > 100MB ( -size +100M) 的文件

subsequently you could use the same command to delete them.

随后您可以使用相同的命令删除它们。

find / -type f -size +100M -exec rm \{\} \;

-execexecutes a program which gets passed the file or folder it has found ( \{\}), needs to be terminated with \;

-exec执行一个程序,该程序通过它找到的文件或文件夹 ( \{\}),需要终止\;

don't forget you could add -ito rmto approve or disapprove a deletion.

不要忘了,你可以添加-irm批准或者不批准的缺失。