Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux find command gotcha?

Tags:

find

Hi I am trying to find all js & css files in one find command. I tried all of the below but in vain:

find WebContent -name "*.[jc]ss?"

find WebContent -name "*.[jc]ss{0,1}"

find WebContent -name "*.[jc][s]{1,2}$"

find WebContent -name "*.[jc]s{1,2}"

find WebContent -name "*.[jc]s[s]?"

Now what??

like image 834
rabbit Avatar asked Apr 07 '10 09:04

rabbit


People also ask

What is the find command on Linux?

The find command in UNIX is a command line utility for walking a file hierarchy. It can be used to find files and directories and perform subsequent operations on them. It supports searching by file, folder, name, creation date, modification date, owner and permissions.

What is +1 in find command?

The number can be a positive or negative value. A negative value equates to less then so -1 will find files modified within the last day. Similarly +1 will find files modified more than one day ago.

How do I search for a string in Linux?

Finding text strings within files using grep-r – Recursive search. -R – Read all files under each directory, recursively. Follow all symbolic links, unlike -r grep option. -n – Display line number of each matched line.

How do I search for a text file in Linux?

One of the easiest and fastest methods of locating text contained within a file on a computer running Linux is to use the grep command. Below is a basic example of a command used to locate any htm file containing the word "help". If any matches are found, text similar to the following example is shown.


1 Answers

-name accepts arguments that are globs, not regular expressions. You could use -regex if you wanted to use regular expressions, but the -o option (meaning "or") is probably the simplest solution:

find WebContent -name "*.js" -o -name "*.css"
like image 188
Joachim Sauer Avatar answered Sep 28 '22 17:09

Joachim Sauer