Script to list only files of type ASCII text in the current directory?

16,118

Solution 1

The best of 2 worlds: Avoids the use of the useless xargs, and speeds things up, since the + triggers parallel invocation.

find . -type f -exec file {} + | grep ASCII

Solution 2

Exec 'file' on all the files in the current directoy, and then grep for 'ASCII':

find . -maxdepth 1 -exec file {} \; | grep ASCII

Solution 3

find . -type f -print0 | xargs -0 file | grep ASCII

On CentOS 5, ASCII can mean a lot of things such as "ASCII C++ program text", "ASCII English text", and "ASCII text" so you might need to narrow it down more.

Solution 4

If it is just the current directory, no need for find.

Just try file * .* | fgrep ASCII

Share:
16,118

Related videos on Youtube

Host Post
Author by

Host Post

Updated on September 17, 2022

Comments

  • Host Post
    Host Post almost 2 years

    How to write a shell script which searches the current UNIX directory and returns the names of all files of type ASCII text?

    • mattdm
      mattdm over 13 years
      The script you've shown above doesn't seem to relate to the question at all. That's odd.
  • sakisk
    sakisk over 13 years
    How portable is grep ASCII? I remember that once I had problems because the output of file is not exactly the same on all systems but I don't recall if it was related with ASCII files.
  • user unknown
    user unknown about 13 years
    Yes, but I need to add, that this is a gnu-find extension. Most of the time I forget about that.
  • jlliagre
    jlliagre about 13 years
    @user unknown: "+"' isn't a gnu-find extension. It was first introduced by SVR4 find then adopted by the POSIX standard and later included by Gnu find. Every current find implementation is very likely to implement it.
  • user unknown
    user unknown about 13 years
    Thanks @jiliagre, my horizon is to tall, I just know a little bit about about Linux, and enjoy to learn new facts.