Linux commands to find files based on type, size etc.

Use below command for finding some files and searching text into those files,
repalce DIR_TO_SEARCH with the proper path of directory you want to search in,

Linux command for find and grep

 $ find DIR_TO_SEARCH -name '*.c' -exec grep -i 'main' {} \; -print 

This command, finds all c files in DIR_TO_SEARCH directory and greps text “main” into those c files and prints the path of file on console.

Linux command to find file more that certain specified size

 $ find DIR_TO_SEARCH -size +100M 

This command, finds all files in DIR_TO_SEARCH directory which are more than 100MB and prints the path of file on console.

READ  Create a Dual Partition SD Card with Linux / Ubuntu

Linux command to find and remove certain files

 $ find DIR_TO_SEARCH -type f -name FILE_TO_DELETE -exec rm -f {} \; 

Linux command to find a file with name

 $ find DIR_TO_SEARCH -name hellowordld.pdf 

This command will find a pdf file with name ellowordld.pdf you need to use your filename.

Leave a Reply

Your email address will not be published. Required fields are marked *