LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-06-2014, 05:16 AM   #1
jojanmpaul
Member
 
Registered: Sep 2012
Location: Bangalore
Posts: 80

Rep: Reputation: Disabled
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
 
Old 06-06-2014, 05:43 AM   #2
pingu
Senior Member
 
Registered: Jul 2004
Location: Skuttunge SWEDEN
Distribution: Debian preferably
Posts: 1,350

Rep: Reputation: 127Reputation: 127
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
 
Old 06-06-2014, 05:49 AM   #3
jojanmpaul
Member
 
Registered: Sep 2012
Location: Bangalore
Posts: 80

Original Poster
Rep: Reputation: Disabled
Am using the following to command but no luck

find /var/www/html/Macrotext/ -name '*.php' | grep 10.10.3.120 >> /tmp/phpfilelist120.txt
 
Old 06-06-2014, 05:56 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,121

Rep: Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270
because that grep will search in the filenames instead of contents. You need to check the -exec flag of find (see man page)
 
Old 06-06-2014, 06:00 AM   #5
pingu
Senior Member
 
Registered: Jul 2004
Location: Skuttunge SWEDEN
Distribution: Debian preferably
Posts: 1,350

Rep: Reputation: 127Reputation: 127
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.

Last edited by pingu; 06-06-2014 at 06:02 AM. Reason: Edit - replace "first" w "second"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make link list and add and delete list node in shared memory golden_boy615 Programming 1 12-18-2011 07:52 AM
Need advice on a script to search many files for list of terms, append hits to list jimmy the saint Programming 1 07-11-2010 04:59 AM
[SOLVED] Make list of directories which contain files other than subdirs zainka Programming 9 10-21-2009 05:20 AM
Kate: Append files to existing list and enable the Recent List AGazzaz Linux - Software 2 10-13-2009 09:27 PM
Script to reclusively find all media (mp3) files and make a list tommytomthms5 Linux - Newbie 13 10-15-2008 08:53 PM


All times are GMT -5. The time now is 12:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration