Search for Files Bigger Than Certain Size

When the disk partition is filling up quickly, it’s quite an hassle for the system administrator to find out the location of the files taking up the most space.

An easy way to find and manipulate files based on the file size is by using the find command found in common UNIX distributions.

If you refer to the man page, there are numerous options that you can pass to the find command to accomplish the above task.

Let’s take a look at some of the common options.

  • -type
    Search based on file type
  • -name
    Search based on file name pattern
  • -size
    Search based on size, append a + to search for files greater than specified size
  • -exec
    Execute a command for each matched file, the string ‘{}’ is replaced by the current file being processed. The command is terminated by a ‘;’ character. The terminating character may need to be escaped with a ” to prevent expansion by the shell

To search for regular files bigger than 50MB ( 50 x 1024 x 1024 = 52428800 ) in the directory /home on a standard UNIX machine, the following command can be used:

If you are searching for files on Linux, you can use the GNU find command as follows:

To remove all files with the extension ‘.tmp’ from /home directory and that are over 2MB in size:

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }