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 inpath...
. If nopath...
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/ \;
Enjoy Reading This Article?
Here are some more articles you might like to read next: