HPE GreenLake Administration
- Community Home
 - >
 - Servers and Operating Systems
 - >
 - Operating Systems
 - >
 - Operating System - HP-UX
 - >
 - Re: Searching for new files with a specific string
 
Operating System - HP-UX
        1840139
        Members
    
    
        2391
        Online
    
    
        110161
        Solutions
    
Forums
        Categories
Company
Local Language
                
                  
                  back
                
        
                
        
                
        
                
        
        
        
                
        
                
        
        
        
                
        
              
              Forums
Discussions
Forums
- Data Protection and Retention
 - Entry Storage Systems
 - Legacy
 - Midrange and Enterprise Storage
 - Storage Networking
 - HPE Nimble Storage
 
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
                
                  
                  back
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
            
                
            
                
            
                
            
                
            
            
                
            
                
            
            
                
            
                
              
            Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
 - Appliance Servers
 - Alpha Servers
 - BackOffice Products
 - Internet Products
 - HPE 9000 and HPE e3000 Servers
 - Networking
 - Netservers
 - Secure OS Software for Linux
 - Server Management (Insight Manager 7)
 - Windows Server 2003
 - Operating System - Tru64 Unix
 - ProLiant Deployment and Provisioning
 - Linux-Based Community / Regional
 - Microsoft System Center Integration
 
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
        Information
        Community
Resources
Community Language
        Language
        Forums
Blogs
	
		
			
            
                
            Go to solution
        
            
		
		
			
            	
	
		
        
		
	
	
		Topic Options
			
				
					
	
			
		
	- Subscribe to RSS Feed
 - Mark Topic as New
 - Mark Topic as Read
 - Float this Topic for Current User
 - Bookmark
 - Subscribe
 - Printer Friendly Page
 
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
11-05-2009 07:14 AM
11-05-2009 07:14 AM
			
				
					
					
						Hello,
I am need to search a directory tree for all "new" files containing a specific string. For example, search all files in /usr/var created after 01/01/09 and have the "test" word.
I've been tinkering with find and grep but not gotten too far.
Thanks,
	
			
				
		
			
			
			
			
			
			
		
		
		
	
	
	
I am need to search a directory tree for all "new" files containing a specific string. For example, search all files in /usr/var created after 01/01/09 and have the "test" word.
I've been tinkering with find and grep but not gotten too far.
Thanks,
Solved! Go to Solution.
		3 REPLIES 3
	
	            
            
		
		
			
            
                - Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
11-05-2009 07:31 AM
11-05-2009 07:31 AM
Solution
			
				
					
					
						Hi:
For your 'find' use the '-newer' option to find only files newer than 01/01/2009. Use the 'file' command to confine your queries only to "text" (not binary) files.
# cat .findit
#!/usr/bin/sh
typeset DIR=$1
typeset PAT=$2
touch -amt 010100002009 /tmp/myref
find ${DIR} -xdev -type f -newer /tmp/myref | while read FILE
do
[ $(file ${FILE} | grep -c ascii) -eq 0 ] && continue
grep "${PAT}" ${FILE} /dev/null
done
exit 0
...run as .findit /path_to_search pattern_to_find
Using '-type f' with find limits that which is returned to *files* as opposed to *directories*.
The script skips *binary* files and examines files of type *text* for the pattern_to_find.
Regards!
...JRF...
		
		
	
	
	
For your 'find' use the '-newer' option to find only files newer than 01/01/2009. Use the 'file' command to confine your queries only to "text" (not binary) files.
# cat .findit
#!/usr/bin/sh
typeset DIR=$1
typeset PAT=$2
touch -amt 010100002009 /tmp/myref
find ${DIR} -xdev -type f -newer /tmp/myref | while read FILE
do
[ $(file ${FILE} | grep -c ascii) -eq 0 ] && continue
grep "${PAT}" ${FILE} /dev/null
done
exit 0
...run as .findit /path_to_search pattern_to_find
Using '-type f' with find limits that which is returned to *files* as opposed to *directories*.
The script skips *binary* files and examines files of type *text* for the pattern_to_find.
Regards!
...JRF...
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
11-05-2009 09:34 AM
11-05-2009 09:34 AM
			
				
					
						
							Re: Searching for new files with a specific string
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						JRF,
Thank you...so much.
KJA
		
		
	
	
	
Thank you...so much.
KJA
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
11-05-2009 09:35 AM
11-05-2009 09:35 AM
			
				
					
						
							Re: Searching for new files with a specific string
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						The example provided by JRF did the job.
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
		
		
	
	
	
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
		
	
	
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP