In order now to display the largest directories/files including sub-folders, run : du -Sh | sort -rh | head -n 10. Note: in this example we are sorting by a column that captures the product quantity and is titled Quantity. du -sk * | sort -n Which will display the size of all files and directories in the current directory with the biggest being at the bottom. Try: du --max-depth=7 /* | sort -n - it won't just tell you directories, and there will be duplicates, but it will list everything 7 levels deep and sort them by size order. You now have the biggest files in that folder. $ du -m --max-depth 1 | sort -rn | head -11 List all directories and sort by size bash script. Improve this answer. sort -rn | head -n 10 will show only the top few, if that's of any interest. man ls will show you this. du shows you the disk usage in each subdirectory. 1. n is to compare string numerical value and r to reverse the result being displayed. Add a comment | 5 Answers Active Oldest Votes. 100K tutorials 36K tutorials/target 12K tutorials/test_dir To display the largest directories and files of a particular directory, for example /var, run: $ sudo du /var -a | sort -n -r | head … du : Estimate file space usage; sort : Sort lines of text files or given input data; head : Output the first part of files i.e. For a list of subdirectories in a file system, change the directory to the path name that is associated with that file system. If it is something you can delete, just delete it. human readable just add du -hx --max-depth=1 | sort -n. Llauro 09 September 2015 Reply. Examples of showing a disk usage summary, outputting a human readable format, showing the size of a directory and showing the ten largest files or folders on a system. This is extremely useful as we can search the whole disk and order the output based on file size, allowing us to quickly locate large files. 5. The du command also displays the files and directory sizes in a recursively manner. Then run the following pipeline: $ du | sort -r -n: This pipeline, which uses the reverse (-r) and numeric (-n) options of the sort command, identifies large directories. By aggregating the following three commands (the use of pipes) can help you easily discover a list of largest documents on a Linux machine. Select Smallest to Largest from the Order drop down menu. The following bash script will accept 2 arguments. 7. i prefere root acces to execute the commands The ls command is most popular and very useful command for listing the content of directories. 6. du -h --max-depth=1 tutorials | sort -rh. 1) List Files in the directory by size (Sorting) To list a content of a specific directory with size sorting, we will use -lS options with ls command. You can combine the output of the du command with the sort command to sort the directories by the order of their size. On Mac OS X (which runs a form of Unix) this command works for me: ls -alS That lists the files in order, from largest to smallest. If the File parameter specified is actually a directory, all files within the directory are reported on. With zsh, you'd find the largest file (in terms of apparent size like the size column in ls -l output, not disk usage) with: ls -ld -- **/*(DOL[1]) For the 6 largest ones: ls -ld -- **/*(DOL[1,6]) To sort those by file size, you can use ls's -S option. Reply. du -BM --max-depth=1 | sort -n (or to see it sorted largest first): du -BM --max-depth=1 | sort -nr Caveat: This displays everything in Megabytes, so the smallest unit you will see is 1M. It will display files with the highest size at the top. – Terrance Mar 9 '16 at 18:34. -maxdepth 1 -type f -exec du -h {} + | sort --human-numeric-sort --reverse You can set how deep it can look for files with -maxdepth parameter or without it to be recursive. – AgileTillIDie Mar 17 '14 at 13:51. The following command asks du to return information in summary format, in human readable numbers, for all directories (*) below the current working directory. Click OK. Append a | tail -r to sort by largest first. You can go ahead and delete them if you think they are useless in order to free up some space. By default, the Sort-Object cmdlet performs an ascending sort—the numbers range from small to large. n is to compare string numerical value and r to reverse the result being displayed. find . The above command will show the largest directories which are consuming excessive disk space. The du command has many parameter options that can be used to get the results in many formats. jhon02@msn.com 09 August 2015 Reply. To reverse the listing so it shows smallest to largest, just add the 'r' option to that command: ls -alSr Note: in this example we are sorting by cell values. This will show the directories in the reverse order of their size i.e. du command: It estimates file space usage; sort command: Sort lines of text files or given input data; head command: Output the first part of files i.e. du -a /var | sort -n -r | head -n 10 In the above command the options du is to estimate file space usage, sort if to sort lines of text files or given input data and head is to output the first part of files i.e. 5. A du/sort command to show the largest files under a directory on Mac OS X. the biggest directory on the top. First argument will be a directory name in which we will start our search and the second argument will by a number of directories the script should output. $ ls -l | sort +4rn | more. to display the n largest files/directories. Combine du with other commands through pipes to produce even more useful results. I just read the link and found that the command du /home/* | sort -n -r can sort the file from size ( from largest to smallest ) , but I can not do it sort by size from largest to smallest Help answer threads with 0 replies . This will search your entire filesystem (du -a /), sort the results by size (sort -n -r), and then show only the top ten results (head -n 10). Tutorial on using du, a UNIX and Linux command for estimating file space usage. to display the n largest files/directories. du -sm Pictures/* | sort -nr Display the size of files in blocks from largest to smallest. If you’re looking to accentuate your windows with something a little different, be it curtains or blinds, then you’ve come to the right place!Here at The Range we’ve drawn all you could possibly need into one easy to browse window. to display first 10 largest file . Sort Output By Disk Usage Size. 74. sort -rn sorts things in reverse numerical order. du -a /var | sort -n -r | head -n 10 In the above command the options du is to estimate file space usage, sort if to sort lines of text files or given input data and head is to output the first part of files i.e. | sort … Find Large Files and Directories Using the du Command # The du command is used to estimate file space usage, and it is particularly useful for finding directories and files that consume large amounts of disk space. Linux command to Find the biggest file inside a directory $ ls -lS | head That's it. Any ideas on how to make this command faster ?? $ sudo du -ah | sort -n -r | head -n 10. du -cks * | sort -rn | head -11 # Usually set this up in my bash profile as an alias: # alias ducks='du -cks * | sort -rn | head -11' # Because it is fun to type ducks on the command line. We can ask du to sort the folders in size from largest to smallest. ls -s option flag lists file size. Keep drilling down until you find the biggest files on your system. If the bottom-most item is a directory, then cd into that directory and run the du command again. Let give on example . du -sh ~/* | sort -rh sort has -h flag: -h, --human-numeric-sort, --sort=human-numeric Sort by numerical value, but take into account the SI suffix, if present. While not built into the du command, we can pipe it to the sort command in order to list files in order of file size, such as smallest to largest. If the characters or columns for the files are different, use the following command to sort a list of files by block size, from largest to smallest. In this article, we will explain how to use ls sort option to list directory content by size. If you need to see it in Kilobytes just change the "M" to a "K". Using the command above we can create a bash script to make our life easier. Einstein47 From your folder: find . 8. du -hs * | sort -rh | head -n 10. The following command will print the largest files and directories: du -ahx . $ du -sk ./* | sort -rn | head -5 27921556 ./dir100d 1920392 ./dir200d 14036 ./sqllib 8 ./dir300d 5 ./dir400d Explaining the command above: du. -type f -exec du {} \; | sort -rn | head -10. so the command says:- find all files and run then run du (estimate file space usage) then sort as per the size and get me 10 largest. Note that this command sorts files in a list by the character that is in the fourth field, starting from the left. ls -lS sorts files from largest to smallest. The problem is that du doesn't sort the results. 16. sort -rh will work nicely with du -cksh * as it sorts human-readable units. ls -S option flag sorts files/directories list by file size. – Phrogz Mar 16 '14 at 3:34. The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk usage of files and directories on a machine. find largets 20 files or directories . du -h -s * The Picture folder holds the most data by far. It’s essentially a shortcut for the top ten largest files on your machine. Select the Column by which you want to sort by. Finally, as a bonus, you can sort the results from largest to smallest by piping in the sort command: # du -h -d 1 -t 1G / | sort -hr . To list the directory sizes in Mega bytes and largest at the top du -sm * | sort +0nr du -sm * | sort -nr To list the directory sizes in kilo bytes and largest at the bottom. du -sk * | sort +0n du -sk * | sort -n To list the directory sizes in Mega bytes and largest at the bottom. Share. As you see in the above results, we have listed all files and directories and its sub-directories in the current working directory. – Matti Mar 6 '11 at 20:54 Given a random block on a filesystem, is it possible to find the filename associated with it? Select the Sort on type. To sort a Unix / Linux directory listing by file size, you just need to add one or more options to the base ls. You can also sort the first command like this too, in which case you’re combining the three commands into one: # du -h --max-depth=1 / | grep '[0-9]G\>' | sort -hr . The Unix/Linux command that worked for me on my MacOS system is this: $ du -a * | sort -r -n | head -10. du is the disk usage command, and the -a flag says, “Display an entry for each file in a file hierarchy.” Then I use the sort command to sort the du output numerically and in reverse. $ du -hs */ | sort -nr | head This will give you the biggest directories in the disk, then you can go inside one of them, preferably the biggest ones, and find files to delete using ls command. The du command displays the number of blocks used for files. I might like to know largest file even if it few kb’s … The only problem I am working on is this will take long time to get me results. Share Improve this answer