Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need a way to distinguish a text file. This would be something that a Bash shell script could use. I write obsessively, and I'm stuck with out a dozen fantastically useful labor-saving shell scripts I could write because I don't have a way to test if a file is text or binary without having a C program open it, read a line of bytes from it, and close it!
Surely, there must be one of the little GNU/Unix programs that can be called with the right incantation from a batch script, probably with an obscure option set, which can return a boolean yes/no on whether the file contains ASCII text characters? I know the "less" program on some systems balks at binary files and asks if you'd like to see it anyway, but that's not good enough for automated script purposes.
This is such a basic function (represented on the character level frequently in languages like Python and C as the "isascii()" function or the "isprint()" function), that I'm positive there has to be one already in existence.
Not sure how exactly this can be done with a script but i do know that in a color consol if you type ls -- color text files are white and binaries are green.
So ls must know somehow what the files are without opening each one.
The best way i can think of is due to binaries having the execute permission set on them. Or someway though the file system.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.