Linux Recursive Search inside files

You can make a search inside files within a a directory using the command “find“, to do that:

  • with the find command
cd /to_folder
find . -iname ‘*conf’ | xargs grep ‘string’ -sl

-iname ‘*conf’ states that the seach will only check the files ending with *conf,
using -iname ‘*’ will search inside all the files within the current directory.
grep ‘string’ is the query string that you ment to search for.

If you only want to make a search based on the file names you should better use “locate” since it has an indexing feature to make faster searches:

updatedb
locate filename

 

If you don’t have the locate command, you can install it with the yum installer:

updatedb
yum install mlocate
  • Find files based on their size

With the below command you can find the files greater than 100 MBs.

find /folder/ -type f -size +100000k -exec ls -lh {} \; | awk ‘{ print $9 “: ” $5 }’
  • Find files based on their modification date

With the below command you can find the files based on their modification date., if you write ctime instead of mtime you can list the files created within two days.:

find /folder/ -type f -mtime -2 -exec ls -lh {} \; | awk ‘{ print $9 “: ” $5 }’
VN:F [1.9.22_1171]
 
<div class="gdouter gdheight"
  • 9 Users Found This Useful
Was this answer helpful?

Related Articles

Setting time with NTP in LINUX

NTP (Network Time Protocol) could be used to set time synced with ntp clocks, to do this use the...

Linux version & Operating System info

LINUX Version Info To learn the architecture and kernel version info use the shell command...

Build PHP5.5 on CentOS 6.4 with MSSQL Support [cite]

Most of the yum repos doesn’t include PHP5.5.X on current releases for the time being. So...

Change Outgoing IP of Postfix Mail Server

This can get quite important when your mail server is blacklisted, or if you somehow want to...

Add New Hosting to a System Installed With Plugged.sh

If you use our LAMP installer script and want to add a new domain afterwards, we’ve created...