diff --git a/find/2_Combine_find_and_grep_with_exec/code b/find/2_Combine_find_and_grep_with_exec/code new file mode 100644 index 0000000..9e26f6d --- /dev/null +++ b/find/2_Combine_find_and_grep_with_exec/code @@ -0,0 +1 @@ +find /usr/share -name "*.py" -type f -executable -exec grep -Hnsw "return" {} \; diff --git a/find/2_Combine_find_and_grep_with_exec/info b/find/2_Combine_find_and_grep_with_exec/info new file mode 100644 index 0000000..693a8fe --- /dev/null +++ b/find/2_Combine_find_and_grep_with_exec/info @@ -0,0 +1,80 @@ +Find all files with extension .py and exec permissions, grep only rows that contain *return* word. + + +[source.sh] +---- +find /usr/share -name "*.py" -type f -executable -exec grep -Hnsw "return" {} \; + + +search for files in a directory hierarchy + +-name pattern + Base of file name (the path with the leading directories removed) matches shell pattern pattern. + The metacharacters (`*', `?', and `[]') match a `.' at the start of the base name (this is a + change in findutils-4.2.2; see section STANDARDS CONFORMANCE below). To ignore a directory and + the files under it, use -prune; see an example in the description of -path. Braces are not + recognised as being special, despite the fact that some shells including Bash imbue braces with a + special meaning in shell patterns. The filename matching is performed with the use of the + fnmatch(3) library function. Don't forget to enclose the pattern in quotes in order to protect + it from expansion by the shell. + +type c + File is of type c: + + b block (buffered) special + + c character (unbuffered) special + + d directory + + p named pipe (FIFO) + + f regular file + + l symbolic link + + s socket + + +-exec command ; + Execute command; true if 0 status is returned. All following arguments to find are taken to be + arguments to the command until an argument consisting of `;' is encountered. The string `{}' is + replaced by the current file name being processed everywhere it occurs in the arguments to the + command, not just in arguments where it is alone, as in some versions of find. Both of these + constructions might need to be escaped (with a `\') or quoted to protect them from expansion by + the shell. See the EXAMPLES section for examples of the use of the -exec option. The specified + command is run once for each matched file. The command is executed in the starting directory. + There are unavoidable security problems surrounding use of the -exec action; you should use the + -execdir option instead. + +grep searches the named input FILEs (or standard input if no files are named, or if a single hyphen-minus +(-) is given as file name) for lines containing a match to the given PATTERN. By default, grep prints +the matching lines. + +print lines matching a pattern + +-H, --with-filename + Print the file name for each match. This is the default when there is more than one file to + search. + +-n, --line-number + Prefix each line of output with the 1-based line number within its input file. (-n is specified + by POSIX.) + +-s, --no-messages + Suppress error messages about nonexistent or unreadable files. Portability note: unlike GNU grep, + 7th Edition Unix grep did not conform to POSIX, because it lacked -q and its -s option behaved + like GNU grep's -q option. USG-style grep also lacked -q but its -s option behaved like GNU grep. + Portable shell scripts should avoid both -q and -s and should redirect standard and error output + to /dev/null instead. (-s is specified by POSIX.) + +-w, --word-regexp + Select only those lines containing matches that form whole words. The test is that the matching + substring must either be at the beginning of the line, or preceded by a non-word constituent + character. Similarly, it must be either at the end of the line or followed by a non-word + constituent character. Word-constituent characters are letters, digits, and the underscore. + +---- + + + diff --git a/index_find.yml b/index_find.yml index 5556009..a8bf626 100644 --- a/index_find.yml +++ b/index_find.yml @@ -49,3 +49,26 @@ points: "" # ELO output: log: "bash" + 2_Combine_find_and_grep_with_exec: + display_name: "Combine_find_and_grep_with_exec" + swarmlabservice: "os2" + info: + file: "2_Combine_find_and_grep_with_exec/info" + code: + lang: "bash" + exec: "/bin/bash" + file: "2_Combine_find_and_grep_with_exec/code" + data: "2_Combine_find_and_grep_with_exec/data" + options: "" + mimetype: "bash" + output: + log: "console" + mimetype: "bash" + challenge: + question: "2_Combine_find_and_grep_with_exec/q-info" + codehelp: "2_Combine_find_and_grep_with_exec/codehelp" + codeanswer: "2_Combine_find_and_grep_with_exec/codeanswer" + mimetype: "bash" + points: "" # ELO + output: + log: "bash"