Fedrik
Fedrik

Reputation: 133

search/find a folder that has a name with integer numbers in linux from terminal

I am using fedora 15 on my machine. Actually i am trying to find the folders with name like apache-tomcat-7.0.37 by searching in the entire file system

Actually i had some folders like below in the path /opt/tomcat/

apache-tomcat-7.0.37
apache-tomcat-6.0.34
apache-tomcat-7.0.67
.........

And some folders at /usr/share/tomcat/

apache-tomcat-4.0.7
apache-tomcat-6.0.4
apache-tomcat-8.0.6
.........

So i want is to locate/find/search all these folder paths from linux terminal by using a command.

I have googled a lot and got some commands like locate and find as below

find / -name apache-tomcat*
locate apache-tomcat 

The above commands are listing all the folder including extra unwanted information of folders, so actually what i want is , need to search for only for the folders that has the name like apache-tomcat-x.x.x,apache-tomcat-xx.xx.xx

Here in the folder name the starting words apache-tomcat is same and only the integer part (version number) changes. So i want to find all the folders with different version number like by using regular expressions in place of integer numbers to find the folders

so can anyone please let me know how to search the folder of the above scenario by using a command with regular expressions or someting like that which find all the folders with name apache-tomcat-xx.x.xxx.....

Upvotes: 1

Views: 6213

Answers (2)

regetz
regetz

Reputation: 691

You can provide a suitable regular expression to locate in order to do a fast search of your entire system:

locate -b --regex "apache-tomcat-[0-9]+.[0-9]+.[0-9]+$"

As with any use of locate, the file database it uses will need to be sufficiently up-to-date. If you have sufficient permissions, you can do sudo updatedb to force an update.

Upvotes: 2

Tuxdude
Tuxdude

Reputation: 49563

This should find all files, diretories, links, etc. that have the pattern apache-tomcat-X.Y.Z where X, Y, and Z are integers.

find . -regextype sed -regex ".*/apache-tomcat-[0-9]\+\.[0-9]\+\.[0-9]\+"

If you're looking only for directories, use this variant:

find . -type d -regextype sed -regex ".*/apache-tomcat-[0-9]\+\.[0-9]\+\.[0-9]\+"

If you want to search the entire system starting at /, use this variant:

find / -type d -regextype sed -regex ".*/apache-tomcat-[0-9]\+\.[0-9]\+\.[0-9]\+"

Upvotes: 3

Related Questions