Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

Find command to exclude files with no extension

UNIX for Dummies Questions & Answers


 
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-28-2011
meenavin meenavin is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 11 December 2011, 8:07 PM EST
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Find command to exclude files with no extension

The below 'ls' command will list down files with extensions and suppress the ones with no extension


Code:
 ls |grep  "\\."

But this dosen't work when I apply the same logic using 'find' command


Code:
 find . -type f |grep  "\\."

I need help on how this logic can be implemented using 'find' command
Sponsored Links
    #2  
Old Unix and Linux 11-28-2011
ningy's Unix or Linux Image
ningy ningy is offline
Registered User
 
Join Date: May 2009
Last Activity: 11 June 2014, 2:05 AM EDT
Location: Bangalore, India
Posts: 131
Thanks: 11
Thanked 17 Times in 16 Posts
The above is not working coz when you use . for your directory to search the names will return like ./............. so grep will not return anything...

Why dont you try something like below :


Code:
find /dir1/subdir  -type f |grep "\\."

Sponsored Links
    #3  
Old Unix and Linux 11-28-2011
meenavin meenavin is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 11 December 2011, 8:07 PM EST
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by ningy View Post
The above is not working coz when you use . for your directory to search the names will return like ./............. so grep will not return anything...

Why dont you try something like below :


Code:
find /dir1/subdir  -type f |grep "\\."

It works fine only when there are no folders created with ".". I have few folders with name that has ".". In this case it fails
    #4  
Old Unix and Linux 11-28-2011
cero cero is offline
Registered User
 
Join Date: Aug 2006
Last Activity: 27 June 2017, 10:17 AM EDT
Posts: 452
Thanks: 4
Thanked 98 Times in 90 Posts
Use the -name option of find and avoid grep:

Code:
find . -type f -name "*.*" -print

Sponsored Links
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find command with exclude db2dbac Shell Programming and Scripting 1 05-31-2011 07:35 PM
SunOS: How to exclude directory in find command? saps19 Shell Programming and Scripting 3 03-28-2011 04:24 AM
Help - Find command to exclude sub-directories pchang Shell Programming and Scripting 7 08-17-2010 09:26 PM
find command to exclude directories SmurfGGM UNIX for Dummies Questions & Answers 1 07-10-2008 07:29 AM



All times are GMT -4. The time now is 01:33 AM.