0

Find files by custom size in first level of directory using find command

I am having trouble finding and removing files by refining them using the custom size of the file can you please give me the solution for this problem?

Ubuntu find command Amazon Linux Arch Linux ARM Linux find directories find files eDirectory Linux directory system Add a comment
yousuf
asked Dec 14 2021

Answer

0

You can use the 'find' command in combination with the '-size' option to locate and remove files based on their size. For example, to find and list files larger than a specific size (say, 10MB) use the following command syntax:

find /path/to/your/directory -type f -size +10M

Here,

  • replace '/path/to/your/directory' with your directory location.
  • -type f, ensures that you are looking for regular files (not directories or other types)
  • -size +10M, specifies that you want files larger than 10MB.

Once you identify the files you want to remove, you can use the '-exec' option to pass them to the 'rm' command to delete them:

find /path/to/your/directory -type f -size +10M -exec rm {} \;

Here,

  • '{}', represents the current file that 'find' has matched.
  • '\;', denotes the end of the '-exec' command.
    NOTE: Be careful when using the 'rm' command, especially with 'find'. As the data will be permanently deleted.
    To view the process more practically, about how you can use the find command with the -exec option, go to here.
Add a comment
Aurora
asked Sep 19 2023
edited Sep 20 2023
Post your Answer