{"id":2125,"date":"2024-11-27T11:41:27","date_gmt":"2024-11-27T11:41:27","guid":{"rendered":"https:\/\/tiruppurwebhosting.com\/blog\/?p=2125"},"modified":"2024-11-27T11:41:27","modified_gmt":"2024-11-27T11:41:27","slug":"how-to-find-large-files-and-directories-in-linux-server","status":"publish","type":"post","link":"https:\/\/tiruppurwebhosting.com\/blog\/how-to-find-large-files-and-directories-in-linux-server\/","title":{"rendered":"How To Find Large Files and Directories in Linux Server"},"content":{"rendered":"<h1 class=\"css-1ctyye4\">How To Find Large Files and Directories in Linux Server<\/h1>\n<figure style=\"width: 1200px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/vikhost.com\/wp-content\/uploads\/2024\/02\/Find-Large-Files-on-Linux-or-Unix-server.jpg\" alt=\"How To Find Large Files and Directories in Linux Server\" width=\"1200\" height=\"600\" \/><figcaption class=\"wp-caption-text\">How To Find Large Files and Directories in Linux Server<\/figcaption><\/figure>\n<h1>How To Find Large Files and Directories in Linux Server &#8211; When working with <a href=\"https:\/\/tiruppurwebhosting.com\/vps-hosting.html\">Linux servers<\/a>, it is often essential to monitor the disk space usage. One of the most common tasks is to find large files and directories that occupy too much disk space. To do this, we can use various command-line tools in Linux. In this tutorial, we will discuss some of the most effective methods for locating large files and directories, sorted by largest ones first.<\/h1>\n<h2>How To Find Large Files and Directories in Linux Server &#8211; 3 Ways to Find Large Files and Directors in Linux<\/h2>\n<h3 class=\"wp-block-heading\">Method 1: Using the du Command<\/h3>\n<p>The\u00a0<strong>du<\/strong>\u00a0command is a popular Linux utility that helps to estimate file space usage. It can be used to display the sizes of individual files or directories on a Linux system. The following command shows the sizes of all directories in the current working directory:<\/p>\n<pre class=\"wp-block-code\"><code>$ du -sh *<\/code><\/pre>\n<p>Here, the\u00a0<code>-s<\/code>\u00a0flag indicates that we want to display only the total size of each file or directory, and the\u00a0<code>-h<\/code>\u00a0flag specifies that we want the output to be human-readable (in KB, MB, or GB).<\/p>\n<p>However, this command will list the directories based on their alphabetical order. To display them sorted by size, we can pipe the output of the\u00a0<code>du<\/code>\u00a0command to the\u00a0<code>sort<\/code>\u00a0command, like this:<\/p>\n<pre class=\"wp-block-code\"><code>$ du -sh * | sort -rh<\/code><\/pre>\n<p>Here, the\u00a0<code>sort<\/code>\u00a0command is used to sort the output in reverse numerical order (<code>-r<\/code>\u00a0flag) and human-readable format (<code>-h<\/code>\u00a0flag). The\u00a0<code><strong>sort<\/strong><\/code>\u00a0command will show the largest files and directories at the top of the list.<\/p>\n<h3>How To Find Large Files and Directories in Linux Server &#8211; Method 2: Using the find Command<\/h3>\n<figure style=\"width: 686px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.ytimg.com\/vi\/fu84lWgfXpk\/hq720.jpg?sqp=-oaymwEhCK4FEIIDSFryq4qpAxMIARUAAAAAGAElAADIQj0AgKJD&amp;rs=AOn4CLC6h5px0iaPRu82CsJR4x7D6mmImg\" alt=\"How To Find Large Files and Directories in Linux Server\" width=\"686\" height=\"386\" \/><figcaption class=\"wp-caption-text\">How To Find Large Files and Directories in Linux Server<\/figcaption><\/figure>\n<p>The\u00a0<code><strong>find<\/strong><\/code>\u00a0command is another powerful Linux utility that can be used to locate large files and directories on a Linux system. It is a versatile command that can search for files or directories based on various criteria, such as name, size, type, and time.<\/p>\n<p>To find files and directories larger than a specific size, we can use the\u00a0<code>find<\/code>\u00a0command with the\u00a0<code>-size<\/code>\u00a0option. For example, to find all files larger than 100 MB in the current directory and its sub-directories, we can run this command:<\/p>\n<pre class=\"wp-block-code\"><code>$ find . -type f -size +100M -exec ls -lh {} \\; | awk '{ print $5 \": \" $NF }' | sort -n -r | head<\/code><\/pre>\n<p>Here, the\u00a0<code><strong>.<\/strong><\/code>\u00a0specifies that we want to search in the current directory and its subdirectories. The\u00a0<code><strong>-type f<\/strong><\/code>\u00a0option specifies that we only want to find files (not directories). The\u00a0<code><strong>-size +100M<\/strong><\/code>\u00a0option indicates that we want to find files larger than 100 MB.<\/p>\n<p>The\u00a0<code><strong>ls -lh {} \\;<\/strong><\/code>\u00a0command is used with the\u00a0<code>-exec<\/code>\u00a0option to display the file details for each file found. The\u00a0<code><strong>awk<\/strong><\/code>\u00a0command is then used to extract the file size and name from the output, separated by a colon.<\/p>\n<p>Finally, the output is sorted by numerical order (<code>-n<\/code>\u00a0flag) and reverse order (<code>-r<\/code>\u00a0flag), and the first 10 largest files are displayed (<code>head<\/code>\u00a0command).<\/p>\n<p>To find large directories rather than files, we need to modify the above command slightly. We can replace\u00a0<code>-type f<\/code>\u00a0with\u00a0<code>-type d<\/code>\u00a0to search for directories instead of files:<\/p>\n<pre class=\"wp-block-code\"><code>$ find . -type d -size +1G -exec du -sh {} \\; | sort -rh<\/code><\/pre>\n<p>Here, we are searching for directories larger than 1 GB (<code>-size +1G<\/code>). The\u00a0<code><strong>du -sh {} \\;<\/strong><\/code>\u00a0command is used with the\u00a0<code>-exec<\/code>\u00a0option to display the total size of each directory found. The output is then sorted by size in reverse order (<code>-r<\/code>\u00a0and\u00a0<code>-h<\/code>\u00a0flags).<\/p>\n<h3 class=\"wp-block-heading\">Method 3: Using the ncdu Command<\/h3>\n<p>The\u00a0<strong>ncdu<\/strong>\u00a0command is a useful disk space analyzer tool that can help users monitor their disk usage and find large files and directories on their Linux servers. It offers an interactive text-based user interface that displays information on all files and directories.<\/p>\n<p>To install ncdu on your Linux system, run the following command:<\/p>\n<pre class=\"wp-block-code\"><code>$ sudo apt-get install ncdu<\/code><\/pre>\n<p>Once installed, we can run the ncdu command to analyze the disk usage in a directory:<\/p>\n<pre class=\"wp-block-code\"><code>$ ncdu \/path\/to\/directory<\/code><\/pre>\n<p>This will show a detailed list of all files and directories in the specified directory, sorted by size in descending order. The largest files and directories appear at the top of the list. We can use the arrow keys to navigate through the list and press\u00a0<code>Enter<\/code>\u00a0to explore subdirectories.<\/p>\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n<figure style=\"width: 1020px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/greenwebpage.com\/community\/wp-content\/uploads\/2024\/09\/See-large-files-in-Linux.jpeg\" alt=\"How To Find Large Files and Directories in Linux Server\" width=\"1020\" height=\"600\" \/><figcaption class=\"wp-caption-text\">How To Find Large Files and Directories in Linux Server<\/figcaption><\/figure>\n<p>In this tutorial, we have learned how to find large files and directories on a Linux server, sorted by largest ones first. We have explored various command-line tools, such as du, find, and ncdu, that can help us to monitor the disk space usage of our <a href=\"https:\/\/www.squarebrothers.com\/vps-hosting-india\/\" target=\"_blank\" rel=\"noopener\">Linux systems<\/a>. By using these tools, we can effectively manage the disk space of our <a href=\"https:\/\/www.squarebrothers.com\/cloudlinux-vps-hosting-india\/\" target=\"_blank\" rel=\"noopener\">servers<\/a> and ensure that they are running optimally.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How To Find Large Files and Directories in Linux Server How To Find Large Files and Directories in Linux Server &#8211; When working with Linux servers, it is often essential to monitor the disk space usage. One of the most common tasks is to find large files and directories that occupy too much disk space.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-2125","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/2125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=2125"}],"version-history":[{"count":4,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/2125\/revisions"}],"predecessor-version":[{"id":2129,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/2125\/revisions\/2129"}],"wp:attachment":[{"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=2125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=2125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=2125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}