- How to Find Out Top Directories and Files (Disk Space) in Linux
- How to Find Biggest Files and Directories in Linux
- Find Largest Directories in Linux
- Find Out Top File Sizes Only
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- Linux find largest file in directory recursively using find/du
- Linux find largest file in directory recursively using find
- Linux find a biggest files in /
- Linux find large files quickly with bash alias
- Finding largest file recursively on Linux bash shell using find
- Great! I found the largest files on my disk. What next?
- Conclusion
- How To: Linux Find Large Files in a Directory
- Linux List All Large Files
- Syntax for RedHat / CentOS / Fedora Linux
- Syntax for Debian / Ubuntu Linux
- Finding large files using the find command
- How to Find Large Files & Directories in Linux
- 1) Using find command
- 2) Using ls command
- 3) Using gt5 tool
- 4) Using du command
- 5) Ncdu commands to check disk usage
- 6) Shell Script to find top disk consuming directories
- Conclusion
How to Find Out Top Directories and Files (Disk Space) in Linux
As a Linux administrator, you must periodically check which files and folders are consuming more disk space. It is very necessary to find unnecessary junk and free up them from your hard disk.
This brief tutorial describes how to find the largest files and folders in the Linux file system using du (disk usage) and find command. If you want to learn more about these two commands, then head over to the following articles.
How to Find Biggest Files and Directories in Linux
Run the following command to find out top biggest directories under /home partition.
Find Largest Directories in Linux
The above command displays the biggest 5 directories of my /home partition.
Find Largest Directories in Linux
If you want to display the biggest directories in the current working directory, run:
Find Biggest Directories Only
Let us break down the command and see what says each parameter.
- du command: Estimate file space usage.
- a : Displays all files and folders.
- sort command : Sort lines of text files.
- -n : Compare according to string numerical value.
- -r : Reverse the result of comparisons.
- head : Output the first part of files.
- -n : Print the first ‘n’ lines. (In our case, We displayed the first 5 lines).
Some of you would like to display the above result in human-readable format. i.e you might want to display the largest files in KB, MB, or GB.
Find Top Directories Sizes in Linux
The above command will show the top directories, which are eating up more disk space. If you feel that some directories are not important, you can simply delete a few sub-directories or delete the entire folder to free up some space.
To display the largest folders/files including the sub-directories, run:
Find Largest Folder and Subdirectories
Find out the meaning of each option using in above command:
- du command: Estimate file space usage.
- -h : Print sizes in human-readable format (e.g., 10MB).
- -S : Do not include the size of subdirectories.
- -s : Display only a total for each argument.
- sort command : sort lines of text files.
- -r : Reverse the result of comparisons.
- -h : Compare human readable numbers (e.g., 2K, 1G).
- head : Output the first part of files.
Find Out Top File Sizes Only
If you want to display the biggest file sizes only, then run the following command:
Find Top File Sizes in Linux
To find the largest files in a particular location, just include the path beside the find command:
Find Top File Size in Specific Location
The above command will display the largest file from /home/tecmint/Downloads directory.
That’s all for now. Finding the biggest files and folders is no big deal. Even a novice administrator can easily find them. If you find this tutorial useful, please share it on your social networks and support TecMint.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
Linux find largest file in directory recursively using find/du
I have 500GB SSD installed on my Linux server. My web server is running out of the disk space. I need to find a biggest or largest file concerning file size on the disk. How do I find largest file in a directory recursively using the find command?
To find a big file concerning file size on disk is easy task if you know how to use the find, du and other command. The du command used to estimate file space usage on Linux system. The output of du passed on to the sort and head command using shell pipes. Let us see how to find largest file in Linux server using various commands.
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | No |
Requirements | Linux |
Est. reading time | 3 minutes |
Linux find largest file in directory recursively using find
The procedure to find largest files including directories in Linux is as follows:
- Open the terminal application
- Login as root user using the sudo -i command
- Type du -a /dir/ | sort -n -r | head -n 20
- du will estimate file space usage
- sort will sort out the output of du command
- head will only show top 20 largest file in /dir/
Linux find a biggest files in /
Linux find large files quickly with bash alias
One can hunt down disk space hogs with ducks bash shell alias
How To Find Largest Top 10 Files and Directories On Linux / UNIX / BSD
Finding largest file recursively on Linux bash shell using find
One can only list files and skip the directories with the find command instead of using the du command, sort command and head command combination:
$ sudo find / -type f -printf «%s\t%p\n» | sort -n | tail -1
$ find $HOME -type f -printf ‘%s %p\n’ | sort -nr | head -10
Here is what I got on my systems:
Where, find command options are as follows:
- $HOME – Directory search for files.
- -type f – Search for regular files only.
- -printf ‘%s %p\n’ – Force find to use print format on the scren, interpreting \ escapes and % directives. The %s will print file’s size in bytes. Show file name using %p . This speailized output makes it easy to sort out file names using the sort command.
The -n is for numeric sort and the -r passed to sort will reverse the result of comparisons. The head command is used to control and show the first part of files. In other words, only display the top 10 results from previous commands.
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Great! I found the largest files on my disk. What next?
Depend upon file/dir type you can either move or delete the file. For example, you cannot remove or move the Linux kernel or diver directories. To delete unwanted file on Linux use the rm command:
rm -i -v /path/to/file
To get rid of all files and its sub-directories recursively use following command:
rm -rf /path/to/folderName
To move file to a usb pen mounted at /mnt/usb/, run the mv command:
mv /path/to/large/file/ /mnt/usb/
Conclusion
You just learned how to search, find and list largest or biggest directories/files in Linux using the combination of du/find and other commands. For more info see this page or man pages of du and find commands:
man du
man find
man sort
man head
man tail
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
How To: Linux Find Large Files in a Directory
H ow do I find out all large files in a directory?
There is no single command that can be used to list all large files. But, with the help of find command command and shell pipes, you can easily list all large files. This page explains how to find the largest files and directories in Linux using various commands.
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | Yes |
Requirements | Find and du commands on Linux or Unix |
Est. reading time | 4 minutes |
Linux List All Large Files
To finds all files over 50,000KB (50MB+) in size and display their names, along with size, use following syntax:
The syntax may vary based upon GNU/find and your Linux distro. Hence read man pages.
Syntax for RedHat / CentOS / Fedora Linux
find -type f -size +
Search or find big files Linux (50MB) in current directory, enter:
$ find . -type f -size +50000k -exec ls -lh <> \; | awk ‘< print $9 ": " $5 >‘
Search in my /var/log directory:
# find /var/log -type f -size +100000k -exec ls -lh <> \; | awk ‘< print $9 ": " $5 >‘
Syntax for Debian / Ubuntu Linux
find -type f -size +
Search in current directory:
$ find . -type f -size +10000k -exec ls -lh <> \; | awk ‘< print $8 ": " $5 >‘
Sample output:
Above commands will lists files that are are greater than 10,000 kilobytes in size. To list all files in your home directory tree less than 500 bytes in size, type:
$ find $HOME -size -500b
OR
$ find
-size -500b
To list all files on the system whose size is exactly 20 512-byte blocks, type:
# find / -size 20
Finding large files using the find command
Let us search for files with size greater than 1000 MB, run
Источник
How to Find Large Files & Directories in Linux
Finding the size of large file and directories in Linux servers is one of the most important tasks that every system administrator came across in his daily tasks. So, every system administrator must know about multiple ways to find out the size of larger disks and files consuming the hard disks.
Sometimes, it becomes more important, when your system’s disk is getting filled so rapidly and you have to discover which files or directories are ingesting up, all of your disk area on a Linux. In this case, we should be able to find a particular directory location where the data is being filled up. As there is no such shortcut command which is available to discover the largest documents or directories on a Linux or UNIX file system but there is some possibility by using some command line utilities that can help us reach to the source location.
So, this tutorial will help you to use multiples commands that can be used either on a Linux or UNIX like systems to find the largest files or directories on the file systems.
1) Using find command
The ‘find’ command is very useful to search for files in a directory hierarchy and to search for finding large files and directories in your system. Let’s run the command below to lists all files that have the size bigger than 50MB, you can specify the even larger number.
To find more detailed results about these large files, you can extend your ‘find’ command below parameters.
Use the below command to find the to 10 largest files in a particular directory of your system.
2) Using ls command
The ‘ls’ is a Linux shell command that lists directory contents of files and directories. You can use this command in many ways to list the files and folders. To check the lists the files in the current directory ordered by size with bigger size on the top run below command.
Similarly, you can use ‘ls’ command to add with r for recursively displaying the size of files in the current directory or you can specify the path of that directory you wish to see the size of files present there.
To get a list of top 10 biggest files recursively in the current directory use below command.
To get more help to use ‘ls’ command, you can use below command.
3) Using gt5 tool
The ‘gt5’ is another awesome command line tool, that can be used to check the size of files & directories on a Linux system. But, it must be installed on your system before you can start using it. To install ‘gt5’ you can below command on your Linux system.
After installation, you can use this to check the size of your system files and directories using below commands.
You can specify any directory extended by ‘gt5’ command to check the top size directories and files. To further expand the directories, drag your mouse cursor on that directory and hit enter.
Let’s change your directory to another path and run ‘gt5’ command for the inside view of top files and directories.
4) Using du command
The ‘du’ command abbreviated as disk usage, reports the sizes of directory trees inclusive of all of their contents and the sizes of individual files. This makes it useful for tracking down space hogs, that is, directories and files that consume large or excessive amounts of space on a hard disk drive or other storage media.
The basic syntax for ‘du’ is as shown below.
To find out the top files and directories on a Linux/UNIX filesystem, there is not any appropriate command of du to get the required output but using it with other commands like ‘sort’, ‘head’ and ‘find’ commands as shown below. To get the output in the more human readable form you can use ‘-h’ parameter with the ‘du’ command.
Next, you can use below command by moving into your required directory where you want to check the top files as shown.
5) Ncdu commands to check disk usage
Ncdu is a disk usage analyzer with a Ncurses interface. It is very useful and easy to use when it comes to tracking down space consuming files and directories. You can simply install it using below command on your Ubuntu or RHEL system.
After installation, you can start using this command to check disk usage of your system.
After running this command, it will start updating your disk and show the results on the terminal. Use below command to check the disk usage of root partition of your system.
The biggest folder appears on top which facilitates you for troubleshooting. You can use its help command to know more about its usage to get more benefit from this.
6) Shell Script to find top disk consuming directories
In this shell script, we will see that which top directories are consuming the large disk space, so that we may be able to free some space during an emergency. The commands that we used in this script are ‘du’ with different keys, ‘sort’ and ‘head’.
Let’s create a new file using your command line editor like ‘vi’ and put the following content in it as shown below.
Save and close the configuration file, give the file executable permissions and then run the script to find the top directories under your defined location as shown.
Conclusion
In this tutorial, we used multiple command line utilities to check large and directories on disks of Linux systems. We frequently use multiple ways to reach those files or directories which consume a lot of disk space and have to use such commands to reach those files and directories. In this article, we just covered the command line tools to find disk space usage, while there are many other web analyzers available to find and monitor disk space with large files and directories.
Источник