![]() find -regex '.\.\(jpg\png\)' find -regextype posix-extended -regex '.\. The default regexp syntax is Emacs (basic regexps plus a few extensions such as \ for alternation) there's an option to switch to extended regexps. For a local search (without specifying the starting directory, e.g. On Linux, you can use -regex to combine extensions in a terser way. This sounds a bit complicated, but allows recursive search for. sh files, you have to define (add) your own type sh and use this filter ( -sh) like this: ack word -type-add=sh=.sh -sh / The option -shell is short for -type=shell and includes several file types: currently. may be called ack-grep on your system (on Debian based distros, if I remember correctly).has a grep-like syntax and the same/similar arguments like -i for "ignore case" etc.can easily narrow down your results by using filters for common file types (see below for distinct file name patterns).ignores (by default) directories from common version control systems, e.g.git.PATTERN įor your example, consider using ack -shell word / The combination of grep and find is in many cases ack ( ): ack. The second one is close to what I suggest, but there is no good reason to use xargs here, not to mention that safe and correct usage of xargs requires sacrificing portability for some GNU-only options ( find -print0 | xargs -0). The first one has the additional problem of potentially running into the ARG_MAX limit. ![]() It's best to avoid putting filenames in command substitution altogether. Both grep word `find / -name \*.sh 2>/dev/nullĪnd find / -name "*.sh" 2>/dev/null | xargs grep wordįail on files with whitespace in their name. There are some problems with the suggestions you received and posted in your question. This is for aesthetic and practical reasons, since running find on / will likely result in reams of "permission denied" messages you may not care about for files which you do not have permission to read and directories you do not have permission to traverse. 2>/dev/null: hide error messages (technically, redirect standard error to the black hole that is /dev/null).As previously explained, grep -l prints the names of files containing a match for word. The most portable and efficient recommendation is: find / -type f -name '*.sh' -exec grep -l word repeated from above and is replaced by file names. sh, starting at the root /, then find is the most appropriate tool. If you want to find all files in the file system ending in. Use grep -l word to only print names of files containing a match. If you only want to display filenames, you'll still want to add the -l option as I describe below. Edit: If you have GNU utilities, see Gilles' answer for a method using GNU grep's recursion abilities that is much simpler than the find approach.
0 Comments
Leave a Reply. |