In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Preface
It is well known that when the system runs out of disk space, you may use the df, du, or ncdu commands to check, but these commands only display files in the current directory, not system-wide files.
It will take you a lot of time to use the above command to get the largest file in the system, because you need to go to each directory and run the command repeatedly.
This method is troublesome and inappropriate.
If so, how do you find the top 10 files in Linux?
I searched Google for a long time, but I didn't find any similar articles. Instead, I saw a lot of articles about listing the top 10 files in the current directory. Therefore, I hope this article will be helpful to those with similar needs.
In this tutorial, we will show you how to find the top 10 largest files in your Linux system using the following four methods.
Method 1
There are no specific commands in Linux that can do this directly, so we need to use multiple commands together.
# find /-type f-print0 | xargs-0 du-h | sort-rh | head-n 101.4G / swapfile1.1G / home/magi/ubuntu-17.04-desktop-amd64.iso564M / home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqTFU0XzkzUlJUZzA378M / home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqeldzUmhPeC03Zm8377M / home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqRGd4V0VrOXM4YVU100M / usr/lib/x86_64-linux-gnu/libOxideQtCore.so.093M / usr/lib/firefox/libxul. So84M / var/lib/snapd/snaps/core_3604.snap84M / var/lib/snapd/snaps/core_3440.snap84M / var/lib/snapd/snaps/core_3247.snap
Detailed explanation:
Find: command to search for files in the directory structure /: search the entire system (starting from the root directory)-type: specify the file type
F: normal file-print0: displays the full file name in standard output, followed by an empty character (null) |: control operator Pass the output of one command to the next command for further processing of xargs: a command that converts standard input into command line arguments-0: with null characters instead of white space characters (LCTT translator's note: space, (tabs and line breaks) to split record du-h: command to calculate disk space usage in readable format sort: command to sort text files-r: reverse results-h: print output in readable format head: command at the beginning of the output file n-10: print the first 10 files
Method 2
This is another way to find the top 10 largest files on a Linux system. We still use multiple commands to accomplish this task together.
# find /-type f-exec du-Sh {} + | sort-rh | head-n 101.4G / swapfile1.1G / home/magi/ubuntu-17.04-desktop-amd64.iso564M / home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqTFU0XzkzUlJUZzA378M / home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqeldzUmhPeC03Zm8377M / home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqRGd4V0VrOXM4YVU100M / usr/lib/x86_64-linux-gnu/libOxideQtCore.so.093M / usr/lib/firefox/libxul.so84M / var/lib/snapd/snaps/core_3604.snap84M / var/lib/snapd/snaps/core_3440.snap84M / var/lib/snapd/snaps/core_3247.snap
Detailed explanation:
Find: command to search for files in the directory structure /: search the entire system (starting from the root directory)-type: specify the file type
F: normal file-exec: run the specified command du: calculate the disk space occupied by the file on the selected file-S: does not include the size of the subdirectory-h: print in readable format {}: recursively find the directory and count the disk space occupied by each file |: control operator Pass the output of one command to the next command for further processing sort: command to sort the text file by line-r: reverse the result-h: print out head: command at the beginning of the output file n-10: print the first 10 files
Method 3
Here is another way to search for the top 10 largest files in the Linux system.
# find /-type f-print0 | xargs-0 du | sort-n | tail-10 | cut-f2 | xargs-I {} du-sh {} 84m / var/lib/snapd/snaps/core_3247.snap84M / var/lib/snapd/snaps/core_3440.snap84M / var/lib/snapd/snaps/core_3604.snap93M / usr/lib/firefox/libxul.so100M / usr/lib/x86_64-linux-gnu/libOxideQtCore.so.0377M / home/magi/.gdfuse/magi/cache/ 0B5nso_FPaZFqRGd4V0VrOXM4YVU378M / home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqeldzUmhPeC03Zm8564M / home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqTFU0XzkzUlJUZzA1.1G / home/magi/ubuntu-17.04-desktop-amd64.iso1.4G / swapfile
Detailed explanation:
Find: command to search for files in the directory structure /: search the entire system (starting from the root directory)-type: specify the file type
F: normal file-print0: outputs the full file name, followed by an empty character (null) |: control operator Pass the output of one command to the next command for further processing xargs: command to convert standard input to command line arguments-0: split record du with null characters (null) instead of blank characters: command to calculate disk space occupied by files sort: command to sort text files by line-n: compare by numeric size tail-10: output file end Command (last 10 files) cut: delete specific parts from each line-f2: select only specific field values-I {}: replace each replacement string that appears in the initial parameter with the name read from standard input-s: display only the sum of each parameter-h: print out in readable format {}: recursively find the directory Count the disk space occupied by each file
Method 4
There is also a way to find the top 10 largest files in the Linux system.
# find /-type f-ls | sort-k 7-r-n | head-10 | column-t | awk'{print $7 $11} '1494845440 / swapfile1085984380 / home/magi/ubuntu-17.04-desktop-amd64.iso591003648 / home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqTFU0XzkzUlJUZzA395770383 / home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqeldzUmhPeC03Zm8394891761 / home/magi/.gdfuse/magi/cache/0B5nso_FPaZFqRGd4V0VrOXM4YVU103999072 / usr/lib/x86_64-linux-gnu/libOxideQtCore.so.097356256 / usr/lib/firefox/libxul.so87896064 / var/lib/snapd/snaps/core_3604.snap87793664 / var/lib/snapd/snaps/core_ 3440.snap87089152 / var/lib/snapd/snaps/core_3247.snap
Detailed explanation:
Find: command to search for files in the directory structure /: search the entire system (starting from the root directory)-type: specify the file type
F: normal file-ls: lists the current file in ls-dils format in standard output |: control operator Pass the output of one command to the next command for further processing sort: command to sort text files by line-k: sort by specified column-r: reverse result-n: compare by numeric size head: command at the beginning of the output file-10: print the first 10 files column: command to format its input as multiple columns-t: determine the number of columns the input contains And create a table awk: schema scanning and processing language'{print $7 $11}': print only the specified columns
Summary
The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.
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.