When I type this in Ubuntu:
# cat -A my.config
It outputs:
^@^@^@^@^@^@^@^@^@^@^@
But for:
# cat my.config
nothing shows up in the terminal.
So from bash, how can you tell if a file contains those strange characters?
Thanks!
Those characters are NULL bytes. You can search for them on a file with:
grep -Pa '\x00' /folder/file
You may also search for all non-ASCII characters on a file with this:
grep -Pa "[\x80-\xFF]" /folder/file
Finally, you could check for all non-ASCII characters on all files in a folder with the following code:
grep -Pa -r "[\x80-\xFF]" /folder
Note: the core of this answer relies on grep -P, which might not be available on all grep versions. Also, from grep man about the -P option:
-P, --perl-regexp Interpret PATTERN as a Perl regular expression. This is highly experimental and grep -P may warn of unimplemented features.
Assuming "viewable" class in your post matches grep "graph" class, this should work
grep -la "[^[:graph:]]"
graph character class is part of POSIX BRE, so absent -a this answer would be guaranteed to work on all POSIX platforms.
filecommand, it will tell you if the file is a text file or something else.