find command

Table of Contents


Introduction

The find command is a powerful command-line utility that is used to search for files and directories in a specified location. It can be used to perform operations such as searching for files with specific names, searching for files with specific attributes, and executing commands on the found files.

Here is the general syntax for the find command:

find [path...] [expression]
  • path...: The starting point for the search. The search will start from each directory specified in path.... If no path... is specified, the current directory is used as the starting point.
  • expression: An expression that specifies the conditions that the files must match to be selected. The expression can include options, tests, and actions.

For example, the following command will find all files in the current directory and its subdirectories with a .txt extension:

find . -name "*.txt"

General commands that I used

  • Find all files larger than 500 MB [ Ref. ]

    find / -type f -size +500M
    
  • Find all files smaller than 500 MB

    find / -type f -size -500M
    
  • Find all files larger than 30 MB and delete it.

    find . -type f -size +30M -exec rm {} \;
    
  • To ask for each file before delete:

    find . -type f -size +30M -exec rm -i {} \;
    
  • To find all *.tar.gz file and delete it

    find . -type f -name "*.tar.gz" -size +30M -exec rm -i {} \;
    
  • To find all *.tar.gz file and move it

    find . -type f -name "*.tar.gz" -size +30M -exec mv {} NewFolder/ \;
    

Reference: http://www.zyxware.com/articles/2659/find-and-delete-files-greater-than-a-given-size-from-the-linux-command-line




Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • Vi-Editor
  • EOS uses
  • sed command
  • Grep command
  • GitLab workflow for CMS-AN
  • Condor Jobs
  • awk command
  • ROOT CheatSheet
  • Git CheatSheet
  • GridPack Generation
  • Bash Shell