Using the find
command
A find command is a powerful tool for searching for files on your system. It can be used to find files based on various criteria, such as file name, size, ownership, and permissions.
To find large files in Linux using the find
command, you can use the following syntax:
For example, to find all files larger than 100 MB in the /home
directory, you can use the following command:
The size can also be passed in MB, or GB, for example, to search files larger than 100 MB use 100m
with -size
parameter.
You can also use the -exec
option to perform an action on the files that are found. For example, to delete all files larger than 100 MB in the /home
directory, you can use the following command:
Using the du
command
The du
(disk usage) command is another tool that can be used to find large files in Linux. It displays the size of each file and directory in a directory tree, allowing you to see which files and directories are taking up the most space.
To find large files in Linux using the du
command, you can use the following syntax:
For example, to find the top 10 largest files in the /home
directory, you can use the following command:
Using the locate
command
The locate
command is a tool that can be used to quickly find files on your system. It uses a database of file names to search for files, rather than searching the file system itself, which makes it faster than other tools like find. However, the locate database must be updated regularly in order for it to be effective, so it may not always have the most up-to-date information.
To find large files in Linux using the locate command, you can use the following syntax:
For example, to find all files larger than 100 MB
that contain the string “largefile” in their name, you can use the following command:
Using the ncdu
command
The ncdu
(NCurses Disk Usage) command is a tool that allows you to visualize the disk usage on your system in a text-based interface. It displays a list of directories and the amount of space they are taking up, and you can navigate through the directories by using the arrow keys.
To use the ncdu
command to find large files in Linux, follow these steps:
You can also use the -x option to tell ncdu
to scan directories that are on different filesystems, and the -r
option to recursively scan subdirectories. For example, to find large files in the /home
directory and all of its subdirectories, you can use the following command: