• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

search in unix for files without extension

 
Anand Bhatt
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to find the files without any extensions under one directory. What is the Unix command for same.
Also how can i narrow down my search so that I can exclude some files from search
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34695
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's actually two commands. You first need "ls" to list the files in that directory. You then need to pipe it to grep to get the lines that don't match.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11893
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the find command, and on that man page, the ! (or -not) operator, the -depth option, and -name option, and the -type option. A combination of these will work.

In thinking about this, my answer is probably better for answering homework assignment. Jeanne's is way easier if you are actually trying to get the work done with the least amount of effort.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34695
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd use Andrew's way if I needed to go more than one directory in. If all the files are in the top level directory I am in, ls is simpler.
 
Anand Bhatt
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both if you a Big thanks for quick reply .I will definetly use both optiosn sugested by you.
I would like it more clear ,and let see if you cansugest some more accurate command
I have root directory emp and inside emp there are lots of sub-directories(depth could be from 1.........10+ level)
Now my exact reuirement is:
I need to list/find all shell scripts files( unfortunately those files have no extension like .sh,thse files contains .sh a ) under this top level directory i,e. emp .

In summary : List down those files having no extension and those files contains .sh in it.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11893
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still think my way solves this perfectly - just leave out the -depth option since you do not care about how many directories you traverse.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic