


The pattern is just a regex that says look for a dot followed by one or more chars that are not a dot \+, at the end of a line $. Next we have grep -o ".\+$" the -o tells grep to only output lines that match the pattern, and only output the match. The -type f omits directories from showing up in the list. jsįirst we have find /some/dir -type f which just limits find to output all the files in the directory recursively. In some cases we may need to search case insensitive and recursive manner. grep -i 'ISMAIL' /etc/passwd Case Insensitive Case Insensitive and Recursive. We will use -i option in order to specify case insensitivity. We expect to match both ismail and ISMAIL in /etc/passwd file. This will print out a nice list like this: 5. Now we will search for ISMAIL in a case insensitive manner. Here's one way to print out a list of extensions and the number of files of each type: find /some/dir -type f | grep -o ".\+$" | sort | uniq -c What if you want a listing of all file extensions and the count of files in a directory? js to show up only at the end of the file. js anywhere in the path, so we could improve that script by using a regular expression $ character, for example: find /some/dir | grep -c '\.js$' The above would also match a file, or a directory had. The -c in grep tells it to count the matches, I'm using fgrep here because I'm not using a regex (to avoid escaping the dot). For example you want to know how many js files are in a directory, you can run this: find /some/dir | fgrep -c '.js' For this example, we have created a Grep directory with VPS and SharedHosting directories inside it and will look for the VPS query.

#Grep recursive search how to#
Back in 2004 I wrote up a blog entry showing how to get a count of files by a specific extension. Recursive grep is useful for searching between all the lines in sub-directories and files inside the current working directory.
