How can I list only files that aren't compiled code in the current directory?

I'm reviewing the custom scripts and code on several HPUX and Linux servers before transferring them to a newer system. I get tired of seeing PuTTYPuTTYPuTTYPuTTYPuTTY when I encounter a file that is compiled.

I would like to sort them so that I can skip over the compiled software and come back to them at a later time.

  • 1
    maybe file * | grep -v ELF (not tested) – pmg Mar 26 '15 at 15:37
  • Your listing has to include file size and rights? Having just the file path is enough? – petry Mar 26 '15 at 15:42
  • file * | grep -v ELF will work if there are no other options, but I'd prefer to list them with file size and rights but exclude the executables. – Jeight Mar 26 '15 at 16:09
  • If you use less or view or several other programs, they'll avoid spewing control sequences to your terminal when you open binary files. – derobert Mar 26 '15 at 16:14
  • 1
    So I guess I can use the following line and create an alias for it file * | grep -v ELF | grep -v executable | awk '{print $1}' | sed -e 's/://g' | xargs ls -l. @pmg you helped me in the right direction. – Jeight Mar 26 '15 at 16:21

It bends the use of grep a bit

grep -r -I -l .

But it will list all non binary file in current directory. Using mostly the -I switch to exclude binary

  • It will recursively list files under that directory also. OP asked for current directory only. – Dr Beco Apr 15 '17 at 1:45
  • @DrBeco just drop the -r option – fie May 15 at 8:56

When ignoring files with the executable bit set, I just use this command:

find . ! -perm -111

To keep it from recursively enter into other directories:

find . -maxdepth 1 ! -perm -111

No need for pipes to mix lots of commands, just the powerful plain find command.

PS. Reference also link to my other answer


It should work,

file * | egrep -v 'ELF|executable' | awk '{print $1}' | sed -e 's/://g' | xargs ls -l

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.