Tweeted twitter.com/StackUnix/status/717891916227022852
6 deleted 546 characters in body
source | link

I'm writing a quick tool to inspect the contents of a node.js node_modules folder or python virtualenv for native dependencies. As a quick first approximation to this I wrote the following command.

find . | xargs file | awk '/C source/ {print $1} /ELF/ {print $1}'

I'm okay with false positives but not false negatives (e.g. files literally containing the string ELF or C source can be marked suspicious.), but this script also potentially breaks on long file names (because xargs will split them) and file names containing spaces (because awk will split on whitespace) and file names containing newlines (because find uses newlines to separate paths).

Is there a way to filter the paths generated by find by seeing if the output of file {} (possibly with some additional options to remove the path entirely from the output of file) matches a particular regular expression?

CORRECTIONS:

use exec cmd {} + and remove trailing colon from each line of output.

find . -exec file {} + | awk '/C source/ {print $1} /ELF/ {print $1} | sed -e 's/:$//'

replacing awk with grep -q and move test inside the -exec command. Use file -b instead of file to get just the classification of the file in question. No directory will ever be an ELF or C source file, add -type f to arguments of find command.

find . -type f -exec sh -c 'file -b "$0" | grep -q "^ELF\|^C source" && printf %s\\n "$0"' {} \;

I'm writing a quick tool to inspect the contents of a node.js node_modules folder or python virtualenv for native dependencies. As a quick first approximation to this I wrote the following command.

find . | xargs file | awk '/C source/ {print $1} /ELF/ {print $1}'

I'm okay with false positives but not false negatives (e.g. files literally containing the string ELF or C source can be marked suspicious.), but this script also potentially breaks on long file names (because xargs will split them) and file names containing spaces (because awk will split on whitespace) and file names containing newlines (because find uses newlines to separate paths).

Is there a way to filter the paths generated by find by seeing if the output of file {} (possibly with some additional options to remove the path entirely from the output of file) matches a particular regular expression?

CORRECTIONS:

use exec cmd {} + and remove trailing colon from each line of output.

find . -exec file {} + | awk '/C source/ {print $1} /ELF/ {print $1} | sed -e 's/:$//'

replacing awk with grep -q and move test inside the -exec command. Use file -b instead of file to get just the classification of the file in question. No directory will ever be an ELF or C source file, add -type f to arguments of find command.

find . -type f -exec sh -c 'file -b "$0" | grep -q "^ELF\|^C source" && printf %s\\n "$0"' {} \;

I'm writing a quick tool to inspect the contents of a node.js node_modules folder or python virtualenv for native dependencies. As a quick first approximation to this I wrote the following command.

find . | xargs file | awk '/C source/ {print $1} /ELF/ {print $1}'

I'm okay with false positives but not false negatives (e.g. files literally containing the string ELF or C source can be marked suspicious.), but this script also potentially breaks on long file names (because xargs will split them) and file names containing spaces (because awk will split on whitespace) and file names containing newlines (because find uses newlines to separate paths).

Is there a way to filter the paths generated by find by seeing if the output of file {} (possibly with some additional options to remove the path entirely from the output of file) matches a particular regular expression?

5 added 105 characters in body
source | link

I'm writing a quick tool to inspect the contents of a node.js node_modules folder or python virtualenv for native dependencies. As a quick first approximation to this I wrote the following command.

find . | xargs file | awk '/C source/ {print $1} /ELF/ {print $1}'

I'm okay with false positives but not false negatives (e.g. files literally containing the string ELF or C source can be marked suspicious.), but this script also potentially breaks on long file names (because xargs will split them) and file names containing spaces (because awk will split on whitespace) and file names containing newlines (because find uses newlines to separate paths).

Is there a way to filter the paths generated by find by seeing if the output of file {} (possibly with some additional options to remove the path entirely from the output of file) matches a particular regular expression?

CORRECTIONS:

use exec cmd {} + and remove trailing colon from each line of output.

find . -exec file {} + | awk '/C source/ {print $1} /ELF/ {print $1} | sed -e 's/:$//'

replacing awk with grep -q and move test inside the -exec command. Use file -b instead of file to get just the classification of the file in question. No directory will ever be an ELF or C source file, add -type f to arguments of find command.

find . -type f -exec sh -c 'file -b "$0" | grep -q "^ELF\|^C source" && printf %s\\n "$0"' {} \;

I'm writing a quick tool to inspect the contents of a node.js node_modules folder or python virtualenv for native dependencies. As a quick first approximation to this I wrote the following command.

find . | xargs file | awk '/C source/ {print $1} /ELF/ {print $1}'

I'm okay with false positives but not false negatives (e.g. files literally containing the string ELF or C source can be marked suspicious.), but this script also potentially breaks on long file names (because xargs will split them) and file names containing spaces (because awk will split on whitespace) and file names containing newlines (because find uses newlines to separate paths).

Is there a way to filter the paths generated by find by seeing if the output of file {} (possibly with some additional options to remove the path entirely from the output of file) matches a particular regular expression?

CORRECTIONS:

use exec cmd {} + and remove trailing colon from each line of output.

find . -exec file {} + | awk '/C source/ {print $1} /ELF/ {print $1} | sed -e 's/:$//'

replacing awk with grep -q and move test inside the -exec command. Use file -b instead of file to get just the classification of the file in question.

find . -exec sh -c 'file -b "$0" | grep -q "^ELF\|^C source" && printf %s\\n "$0"' {} \;

I'm writing a quick tool to inspect the contents of a node.js node_modules folder or python virtualenv for native dependencies. As a quick first approximation to this I wrote the following command.

find . | xargs file | awk '/C source/ {print $1} /ELF/ {print $1}'

I'm okay with false positives but not false negatives (e.g. files literally containing the string ELF or C source can be marked suspicious.), but this script also potentially breaks on long file names (because xargs will split them) and file names containing spaces (because awk will split on whitespace) and file names containing newlines (because find uses newlines to separate paths).

Is there a way to filter the paths generated by find by seeing if the output of file {} (possibly with some additional options to remove the path entirely from the output of file) matches a particular regular expression?

CORRECTIONS:

use exec cmd {} + and remove trailing colon from each line of output.

find . -exec file {} + | awk '/C source/ {print $1} /ELF/ {print $1} | sed -e 's/:$//'

replacing awk with grep -q and move test inside the -exec command. Use file -b instead of file to get just the classification of the file in question. No directory will ever be an ELF or C source file, add -type f to arguments of find command.

find . -type f -exec sh -c 'file -b "$0" | grep -q "^ELF\|^C source" && printf %s\\n "$0"' {} \;
4 added 262 characters in body
source | link

I'm writing a quick tool to inspect the contents of a node.js node_modules folder or python virtualenv for native dependencies. As a quick first approximation to this I wrote the following command.

find . | xargs file | awk '/C source/ {print $1} /ELF/ {print $1}'

I'm okay with false positives but not false negatives (e.g. files literally containing the string ELF or C source can be marked suspicious.), but this script also potentially breaks on long file names (because xargs will split them) and file names containing spaces (because awk will split on whitespace) and file names containing newlines (because find uses newlines to separate paths).

Is there a way to filter the paths generated by find by seeing if the output of file {} (possibly with some additional options to remove the path entirely from the output of file) matches a particular regular expression?

CORRECTIONS:

use exec cmd {} + and remove trailing colon from each line of output.

find . -exec file {} + | awk '/C source/ {print $1} /ELF/ {print $1} | sed -e 's/:$//'

replacing awk with grep -q and move test inside the -exec command. Use file -b instead of file to get just the classification of the file in question.

find . -exec sh -c 'file -b "$0" | grep -q "^ELF\|^C source" && printf %s\\n "$0"' {} \;

I'm writing a quick tool to inspect the contents of a node.js node_modules folder or python virtualenv for native dependencies. As a quick first approximation to this I wrote the following command.

find . | xargs file | awk '/C source/ {print $1} /ELF/ {print $1}'

I'm okay with false positives but not false negatives (e.g. files literally containing the string ELF or C source can be marked suspicious.), but this script also potentially breaks on long file names (because xargs will split them) and file names containing spaces (because awk will split on whitespace) and file names containing newlines (because find uses newlines to separate paths).

Is there a way to filter the paths generated by find by seeing if the output of file {} (possibly with some additional options to remove the path entirely from the output of file) matches a particular regular expression?

CORRECTIONS:

use exec cmd {} + and remove trailing colon from each line of output.

find -exec file {} + | awk '/C source/ {print $1} /ELF/ {print $1} | sed -e 's/:$//'

I'm writing a quick tool to inspect the contents of a node.js node_modules folder or python virtualenv for native dependencies. As a quick first approximation to this I wrote the following command.

find . | xargs file | awk '/C source/ {print $1} /ELF/ {print $1}'

I'm okay with false positives but not false negatives (e.g. files literally containing the string ELF or C source can be marked suspicious.), but this script also potentially breaks on long file names (because xargs will split them) and file names containing spaces (because awk will split on whitespace) and file names containing newlines (because find uses newlines to separate paths).

Is there a way to filter the paths generated by find by seeing if the output of file {} (possibly with some additional options to remove the path entirely from the output of file) matches a particular regular expression?

CORRECTIONS:

use exec cmd {} + and remove trailing colon from each line of output.

find . -exec file {} + | awk '/C source/ {print $1} /ELF/ {print $1} | sed -e 's/:$//'

replacing awk with grep -q and move test inside the -exec command. Use file -b instead of file to get just the classification of the file in question.

find . -exec sh -c 'file -b "$0" | grep -q "^ELF\|^C source" && printf %s\\n "$0"' {} \;
3 deleted 8 characters in body
source | link
2 added 191 characters in body
source | link
1
source | link