In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to find large files in Linux. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.
Over time, disk drives can be messed up by unnecessary files that take up a lot of disk space, resulting in insufficient disk space for Linux devices. So how to find these large files?
Use the find command to find large files
The find command is one of the most powerful tools in the Linux system to manage the staff library. It allows users to search for files and directories based on different criteria, including file size.
For example, if you want to search for files larger than 100MB, you can use the following command in the current working directory:
Sudo find. -xdev-type f-size + 100m
Description: you can put "." Replace with the path to the directory where you want to search for the largest file.
The output displays a list of files without any other information.
/ var/lib/libvirt/images/centos-7-desktop_default.img/var/lib/libvirt/images/bionic64_default.img/var/lib/libvirt/images/win10.qcow2/var/lib/libvirt/images/debian-9_default.img/var/lib/libvirt/images/ubuntu-18-04-desktop_default.img/var/lib/libvirt/images/centos-7_default.img
The find command can also be used in conjunction with other tools, such as ls or sort, to perform operations on these files.
For example, we pass the output of the find command to ls,ls to output the size of each found file, and then pipe the output to the sort command, sorting it according to the file size of column 5.
Find. -xdev-type f-size + 100m-print | xargs ls-lh | sort-k5pje 5-h-r
The following output is achieved:
-rw- 1 root root 40967M Jan 5 14:12 / var/lib/libvirt/images/win10.qcow2-rw- 1 root root 3725M Jan 7 22:12 / var/lib/libvirt/images/debian-9_default.img-rw- 1 root root 1524M Dec 30 07:46 / var/lib/libvirt/images/centos-7-desktop_default.img-rw- 1 root root 999m Jan 5 14:43 / var/lib/libvirt/images/ubuntu-18-04 var/lib/libvirt/images/centos-7_default.img-rw- root root 378M Jan 7 22:26 / var/lib/libvirt/images/bionic64_default.img
If the output contains a lot of information, we can also use the head command to output only the first 10 lines:
Find. -xdev-type f-size + 100m-print | xargs ls-lh | sort-k5pje 5-h-r | head
Let's break down and understand the above command:
1 、 find. -xdev-type f-size+100M-print: search the current working directory (.) for files (- type f) greater than 100MB (- size+100M), do not lower the directory on other file systems (- xdev), output the full file name on standard output, and then wrap the output (- print).
1. Xargs ls-lh: use xargs to execute the ls-lh command, which displays the output in a human-readable long list format.
3. Sort-k5pint 5-h-r: sort the rows according to column 5 (- k5pje 5), compare the human readable format (- h) and reverse the result (- r).
4. Head: only the first 10 lines of the pipe output are displayed.
The find command has many powerful options. For example, you can search for large files greater than x days, large files with a specific extension, or large files that belong to a specific user.
Use the du command to find large files and directories
The du command is used to estimate file space usage and is particularly useful for finding directories and files that take up a lot of disk space.
Use the following command to output the largest files and directories:
Du-ahx. | | sort-rh | head-5 |
Output:
55G.24G./.vagrant.d/boxes24G./.vagrant.d13G./Projects5.2G./.minikube
Command description:
1. Du-ahx.: estimate file space usage in the current working directory (.), calculate files and directories (a), output size in human-readable format (h), and skip directories on different file systems (x).
2. Sort-rh: sorts the rows by comparing the human-readable format (- h) and reverses the result (- r).
3. Head-5: output only the first five lines of the pipeline output.
The du command contains additional options that you can use to optimize the output of disk space usage.
Thank you for reading! This is the end of the method of finding large files in Linux. I hope the above content can help you to some extent, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.