One of the most common problems we all face with our systems is identifying large files that take up precious disk space. Whether you are a seasoned Linux user or a beginner, efficiently managing disk space is a necessary skill everyone should know. In this article, we will discuss different methods to find large files in your Linux system to help you recover valuable disk space.
How to Filter Large Files with find Command
The find command in Linux is a powerful tool to search for files and folders based on your criteria. When combined with the appropriate options, you can find large files hogging up memory on your Linux system. To locate the large files in Linux using the find command, use this syntax:
find <path_to_search> -type f -size <size_limit>
In the above syntax:
-type f
is used to specify the find command to look for only files.-size <size_limit>
specifies the file size limit to look for.
For example, to search for files larger than 1GB in the current directory, the command is:
find . -type f -size +1G
Whether large or small files, the find command is a life-saving Linux command. If you want to know more ways to use the find command, do check out our guide on
How to Find Large Files with du Command
The du command (stands for “disk usage”) is another powerful and versatile command line tool used to analyze the system disk usage in Linux. With the help of appropriate options, you can use it to find large files and folders in your Linux system. Use the following syntax to filter large files with the du command:
du -a -h <path_to_directory> | sort -h -r
Seems complicated? Let’s break down the syntax here:
- du: the command to analyze the disk usage
- -a: displays all files and folders
- -h: displays all sizes in MB, GB, KB, etc
- <path_to_directory>: specifies the directory path wherein you need to analyze the disk space
- |: this character is known as the “Pipe Character” and is used to send the output of a command as the input to the next command
- sort: this command is used to sort the output of any command
- -h: used to sort according to the human-readable numerical value of the file sizes
- -r: reverses the sorted output
Say, if you want to find all the large files in the ~/Documents/test directory, use this Linux command:
du -a -h ~/Documents/test | sort -h -r
If you want to see the amount of disk space acquired by different files and apps, check out our guide on different methods to check disk usage in Linux.
How to Find Large Files using ls Command
The ls command is the most basic yet powerful command. Generally, it is used to list the contents of a directory in alphabetical order. But with the help of some flags, you can use it to print all the large files in a directory as per this syntax:
ls <path_to_directory> -l -h -S
In the above syntax:
- <path_to_directory> refers to the directory path where you need to find the large files in your Linux file system. If left out, then ls will look inside the current directory.
- -l flag shows all the details of each entry.
- -h displays the sizes in kilobytes, megabytes, etc.
- -S sorts the output in reverse descending order.
For example, if you need to look for large files in the current directory on your Linux system, use this:
ls -l -h -S
To find the 10 largest files in Linux, use this syntax: du -a -h <path_to_directory> | sort -n -r | head -10
To find all the files with a specific permission set, use this syntax: find <path_to_directory> -perm <permissions> -type f
. Replace <path_to_directory>
with the directory, you want to search in and <permissions>
with the absolute mode permissions.