unix find command

To find files based on name, the syntax is

find [path…] -name filepattern


find ~/Downloads/temp -name struts*xml

To use a regular expression:

find ~/Downloads/temp/ -regex .*jar.*/stru.*xml

Find other options here.

A strange thing I have noticed with the command “find ./ -name struts*” is that it only searches for files that match the name struts-tags.tld and ignore files like struts.xml. Later found out that the folder from where I am executing this search has only file that matches the format ‘struts*’, which is struts-tags.tld. So this looks like a feature of OSX to expand the struts* to struts-tags.tld. If there are more than one file that match the pattern, find will throw an error. So the correct way to search is to include the name in quotes as shown below:

find ~/Downloads/temp/ -name ‘sitemesh*’


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: