Busybox does not include the traditional linux "file" commad. Is there any alternative way to detect whether a file is binary or ascii? Thanks
Asked
Active
Viewed 811 times
1 Answers
0
You can try using grep. This thread contains some variants of using grep command: https://stackoverflow.com/a/30133802/3694234. For me, this command works fine.
$ grep -P "[^\x00-\x7F]" filename && echo Binary || echo Text
You can use this in a bash script
#!/bin/bash
type=$(grep -P "[^\x00-\x7F]" $1 > /dev/null && echo Binary || echo Text)
echo "File type: ${type}"
Sample output
$ ./getFileType.sh test.c
File type: Text
$ ./getFileType.sh test
File type: Binary

Yasir Khan
- 645
- 4
- 9