I got some issues grepping a certain text in a folder.
grep "Notifying status" -R
Binary file fix2.log matches
It turns out that the file containing the text is binary. Actually it is a log file (created by PAC manager) and can be read properly using notepad++ (or any other text file). I'm not sure why the OS determines it a
When I do ls
so all files are listed with the same -rwxr--r--
When I do file fix2.log
it shows as data
Is there any command to show if a file is binary or not, example from ls
view?
Under Linux/Unix, look for anything that isn't "text/plain":
$ file -I -b /tmp/local-access.log
text/plain; charset=us-ascii
Edit:
Actually, since file
does classify between different types of text-file, the encoding might be the better way to go:
$ echo "Testing" | file -I -b -
text/plain; charset=us-ascii
$ echo "<html></html>" | file -I -b -
text/html; charset=us-ascii
$ echo "<?xml version="1.0"?><catalog></catalog>" | file -I -b -
application/xml; charset=us-ascii
$ echo "<?xml version="1.0"?><catalog></catalog>" | file --mime-encoding -b -
us-ascii
Note @CharlesDuffy's comment below. This will only check some head/tail information but, 1) this will be sufficient in all non-exotic situations (most binary files aren't going to have pure text at the front and back of the file), and 2) you don't necessarily want to check every byte if the input is of arbitrary length (e.g. 2G)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With