Find human-readable files











up vote
8
down vote

favorite
4












I am trying to find an efficient way to do the level 5 of the OverTheWire bandit challenge.



Anyway, I have a bunch of files, and there is only one that respects the following criteria:




  • Human-readable

  • 1033 bytes in size

  • Non-executable


Right now, I am using the find command, and I am able to find the files matching the 2 last criteria:



find . -size 1033c ! -executable


However, I don't know how to excluse non-human-readable files. Solutions I found for that challenge use the -readable test parameter, but I don't think this works. -readable only looks at the files' permissions, and not at its content, while the challenge description ask for an ASCII file or something like that.










share|improve this question




















  • 1




    How do you define human readable? Not binary?
    – terdon
    Sep 30 '16 at 13:51










  • file command is your friend :)
    – Romeo Ninov
    Sep 30 '16 at 13:52










  • Maybe duplicate of: stackoverflow.com/questions/14505218/…
    – zuazo
    Sep 30 '16 at 13:55










  • @zuazo there's no such thing as cross-site duplicates. That post might have the answer, but it isn't a "duplicate".
    – terdon
    Sep 30 '16 at 13:56






  • 2




    Humans are one of the most intelligent known species on earth. They're also the only one known to versed with computers. They can read most files provided they can find out the type and get hold of the encryption keys for encrypted one.
    – Stéphane Chazelas
    Sep 30 '16 at 13:58

















up vote
8
down vote

favorite
4












I am trying to find an efficient way to do the level 5 of the OverTheWire bandit challenge.



Anyway, I have a bunch of files, and there is only one that respects the following criteria:




  • Human-readable

  • 1033 bytes in size

  • Non-executable


Right now, I am using the find command, and I am able to find the files matching the 2 last criteria:



find . -size 1033c ! -executable


However, I don't know how to excluse non-human-readable files. Solutions I found for that challenge use the -readable test parameter, but I don't think this works. -readable only looks at the files' permissions, and not at its content, while the challenge description ask for an ASCII file or something like that.










share|improve this question




















  • 1




    How do you define human readable? Not binary?
    – terdon
    Sep 30 '16 at 13:51










  • file command is your friend :)
    – Romeo Ninov
    Sep 30 '16 at 13:52










  • Maybe duplicate of: stackoverflow.com/questions/14505218/…
    – zuazo
    Sep 30 '16 at 13:55










  • @zuazo there's no such thing as cross-site duplicates. That post might have the answer, but it isn't a "duplicate".
    – terdon
    Sep 30 '16 at 13:56






  • 2




    Humans are one of the most intelligent known species on earth. They're also the only one known to versed with computers. They can read most files provided they can find out the type and get hold of the encryption keys for encrypted one.
    – Stéphane Chazelas
    Sep 30 '16 at 13:58















up vote
8
down vote

favorite
4









up vote
8
down vote

favorite
4






4





I am trying to find an efficient way to do the level 5 of the OverTheWire bandit challenge.



Anyway, I have a bunch of files, and there is only one that respects the following criteria:




  • Human-readable

  • 1033 bytes in size

  • Non-executable


Right now, I am using the find command, and I am able to find the files matching the 2 last criteria:



find . -size 1033c ! -executable


However, I don't know how to excluse non-human-readable files. Solutions I found for that challenge use the -readable test parameter, but I don't think this works. -readable only looks at the files' permissions, and not at its content, while the challenge description ask for an ASCII file or something like that.










share|improve this question















I am trying to find an efficient way to do the level 5 of the OverTheWire bandit challenge.



Anyway, I have a bunch of files, and there is only one that respects the following criteria:




  • Human-readable

  • 1033 bytes in size

  • Non-executable


Right now, I am using the find command, and I am able to find the files matching the 2 last criteria:



find . -size 1033c ! -executable


However, I don't know how to excluse non-human-readable files. Solutions I found for that challenge use the -readable test parameter, but I don't think this works. -readable only looks at the files' permissions, and not at its content, while the challenge description ask for an ASCII file or something like that.







files find






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 30 '16 at 14:09









Jeff Schaller

37.4k1052121




37.4k1052121










asked Sep 30 '16 at 13:44









J.Doe

41112




41112








  • 1




    How do you define human readable? Not binary?
    – terdon
    Sep 30 '16 at 13:51










  • file command is your friend :)
    – Romeo Ninov
    Sep 30 '16 at 13:52










  • Maybe duplicate of: stackoverflow.com/questions/14505218/…
    – zuazo
    Sep 30 '16 at 13:55










  • @zuazo there's no such thing as cross-site duplicates. That post might have the answer, but it isn't a "duplicate".
    – terdon
    Sep 30 '16 at 13:56






  • 2




    Humans are one of the most intelligent known species on earth. They're also the only one known to versed with computers. They can read most files provided they can find out the type and get hold of the encryption keys for encrypted one.
    – Stéphane Chazelas
    Sep 30 '16 at 13:58
















  • 1




    How do you define human readable? Not binary?
    – terdon
    Sep 30 '16 at 13:51










  • file command is your friend :)
    – Romeo Ninov
    Sep 30 '16 at 13:52










  • Maybe duplicate of: stackoverflow.com/questions/14505218/…
    – zuazo
    Sep 30 '16 at 13:55










  • @zuazo there's no such thing as cross-site duplicates. That post might have the answer, but it isn't a "duplicate".
    – terdon
    Sep 30 '16 at 13:56






  • 2




    Humans are one of the most intelligent known species on earth. They're also the only one known to versed with computers. They can read most files provided they can find out the type and get hold of the encryption keys for encrypted one.
    – Stéphane Chazelas
    Sep 30 '16 at 13:58










1




1




How do you define human readable? Not binary?
– terdon
Sep 30 '16 at 13:51




How do you define human readable? Not binary?
– terdon
Sep 30 '16 at 13:51












file command is your friend :)
– Romeo Ninov
Sep 30 '16 at 13:52




file command is your friend :)
– Romeo Ninov
Sep 30 '16 at 13:52












Maybe duplicate of: stackoverflow.com/questions/14505218/…
– zuazo
Sep 30 '16 at 13:55




Maybe duplicate of: stackoverflow.com/questions/14505218/…
– zuazo
Sep 30 '16 at 13:55












@zuazo there's no such thing as cross-site duplicates. That post might have the answer, but it isn't a "duplicate".
– terdon
Sep 30 '16 at 13:56




@zuazo there's no such thing as cross-site duplicates. That post might have the answer, but it isn't a "duplicate".
– terdon
Sep 30 '16 at 13:56




2




2




Humans are one of the most intelligent known species on earth. They're also the only one known to versed with computers. They can read most files provided they can find out the type and get hold of the encryption keys for encrypted one.
– Stéphane Chazelas
Sep 30 '16 at 13:58






Humans are one of the most intelligent known species on earth. They're also the only one known to versed with computers. They can read most files provided they can find out the type and get hold of the encryption keys for encrypted one.
– Stéphane Chazelas
Sep 30 '16 at 13:58












10 Answers
10






active

oldest

votes

















up vote
9
down vote













Yes, you can use find to look for non-executable files of the right size and then use file to check for ASCII. Something like:



find . -type f -size 1033c ! -executable -exec file {} + | grep ASCII


The question, however, isn't as simple as it sounds. 'Human readable' is a horribly vague term. Presumably, you mean text. OK, but what kind of text? Latin character ASCII only? Full Unicode? For example, consider these three files:



$ cat file1
abcde
$ cat file2
αβγδε
$ cat file3
abcde
αβγδε
$ cat file4
#!/bin/sh
echo foo


These are all text and human readable. Now, let's see what file makes of them:



$ file *
file1: ASCII text
file2: UTF-8 Unicode text
file3: UTF-8 Unicode text
file4: POSIX shell script, ASCII text executable


So, the find command above will only find file1 (for the sake of this example, let's imagine those files had 1033 characters). You could expand the find to look for the string text:



find . -type f -size 1033c ! -executable -exec file {} + | grep -w text


With the -w, grep will only print lines where text is found as a stand-alone word. That should be pretty close to what you want, but I can't guarantee that there is no other file type whose description might also include the string text.






share|improve this answer




























    up vote
    2
    down vote













    While -exec is mostly used to do something with the files that where found, it can also act as a test. Therefore, we can add it to your other criteria:



    find . 
    -size 1033c
    -not -executable
    -exec sh -c 'file {} | grep "text$"' ;


    Remember, grep returns non-zero when the pattern wasn't found, and sh -c "COMMAND" will return the result of the evaluation (as long as it's valid). So this will only print files where file <filename> spits something out that ends with text, e.g. "UTF-8 Unicode text` or "ASCII text", but not "Non-ISO extended-ASCII text, with escape sequences".



    In a single line, it even ends up shorter than going over xargs:



    find . -size 1033c -not -executable -exec sh -c 'file {} | grep "text$"' ;


    Keep in mind that you can replace sh -c 'file {} | grep "text$"' with any custom command. If you want to check for something very complex, it might be a better idea to provide a shell script and use that instead:



    find . -size 1033c -not -executable -exec is_human_readable.sh {} ;


    which, in the long run, is easier to maintain than your shell's history:



    #!/bin/sh
    file "$@" | grep "text$" > /dev/null





    share|improve this answer





















    • Nice! Note, however, that matching text$ will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.
      – terdon
      Sep 30 '16 at 14:39










    • @terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
      – Zeta
      Sep 30 '16 at 14:43


















    up vote
    1
    down vote













    find . -size 1033c ! -executable -exec file {} +





    share|improve this answer






























      up vote
      0
      down vote













      find . -size 1033c ! -executable|xargs file|grep "ASCII text" |awk -F: '{print $1}'


      Please try this combined commands. it works on my station.






      share|improve this answer




























        up vote
        0
        down vote













        You can try this



        find . -size 1033c ! -executable -exec file {} +


        Your challenge does not allows grep. password file will be reported as "ASCII text, with very long lines"






        share|improve this answer






























          up vote
          0
          down vote













          To filter out the human-readable file names, you can make use of the [:print:] (printable) character class name. You will find more about such classes in the manual for grep.



          find . -type f -size 1033c -name "[[:print:]]*" ! -executable




          On a second thought, the "human-readable" requirement might refer to the file's content, instead of its name. In other words, you would be searching for text files. That is a little more tricky. As @D_Bye suggested in a comment, you should then use the file command to determine the file content type. But it would not be a good idea to run file after a pipe, because it would complicate the task of displaying the file's name. Here's what I suggest:



          find . -type f -size 1033c ! -executable -exec sh -c 'file -b $0 | grep -q text' {} ; -print


          This is briefly how the file-part works:




          • The -exec predicate executes sh -c 'file -b $0 | grep -q text' FILENAME for each FILENAME that satisfies all the previous conditions (type, size, non-executable).

          • For each of those files, a shell (sh) runs this short script: file -b $0 | grep -q text, replacing $0 with the filename.

          • The file program determines the content type of each file and outputs this information. The -b option prevents printing the name of each tested file.


          • grep filters the output coming from file program, searching for lines containing "text". (See for yourself, how a typical output of the file command looks like.)

          • But grep does not output the filtered text, because it has the -q (quiet) option given. What it does, is just change its exit status to either 0 (which represents "true" - the filtered text was found) or 1 (meaning "error" - the text "text" did not appear in the output from file).

          • The true/false exit status coming from grep is passed further by sh to find and acts as the final result of the whole "-exec sh -c 'file $0 | grep -q text' {} ;" test.

          • In case the above test returned true, the -print command is executed (i.e. the name of the tested file is printed).






          share|improve this answer




























            up vote
            0
            down vote













            You only need to use:



            find inhere -size 1033c


            It will give you the only file that contains the password.






            share|improve this answer




























              up vote
              0
              down vote













              bandit4@bandit:~$ ls
              inhere

              bandit4@bandit:~$ file inhere/*


              inhere/-file00: data
              inhere/-file01: data
              inhere/-file02: data
              inhere/-file03: data
              inhere/-file04: data
              inhere/-file05: data
              inhere/-file06: data
              inhere/-file07: ASCII text
              inhere/-file08: data
              inhere/-file09: data

              bandit4@bandit:~$ pwd

              /home/bandit4

              bandit4@bandit:~$ cat /home/bandit4/inhere/-file07

              koReBOKuIDDepwhWk7jZC0RTdopnAYKh
              bandit4@bandit:~$





              share|improve this answer























              • Simply use file inhere/* and cat /home/bandit4/inhere/-file07
                – user234732
                Jun 5 '17 at 22:41




















              up vote
              0
              down vote













              find  -type f ! -executable -size 1033c


              will get you the file from the exercise






              share|improve this answer




























                up vote
                -1
                down vote













                du --human-readable | find -not -executable -size 1033c


                will get your result






                share|improve this answer










                New contributor




                Varun Rathore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.


















                  Your Answer








                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "106"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  convertImagesToLinks: false,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f313442%2ffind-human-readable-files%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  10 Answers
                  10






                  active

                  oldest

                  votes








                  10 Answers
                  10






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  9
                  down vote













                  Yes, you can use find to look for non-executable files of the right size and then use file to check for ASCII. Something like:



                  find . -type f -size 1033c ! -executable -exec file {} + | grep ASCII


                  The question, however, isn't as simple as it sounds. 'Human readable' is a horribly vague term. Presumably, you mean text. OK, but what kind of text? Latin character ASCII only? Full Unicode? For example, consider these three files:



                  $ cat file1
                  abcde
                  $ cat file2
                  αβγδε
                  $ cat file3
                  abcde
                  αβγδε
                  $ cat file4
                  #!/bin/sh
                  echo foo


                  These are all text and human readable. Now, let's see what file makes of them:



                  $ file *
                  file1: ASCII text
                  file2: UTF-8 Unicode text
                  file3: UTF-8 Unicode text
                  file4: POSIX shell script, ASCII text executable


                  So, the find command above will only find file1 (for the sake of this example, let's imagine those files had 1033 characters). You could expand the find to look for the string text:



                  find . -type f -size 1033c ! -executable -exec file {} + | grep -w text


                  With the -w, grep will only print lines where text is found as a stand-alone word. That should be pretty close to what you want, but I can't guarantee that there is no other file type whose description might also include the string text.






                  share|improve this answer

























                    up vote
                    9
                    down vote













                    Yes, you can use find to look for non-executable files of the right size and then use file to check for ASCII. Something like:



                    find . -type f -size 1033c ! -executable -exec file {} + | grep ASCII


                    The question, however, isn't as simple as it sounds. 'Human readable' is a horribly vague term. Presumably, you mean text. OK, but what kind of text? Latin character ASCII only? Full Unicode? For example, consider these three files:



                    $ cat file1
                    abcde
                    $ cat file2
                    αβγδε
                    $ cat file3
                    abcde
                    αβγδε
                    $ cat file4
                    #!/bin/sh
                    echo foo


                    These are all text and human readable. Now, let's see what file makes of them:



                    $ file *
                    file1: ASCII text
                    file2: UTF-8 Unicode text
                    file3: UTF-8 Unicode text
                    file4: POSIX shell script, ASCII text executable


                    So, the find command above will only find file1 (for the sake of this example, let's imagine those files had 1033 characters). You could expand the find to look for the string text:



                    find . -type f -size 1033c ! -executable -exec file {} + | grep -w text


                    With the -w, grep will only print lines where text is found as a stand-alone word. That should be pretty close to what you want, but I can't guarantee that there is no other file type whose description might also include the string text.






                    share|improve this answer























                      up vote
                      9
                      down vote










                      up vote
                      9
                      down vote









                      Yes, you can use find to look for non-executable files of the right size and then use file to check for ASCII. Something like:



                      find . -type f -size 1033c ! -executable -exec file {} + | grep ASCII


                      The question, however, isn't as simple as it sounds. 'Human readable' is a horribly vague term. Presumably, you mean text. OK, but what kind of text? Latin character ASCII only? Full Unicode? For example, consider these three files:



                      $ cat file1
                      abcde
                      $ cat file2
                      αβγδε
                      $ cat file3
                      abcde
                      αβγδε
                      $ cat file4
                      #!/bin/sh
                      echo foo


                      These are all text and human readable. Now, let's see what file makes of them:



                      $ file *
                      file1: ASCII text
                      file2: UTF-8 Unicode text
                      file3: UTF-8 Unicode text
                      file4: POSIX shell script, ASCII text executable


                      So, the find command above will only find file1 (for the sake of this example, let's imagine those files had 1033 characters). You could expand the find to look for the string text:



                      find . -type f -size 1033c ! -executable -exec file {} + | grep -w text


                      With the -w, grep will only print lines where text is found as a stand-alone word. That should be pretty close to what you want, but I can't guarantee that there is no other file type whose description might also include the string text.






                      share|improve this answer












                      Yes, you can use find to look for non-executable files of the right size and then use file to check for ASCII. Something like:



                      find . -type f -size 1033c ! -executable -exec file {} + | grep ASCII


                      The question, however, isn't as simple as it sounds. 'Human readable' is a horribly vague term. Presumably, you mean text. OK, but what kind of text? Latin character ASCII only? Full Unicode? For example, consider these three files:



                      $ cat file1
                      abcde
                      $ cat file2
                      αβγδε
                      $ cat file3
                      abcde
                      αβγδε
                      $ cat file4
                      #!/bin/sh
                      echo foo


                      These are all text and human readable. Now, let's see what file makes of them:



                      $ file *
                      file1: ASCII text
                      file2: UTF-8 Unicode text
                      file3: UTF-8 Unicode text
                      file4: POSIX shell script, ASCII text executable


                      So, the find command above will only find file1 (for the sake of this example, let's imagine those files had 1033 characters). You could expand the find to look for the string text:



                      find . -type f -size 1033c ! -executable -exec file {} + | grep -w text


                      With the -w, grep will only print lines where text is found as a stand-alone word. That should be pretty close to what you want, but I can't guarantee that there is no other file type whose description might also include the string text.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Sep 30 '16 at 14:36









                      terdon

                      127k31245422




                      127k31245422
























                          up vote
                          2
                          down vote













                          While -exec is mostly used to do something with the files that where found, it can also act as a test. Therefore, we can add it to your other criteria:



                          find . 
                          -size 1033c
                          -not -executable
                          -exec sh -c 'file {} | grep "text$"' ;


                          Remember, grep returns non-zero when the pattern wasn't found, and sh -c "COMMAND" will return the result of the evaluation (as long as it's valid). So this will only print files where file <filename> spits something out that ends with text, e.g. "UTF-8 Unicode text` or "ASCII text", but not "Non-ISO extended-ASCII text, with escape sequences".



                          In a single line, it even ends up shorter than going over xargs:



                          find . -size 1033c -not -executable -exec sh -c 'file {} | grep "text$"' ;


                          Keep in mind that you can replace sh -c 'file {} | grep "text$"' with any custom command. If you want to check for something very complex, it might be a better idea to provide a shell script and use that instead:



                          find . -size 1033c -not -executable -exec is_human_readable.sh {} ;


                          which, in the long run, is easier to maintain than your shell's history:



                          #!/bin/sh
                          file "$@" | grep "text$" > /dev/null





                          share|improve this answer





















                          • Nice! Note, however, that matching text$ will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.
                            – terdon
                            Sep 30 '16 at 14:39










                          • @terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
                            – Zeta
                            Sep 30 '16 at 14:43















                          up vote
                          2
                          down vote













                          While -exec is mostly used to do something with the files that where found, it can also act as a test. Therefore, we can add it to your other criteria:



                          find . 
                          -size 1033c
                          -not -executable
                          -exec sh -c 'file {} | grep "text$"' ;


                          Remember, grep returns non-zero when the pattern wasn't found, and sh -c "COMMAND" will return the result of the evaluation (as long as it's valid). So this will only print files where file <filename> spits something out that ends with text, e.g. "UTF-8 Unicode text` or "ASCII text", but not "Non-ISO extended-ASCII text, with escape sequences".



                          In a single line, it even ends up shorter than going over xargs:



                          find . -size 1033c -not -executable -exec sh -c 'file {} | grep "text$"' ;


                          Keep in mind that you can replace sh -c 'file {} | grep "text$"' with any custom command. If you want to check for something very complex, it might be a better idea to provide a shell script and use that instead:



                          find . -size 1033c -not -executable -exec is_human_readable.sh {} ;


                          which, in the long run, is easier to maintain than your shell's history:



                          #!/bin/sh
                          file "$@" | grep "text$" > /dev/null





                          share|improve this answer





















                          • Nice! Note, however, that matching text$ will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.
                            – terdon
                            Sep 30 '16 at 14:39










                          • @terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
                            – Zeta
                            Sep 30 '16 at 14:43













                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          While -exec is mostly used to do something with the files that where found, it can also act as a test. Therefore, we can add it to your other criteria:



                          find . 
                          -size 1033c
                          -not -executable
                          -exec sh -c 'file {} | grep "text$"' ;


                          Remember, grep returns non-zero when the pattern wasn't found, and sh -c "COMMAND" will return the result of the evaluation (as long as it's valid). So this will only print files where file <filename> spits something out that ends with text, e.g. "UTF-8 Unicode text` or "ASCII text", but not "Non-ISO extended-ASCII text, with escape sequences".



                          In a single line, it even ends up shorter than going over xargs:



                          find . -size 1033c -not -executable -exec sh -c 'file {} | grep "text$"' ;


                          Keep in mind that you can replace sh -c 'file {} | grep "text$"' with any custom command. If you want to check for something very complex, it might be a better idea to provide a shell script and use that instead:



                          find . -size 1033c -not -executable -exec is_human_readable.sh {} ;


                          which, in the long run, is easier to maintain than your shell's history:



                          #!/bin/sh
                          file "$@" | grep "text$" > /dev/null





                          share|improve this answer












                          While -exec is mostly used to do something with the files that where found, it can also act as a test. Therefore, we can add it to your other criteria:



                          find . 
                          -size 1033c
                          -not -executable
                          -exec sh -c 'file {} | grep "text$"' ;


                          Remember, grep returns non-zero when the pattern wasn't found, and sh -c "COMMAND" will return the result of the evaluation (as long as it's valid). So this will only print files where file <filename> spits something out that ends with text, e.g. "UTF-8 Unicode text` or "ASCII text", but not "Non-ISO extended-ASCII text, with escape sequences".



                          In a single line, it even ends up shorter than going over xargs:



                          find . -size 1033c -not -executable -exec sh -c 'file {} | grep "text$"' ;


                          Keep in mind that you can replace sh -c 'file {} | grep "text$"' with any custom command. If you want to check for something very complex, it might be a better idea to provide a shell script and use that instead:



                          find . -size 1033c -not -executable -exec is_human_readable.sh {} ;


                          which, in the long run, is easier to maintain than your shell's history:



                          #!/bin/sh
                          file "$@" | grep "text$" > /dev/null






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 30 '16 at 14:36









                          Zeta

                          45627




                          45627












                          • Nice! Note, however, that matching text$ will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.
                            – terdon
                            Sep 30 '16 at 14:39










                          • @terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
                            – Zeta
                            Sep 30 '16 at 14:43


















                          • Nice! Note, however, that matching text$ will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.
                            – terdon
                            Sep 30 '16 at 14:39










                          • @terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
                            – Zeta
                            Sep 30 '16 at 14:43
















                          Nice! Note, however, that matching text$ will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.
                          – terdon
                          Sep 30 '16 at 14:39




                          Nice! Note, however, that matching text$ will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.
                          – terdon
                          Sep 30 '16 at 14:39












                          @terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
                          – Zeta
                          Sep 30 '16 at 14:43




                          @terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
                          – Zeta
                          Sep 30 '16 at 14:43










                          up vote
                          1
                          down vote













                          find . -size 1033c ! -executable -exec file {} +





                          share|improve this answer



























                            up vote
                            1
                            down vote













                            find . -size 1033c ! -executable -exec file {} +





                            share|improve this answer

























                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote









                              find . -size 1033c ! -executable -exec file {} +





                              share|improve this answer














                              find . -size 1033c ! -executable -exec file {} +






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Aug 16 at 11:21









                              jimmij

                              30.5k869103




                              30.5k869103










                              answered Aug 16 at 10:22









                              user305801

                              111




                              111






















                                  up vote
                                  0
                                  down vote













                                  find . -size 1033c ! -executable|xargs file|grep "ASCII text" |awk -F: '{print $1}'


                                  Please try this combined commands. it works on my station.






                                  share|improve this answer

























                                    up vote
                                    0
                                    down vote













                                    find . -size 1033c ! -executable|xargs file|grep "ASCII text" |awk -F: '{print $1}'


                                    Please try this combined commands. it works on my station.






                                    share|improve this answer























                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote









                                      find . -size 1033c ! -executable|xargs file|grep "ASCII text" |awk -F: '{print $1}'


                                      Please try this combined commands. it works on my station.






                                      share|improve this answer












                                      find . -size 1033c ! -executable|xargs file|grep "ASCII text" |awk -F: '{print $1}'


                                      Please try this combined commands. it works on my station.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Sep 30 '16 at 14:11









                                      Fengbo Wu

                                      11




                                      11






















                                          up vote
                                          0
                                          down vote













                                          You can try this



                                          find . -size 1033c ! -executable -exec file {} +


                                          Your challenge does not allows grep. password file will be reported as "ASCII text, with very long lines"






                                          share|improve this answer



























                                            up vote
                                            0
                                            down vote













                                            You can try this



                                            find . -size 1033c ! -executable -exec file {} +


                                            Your challenge does not allows grep. password file will be reported as "ASCII text, with very long lines"






                                            share|improve this answer

























                                              up vote
                                              0
                                              down vote










                                              up vote
                                              0
                                              down vote









                                              You can try this



                                              find . -size 1033c ! -executable -exec file {} +


                                              Your challenge does not allows grep. password file will be reported as "ASCII text, with very long lines"






                                              share|improve this answer














                                              You can try this



                                              find . -size 1033c ! -executable -exec file {} +


                                              Your challenge does not allows grep. password file will be reported as "ASCII text, with very long lines"







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Sep 30 '16 at 14:52

























                                              answered Sep 30 '16 at 13:57









                                              Emmanuel

                                              2,98911120




                                              2,98911120






















                                                  up vote
                                                  0
                                                  down vote













                                                  To filter out the human-readable file names, you can make use of the [:print:] (printable) character class name. You will find more about such classes in the manual for grep.



                                                  find . -type f -size 1033c -name "[[:print:]]*" ! -executable




                                                  On a second thought, the "human-readable" requirement might refer to the file's content, instead of its name. In other words, you would be searching for text files. That is a little more tricky. As @D_Bye suggested in a comment, you should then use the file command to determine the file content type. But it would not be a good idea to run file after a pipe, because it would complicate the task of displaying the file's name. Here's what I suggest:



                                                  find . -type f -size 1033c ! -executable -exec sh -c 'file -b $0 | grep -q text' {} ; -print


                                                  This is briefly how the file-part works:




                                                  • The -exec predicate executes sh -c 'file -b $0 | grep -q text' FILENAME for each FILENAME that satisfies all the previous conditions (type, size, non-executable).

                                                  • For each of those files, a shell (sh) runs this short script: file -b $0 | grep -q text, replacing $0 with the filename.

                                                  • The file program determines the content type of each file and outputs this information. The -b option prevents printing the name of each tested file.


                                                  • grep filters the output coming from file program, searching for lines containing "text". (See for yourself, how a typical output of the file command looks like.)

                                                  • But grep does not output the filtered text, because it has the -q (quiet) option given. What it does, is just change its exit status to either 0 (which represents "true" - the filtered text was found) or 1 (meaning "error" - the text "text" did not appear in the output from file).

                                                  • The true/false exit status coming from grep is passed further by sh to find and acts as the final result of the whole "-exec sh -c 'file $0 | grep -q text' {} ;" test.

                                                  • In case the above test returned true, the -print command is executed (i.e. the name of the tested file is printed).






                                                  share|improve this answer

























                                                    up vote
                                                    0
                                                    down vote













                                                    To filter out the human-readable file names, you can make use of the [:print:] (printable) character class name. You will find more about such classes in the manual for grep.



                                                    find . -type f -size 1033c -name "[[:print:]]*" ! -executable




                                                    On a second thought, the "human-readable" requirement might refer to the file's content, instead of its name. In other words, you would be searching for text files. That is a little more tricky. As @D_Bye suggested in a comment, you should then use the file command to determine the file content type. But it would not be a good idea to run file after a pipe, because it would complicate the task of displaying the file's name. Here's what I suggest:



                                                    find . -type f -size 1033c ! -executable -exec sh -c 'file -b $0 | grep -q text' {} ; -print


                                                    This is briefly how the file-part works:




                                                    • The -exec predicate executes sh -c 'file -b $0 | grep -q text' FILENAME for each FILENAME that satisfies all the previous conditions (type, size, non-executable).

                                                    • For each of those files, a shell (sh) runs this short script: file -b $0 | grep -q text, replacing $0 with the filename.

                                                    • The file program determines the content type of each file and outputs this information. The -b option prevents printing the name of each tested file.


                                                    • grep filters the output coming from file program, searching for lines containing "text". (See for yourself, how a typical output of the file command looks like.)

                                                    • But grep does not output the filtered text, because it has the -q (quiet) option given. What it does, is just change its exit status to either 0 (which represents "true" - the filtered text was found) or 1 (meaning "error" - the text "text" did not appear in the output from file).

                                                    • The true/false exit status coming from grep is passed further by sh to find and acts as the final result of the whole "-exec sh -c 'file $0 | grep -q text' {} ;" test.

                                                    • In case the above test returned true, the -print command is executed (i.e. the name of the tested file is printed).






                                                    share|improve this answer























                                                      up vote
                                                      0
                                                      down vote










                                                      up vote
                                                      0
                                                      down vote









                                                      To filter out the human-readable file names, you can make use of the [:print:] (printable) character class name. You will find more about such classes in the manual for grep.



                                                      find . -type f -size 1033c -name "[[:print:]]*" ! -executable




                                                      On a second thought, the "human-readable" requirement might refer to the file's content, instead of its name. In other words, you would be searching for text files. That is a little more tricky. As @D_Bye suggested in a comment, you should then use the file command to determine the file content type. But it would not be a good idea to run file after a pipe, because it would complicate the task of displaying the file's name. Here's what I suggest:



                                                      find . -type f -size 1033c ! -executable -exec sh -c 'file -b $0 | grep -q text' {} ; -print


                                                      This is briefly how the file-part works:




                                                      • The -exec predicate executes sh -c 'file -b $0 | grep -q text' FILENAME for each FILENAME that satisfies all the previous conditions (type, size, non-executable).

                                                      • For each of those files, a shell (sh) runs this short script: file -b $0 | grep -q text, replacing $0 with the filename.

                                                      • The file program determines the content type of each file and outputs this information. The -b option prevents printing the name of each tested file.


                                                      • grep filters the output coming from file program, searching for lines containing "text". (See for yourself, how a typical output of the file command looks like.)

                                                      • But grep does not output the filtered text, because it has the -q (quiet) option given. What it does, is just change its exit status to either 0 (which represents "true" - the filtered text was found) or 1 (meaning "error" - the text "text" did not appear in the output from file).

                                                      • The true/false exit status coming from grep is passed further by sh to find and acts as the final result of the whole "-exec sh -c 'file $0 | grep -q text' {} ;" test.

                                                      • In case the above test returned true, the -print command is executed (i.e. the name of the tested file is printed).






                                                      share|improve this answer












                                                      To filter out the human-readable file names, you can make use of the [:print:] (printable) character class name. You will find more about such classes in the manual for grep.



                                                      find . -type f -size 1033c -name "[[:print:]]*" ! -executable




                                                      On a second thought, the "human-readable" requirement might refer to the file's content, instead of its name. In other words, you would be searching for text files. That is a little more tricky. As @D_Bye suggested in a comment, you should then use the file command to determine the file content type. But it would not be a good idea to run file after a pipe, because it would complicate the task of displaying the file's name. Here's what I suggest:



                                                      find . -type f -size 1033c ! -executable -exec sh -c 'file -b $0 | grep -q text' {} ; -print


                                                      This is briefly how the file-part works:




                                                      • The -exec predicate executes sh -c 'file -b $0 | grep -q text' FILENAME for each FILENAME that satisfies all the previous conditions (type, size, non-executable).

                                                      • For each of those files, a shell (sh) runs this short script: file -b $0 | grep -q text, replacing $0 with the filename.

                                                      • The file program determines the content type of each file and outputs this information. The -b option prevents printing the name of each tested file.


                                                      • grep filters the output coming from file program, searching for lines containing "text". (See for yourself, how a typical output of the file command looks like.)

                                                      • But grep does not output the filtered text, because it has the -q (quiet) option given. What it does, is just change its exit status to either 0 (which represents "true" - the filtered text was found) or 1 (meaning "error" - the text "text" did not appear in the output from file).

                                                      • The true/false exit status coming from grep is passed further by sh to find and acts as the final result of the whole "-exec sh -c 'file $0 | grep -q text' {} ;" test.

                                                      • In case the above test returned true, the -print command is executed (i.e. the name of the tested file is printed).







                                                      share|improve this answer












                                                      share|improve this answer



                                                      share|improve this answer










                                                      answered Mar 13 '17 at 19:13









                                                      Alfran

                                                      1011




                                                      1011






















                                                          up vote
                                                          0
                                                          down vote













                                                          You only need to use:



                                                          find inhere -size 1033c


                                                          It will give you the only file that contains the password.






                                                          share|improve this answer

























                                                            up vote
                                                            0
                                                            down vote













                                                            You only need to use:



                                                            find inhere -size 1033c


                                                            It will give you the only file that contains the password.






                                                            share|improve this answer























                                                              up vote
                                                              0
                                                              down vote










                                                              up vote
                                                              0
                                                              down vote









                                                              You only need to use:



                                                              find inhere -size 1033c


                                                              It will give you the only file that contains the password.






                                                              share|improve this answer












                                                              You only need to use:



                                                              find inhere -size 1033c


                                                              It will give you the only file that contains the password.







                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered Mar 26 '17 at 0:09









                                                              BugHunterUK

                                                              178119




                                                              178119






















                                                                  up vote
                                                                  0
                                                                  down vote













                                                                  bandit4@bandit:~$ ls
                                                                  inhere

                                                                  bandit4@bandit:~$ file inhere/*


                                                                  inhere/-file00: data
                                                                  inhere/-file01: data
                                                                  inhere/-file02: data
                                                                  inhere/-file03: data
                                                                  inhere/-file04: data
                                                                  inhere/-file05: data
                                                                  inhere/-file06: data
                                                                  inhere/-file07: ASCII text
                                                                  inhere/-file08: data
                                                                  inhere/-file09: data

                                                                  bandit4@bandit:~$ pwd

                                                                  /home/bandit4

                                                                  bandit4@bandit:~$ cat /home/bandit4/inhere/-file07

                                                                  koReBOKuIDDepwhWk7jZC0RTdopnAYKh
                                                                  bandit4@bandit:~$





                                                                  share|improve this answer























                                                                  • Simply use file inhere/* and cat /home/bandit4/inhere/-file07
                                                                    – user234732
                                                                    Jun 5 '17 at 22:41

















                                                                  up vote
                                                                  0
                                                                  down vote













                                                                  bandit4@bandit:~$ ls
                                                                  inhere

                                                                  bandit4@bandit:~$ file inhere/*


                                                                  inhere/-file00: data
                                                                  inhere/-file01: data
                                                                  inhere/-file02: data
                                                                  inhere/-file03: data
                                                                  inhere/-file04: data
                                                                  inhere/-file05: data
                                                                  inhere/-file06: data
                                                                  inhere/-file07: ASCII text
                                                                  inhere/-file08: data
                                                                  inhere/-file09: data

                                                                  bandit4@bandit:~$ pwd

                                                                  /home/bandit4

                                                                  bandit4@bandit:~$ cat /home/bandit4/inhere/-file07

                                                                  koReBOKuIDDepwhWk7jZC0RTdopnAYKh
                                                                  bandit4@bandit:~$





                                                                  share|improve this answer























                                                                  • Simply use file inhere/* and cat /home/bandit4/inhere/-file07
                                                                    – user234732
                                                                    Jun 5 '17 at 22:41















                                                                  up vote
                                                                  0
                                                                  down vote










                                                                  up vote
                                                                  0
                                                                  down vote









                                                                  bandit4@bandit:~$ ls
                                                                  inhere

                                                                  bandit4@bandit:~$ file inhere/*


                                                                  inhere/-file00: data
                                                                  inhere/-file01: data
                                                                  inhere/-file02: data
                                                                  inhere/-file03: data
                                                                  inhere/-file04: data
                                                                  inhere/-file05: data
                                                                  inhere/-file06: data
                                                                  inhere/-file07: ASCII text
                                                                  inhere/-file08: data
                                                                  inhere/-file09: data

                                                                  bandit4@bandit:~$ pwd

                                                                  /home/bandit4

                                                                  bandit4@bandit:~$ cat /home/bandit4/inhere/-file07

                                                                  koReBOKuIDDepwhWk7jZC0RTdopnAYKh
                                                                  bandit4@bandit:~$





                                                                  share|improve this answer














                                                                  bandit4@bandit:~$ ls
                                                                  inhere

                                                                  bandit4@bandit:~$ file inhere/*


                                                                  inhere/-file00: data
                                                                  inhere/-file01: data
                                                                  inhere/-file02: data
                                                                  inhere/-file03: data
                                                                  inhere/-file04: data
                                                                  inhere/-file05: data
                                                                  inhere/-file06: data
                                                                  inhere/-file07: ASCII text
                                                                  inhere/-file08: data
                                                                  inhere/-file09: data

                                                                  bandit4@bandit:~$ pwd

                                                                  /home/bandit4

                                                                  bandit4@bandit:~$ cat /home/bandit4/inhere/-file07

                                                                  koReBOKuIDDepwhWk7jZC0RTdopnAYKh
                                                                  bandit4@bandit:~$






                                                                  share|improve this answer














                                                                  share|improve this answer



                                                                  share|improve this answer








                                                                  edited Aug 2 at 16:00









                                                                  Jesse_b

                                                                  11.5k23063




                                                                  11.5k23063










                                                                  answered Jun 5 '17 at 22:38







                                                                  user234732



















                                                                  • Simply use file inhere/* and cat /home/bandit4/inhere/-file07
                                                                    – user234732
                                                                    Jun 5 '17 at 22:41




















                                                                  • Simply use file inhere/* and cat /home/bandit4/inhere/-file07
                                                                    – user234732
                                                                    Jun 5 '17 at 22:41


















                                                                  Simply use file inhere/* and cat /home/bandit4/inhere/-file07
                                                                  – user234732
                                                                  Jun 5 '17 at 22:41






                                                                  Simply use file inhere/* and cat /home/bandit4/inhere/-file07
                                                                  – user234732
                                                                  Jun 5 '17 at 22:41












                                                                  up vote
                                                                  0
                                                                  down vote













                                                                  find  -type f ! -executable -size 1033c


                                                                  will get you the file from the exercise






                                                                  share|improve this answer

























                                                                    up vote
                                                                    0
                                                                    down vote













                                                                    find  -type f ! -executable -size 1033c


                                                                    will get you the file from the exercise






                                                                    share|improve this answer























                                                                      up vote
                                                                      0
                                                                      down vote










                                                                      up vote
                                                                      0
                                                                      down vote









                                                                      find  -type f ! -executable -size 1033c


                                                                      will get you the file from the exercise






                                                                      share|improve this answer












                                                                      find  -type f ! -executable -size 1033c


                                                                      will get you the file from the exercise







                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered Sep 29 at 12:42









                                                                      coolhand

                                                                      1092




                                                                      1092






















                                                                          up vote
                                                                          -1
                                                                          down vote













                                                                          du --human-readable | find -not -executable -size 1033c


                                                                          will get your result






                                                                          share|improve this answer










                                                                          New contributor




                                                                          Varun Rathore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                          Check out our Code of Conduct.






















                                                                            up vote
                                                                            -1
                                                                            down vote













                                                                            du --human-readable | find -not -executable -size 1033c


                                                                            will get your result






                                                                            share|improve this answer










                                                                            New contributor




                                                                            Varun Rathore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                            Check out our Code of Conduct.




















                                                                              up vote
                                                                              -1
                                                                              down vote










                                                                              up vote
                                                                              -1
                                                                              down vote









                                                                              du --human-readable | find -not -executable -size 1033c


                                                                              will get your result






                                                                              share|improve this answer










                                                                              New contributor




                                                                              Varun Rathore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.









                                                                              du --human-readable | find -not -executable -size 1033c


                                                                              will get your result







                                                                              share|improve this answer










                                                                              New contributor




                                                                              Varun Rathore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.









                                                                              share|improve this answer



                                                                              share|improve this answer








                                                                              edited 16 hours ago





















                                                                              New contributor




                                                                              Varun Rathore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.









                                                                              answered 16 hours ago









                                                                              Varun Rathore

                                                                              11




                                                                              11




                                                                              New contributor




                                                                              Varun Rathore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.





                                                                              New contributor





                                                                              Varun Rathore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.






                                                                              Varun Rathore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.






























                                                                                  draft saved

                                                                                  draft discarded




















































                                                                                  Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                                                                  • Please be sure to answer the question. Provide details and share your research!

                                                                                  But avoid



                                                                                  • Asking for help, clarification, or responding to other answers.

                                                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                                                  To learn more, see our tips on writing great answers.





                                                                                  Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                                                  Please pay close attention to the following guidance:


                                                                                  • Please be sure to answer the question. Provide details and share your research!

                                                                                  But avoid



                                                                                  • Asking for help, clarification, or responding to other answers.

                                                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                                                  To learn more, see our tips on writing great answers.




                                                                                  draft saved


                                                                                  draft discarded














                                                                                  StackExchange.ready(
                                                                                  function () {
                                                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f313442%2ffind-human-readable-files%23new-answer', 'question_page');
                                                                                  }
                                                                                  );

                                                                                  Post as a guest















                                                                                  Required, but never shown





















































                                                                                  Required, but never shown














                                                                                  Required, but never shown












                                                                                  Required, but never shown







                                                                                  Required, but never shown

































                                                                                  Required, but never shown














                                                                                  Required, but never shown












                                                                                  Required, but never shown







                                                                                  Required, but never shown







                                                                                  Popular posts from this blog

                                                                                  Accessing regular linux commands in Huawei's Dopra Linux

                                                                                  Can't connect RFCOMM socket: Host is down

                                                                                  Kernel panic - not syncing: Fatal Exception in Interrupt