LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Make list of files which contains IP (https://www.linuxquestions.org/questions/linux-newbie-8/make-list-of-files-which-contains-ip-4175507224/)

jojanmpaul 06-06-2014 04:16 AM

Make list of files which contains IP
 
Hello,

I would like to make a list of files which is having IP address present.

Example I can list the .php files by using the following,
find /var/www/html/Macrotext/ -name *.php >> /tmp/phpfilelist.txt

But how to list .php the files which is only having IP address in it.

Kind regards,
Jojan Paul

pingu 06-06-2014 04:43 AM

You can use 'grep' to find the files, 'grep -l' will print only filenames.
Here's one good page for you: http://www.shellhacks.com/en/RegEx-F...ile-Using-Grep

jojanmpaul 06-06-2014 04:49 AM

Am using the following to command but no luck

find /var/www/html/Macrotext/ -name '*.php' | grep 10.10.3.120 >> /tmp/phpfilelist120.txt

pan64 06-06-2014 04:56 AM

because that grep will search in the filenames instead of contents. You need to check the -exec flag of find (see man page)

pingu 06-06-2014 05:00 AM

You need to understand what you are doing.
In your example, you list all filenames ending with '.php', then you look for an ip address in the filenames.
You could do this two ways:
1. Find all files with ip addresses in them, then sort out the php-files
or
2. Find all php-files, then search each file for ip addresses.
Both ways work, without too much thinking I'd say the first method requires little less coding.
But if you want to search places with large amount of files the second method is probably faster - it's quicker to search for filenames than to search for a string in files.


All times are GMT -5. The time now is 08:20 PM.