The moose likes Linux / UNIX and the fly likes search in unix for files without extension Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Reply Bookmark "search in unix for files without extension" Watch "search in unix for files without extension" New topic
Author

search in unix for files without extension

Anand Bhatt
Ranch Hand

Joined: May 30, 2007
Posts: 179
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 23635

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Certs: SCEA Part 1, Part 2 & 3 & Core Spring 3, OCAJP
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 9982

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.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 23635

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

Joined: May 30, 2007
Posts: 179
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

Joined: Mar 28, 2003
Posts: 9982

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.
 
 
subject: search in unix for files without extension
 
Threads others viewed
Need to search large log files present in a remote unix server
Renaming the logs in Unix without shutting the server
A way out ?
Can i check i byte[] contains binary bytes ???
File locking in Unix?
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com