What is wrong with my use of “find -print0”? [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












7















I'm confused by this experiment (in Bash):



$ mkdir 'foon'
$ find . -print0 | od -c
0000000 . . / f o o n
0000012


As you can see, "find" is correctly delimiting the output with null characters, but it escapes the newline in the directory name as "foon" with a backslash "n". Why is it doing this? I told it "-print0" which says "This allows file names that contain newlines ... to be correctly interpreted by programs that process the find output." The escaping should not be necessary, since "" is the delimiter, not "n".










share|improve this question















closed as off-topic by Michael Homer, mosvy, Jesse_b, Archemar, jimmij Feb 25 at 13:39


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Michael Homer, mosvy, Jesse_b, Archemar, jimmij
If this question can be reworded to fit the rules in the help center, please edit the question.











  • 14





    You made a directory called literally foon, with a backslash in its name.

    – Michael Homer
    Feb 23 at 6:36







  • 7





    Soo ... embarrassing .... but learned something from the answers, thank you all.

    – Metamorphic
    Feb 23 at 6:50











  • If you did an ls you would have seen that.

    – Bakuriu
    Feb 23 at 10:32











  • @Bakuriu, no because ls prints exactly what I passed to mkdir, 'foon'...

    – Metamorphic
    Feb 23 at 10:42











  • There is no Neulinge in your filename, ‚n‘ is a literal 2 char string

    – eckes
    Feb 23 at 15:42















7















I'm confused by this experiment (in Bash):



$ mkdir 'foon'
$ find . -print0 | od -c
0000000 . . / f o o n
0000012


As you can see, "find" is correctly delimiting the output with null characters, but it escapes the newline in the directory name as "foon" with a backslash "n". Why is it doing this? I told it "-print0" which says "This allows file names that contain newlines ... to be correctly interpreted by programs that process the find output." The escaping should not be necessary, since "" is the delimiter, not "n".










share|improve this question















closed as off-topic by Michael Homer, mosvy, Jesse_b, Archemar, jimmij Feb 25 at 13:39


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Michael Homer, mosvy, Jesse_b, Archemar, jimmij
If this question can be reworded to fit the rules in the help center, please edit the question.











  • 14





    You made a directory called literally foon, with a backslash in its name.

    – Michael Homer
    Feb 23 at 6:36







  • 7





    Soo ... embarrassing .... but learned something from the answers, thank you all.

    – Metamorphic
    Feb 23 at 6:50











  • If you did an ls you would have seen that.

    – Bakuriu
    Feb 23 at 10:32











  • @Bakuriu, no because ls prints exactly what I passed to mkdir, 'foon'...

    – Metamorphic
    Feb 23 at 10:42











  • There is no Neulinge in your filename, ‚n‘ is a literal 2 char string

    – eckes
    Feb 23 at 15:42













7












7








7








I'm confused by this experiment (in Bash):



$ mkdir 'foon'
$ find . -print0 | od -c
0000000 . . / f o o n
0000012


As you can see, "find" is correctly delimiting the output with null characters, but it escapes the newline in the directory name as "foon" with a backslash "n". Why is it doing this? I told it "-print0" which says "This allows file names that contain newlines ... to be correctly interpreted by programs that process the find output." The escaping should not be necessary, since "" is the delimiter, not "n".










share|improve this question
















I'm confused by this experiment (in Bash):



$ mkdir 'foon'
$ find . -print0 | od -c
0000000 . . / f o o n
0000012


As you can see, "find" is correctly delimiting the output with null characters, but it escapes the newline in the directory name as "foon" with a backslash "n". Why is it doing this? I told it "-print0" which says "This allows file names that contain newlines ... to be correctly interpreted by programs that process the find output." The escaping should not be necessary, since "" is the delimiter, not "n".







find filenames






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 23 at 9:46









Kusalananda

136k17257426




136k17257426










asked Feb 23 at 6:30









MetamorphicMetamorphic

366111




366111




closed as off-topic by Michael Homer, mosvy, Jesse_b, Archemar, jimmij Feb 25 at 13:39


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Michael Homer, mosvy, Jesse_b, Archemar, jimmij
If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by Michael Homer, mosvy, Jesse_b, Archemar, jimmij Feb 25 at 13:39


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Michael Homer, mosvy, Jesse_b, Archemar, jimmij
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 14





    You made a directory called literally foon, with a backslash in its name.

    – Michael Homer
    Feb 23 at 6:36







  • 7





    Soo ... embarrassing .... but learned something from the answers, thank you all.

    – Metamorphic
    Feb 23 at 6:50











  • If you did an ls you would have seen that.

    – Bakuriu
    Feb 23 at 10:32











  • @Bakuriu, no because ls prints exactly what I passed to mkdir, 'foon'...

    – Metamorphic
    Feb 23 at 10:42











  • There is no Neulinge in your filename, ‚n‘ is a literal 2 char string

    – eckes
    Feb 23 at 15:42












  • 14





    You made a directory called literally foon, with a backslash in its name.

    – Michael Homer
    Feb 23 at 6:36







  • 7





    Soo ... embarrassing .... but learned something from the answers, thank you all.

    – Metamorphic
    Feb 23 at 6:50











  • If you did an ls you would have seen that.

    – Bakuriu
    Feb 23 at 10:32











  • @Bakuriu, no because ls prints exactly what I passed to mkdir, 'foon'...

    – Metamorphic
    Feb 23 at 10:42











  • There is no Neulinge in your filename, ‚n‘ is a literal 2 char string

    – eckes
    Feb 23 at 15:42







14




14





You made a directory called literally foon, with a backslash in its name.

– Michael Homer
Feb 23 at 6:36






You made a directory called literally foon, with a backslash in its name.

– Michael Homer
Feb 23 at 6:36





7




7





Soo ... embarrassing .... but learned something from the answers, thank you all.

– Metamorphic
Feb 23 at 6:50





Soo ... embarrassing .... but learned something from the answers, thank you all.

– Metamorphic
Feb 23 at 6:50













If you did an ls you would have seen that.

– Bakuriu
Feb 23 at 10:32





If you did an ls you would have seen that.

– Bakuriu
Feb 23 at 10:32













@Bakuriu, no because ls prints exactly what I passed to mkdir, 'foon'...

– Metamorphic
Feb 23 at 10:42





@Bakuriu, no because ls prints exactly what I passed to mkdir, 'foon'...

– Metamorphic
Feb 23 at 10:42













There is no Neulinge in your filename, ‚n‘ is a literal 2 char string

– eckes
Feb 23 at 15:42





There is no Neulinge in your filename, ‚n‘ is a literal 2 char string

– eckes
Feb 23 at 15:42










2 Answers
2






active

oldest

votes


















20














The problem is not in find, but in how you're creating this directory. The single quoted string 'foon' is actually a 5-character string, of which the last two are a backslash and a lowercase "n".



Double-quoting it doesn't help either, since double-quoted strings in shell use backslash as an escape character, but don't really interpret any of the C-style backslash sequences.



In a shell such as bash or zsh, etc. (but not dash from Debian/Ubuntu), you can use $'...', which interprets those sequences:



$ mkdir $'foon'


(See bash's documentation for this feature, called "ANSI C Quoting").



Another option, that should work in any shell compatible with bourne shell is to insert an actual newline:



$ mkdir 'foo
'


That's an actual Return at the end of the first line, only closing the single quote on the second line.






share|improve this answer
































    6














    Let's make a directory named foo plus a newline:



    $ mkdir $'foon'


    Now, let's use find:



    $ find . -print0 | od -c
    0000000 . . / f o o n
    0000011


    n is not escaped.



    The issue is that mkdir 'foon' is the name is interpreted as foo followed by followed by n. We can verify that with:



    $ printf '%s' 'foon' | od -c
    0000000 f o o n
    0000005





    share|improve this answer




















    • 1





      I appreciate showing the verification part!

      – pabouk
      Feb 23 at 21:58

















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    20














    The problem is not in find, but in how you're creating this directory. The single quoted string 'foon' is actually a 5-character string, of which the last two are a backslash and a lowercase "n".



    Double-quoting it doesn't help either, since double-quoted strings in shell use backslash as an escape character, but don't really interpret any of the C-style backslash sequences.



    In a shell such as bash or zsh, etc. (but not dash from Debian/Ubuntu), you can use $'...', which interprets those sequences:



    $ mkdir $'foon'


    (See bash's documentation for this feature, called "ANSI C Quoting").



    Another option, that should work in any shell compatible with bourne shell is to insert an actual newline:



    $ mkdir 'foo
    '


    That's an actual Return at the end of the first line, only closing the single quote on the second line.






    share|improve this answer





























      20














      The problem is not in find, but in how you're creating this directory. The single quoted string 'foon' is actually a 5-character string, of which the last two are a backslash and a lowercase "n".



      Double-quoting it doesn't help either, since double-quoted strings in shell use backslash as an escape character, but don't really interpret any of the C-style backslash sequences.



      In a shell such as bash or zsh, etc. (but not dash from Debian/Ubuntu), you can use $'...', which interprets those sequences:



      $ mkdir $'foon'


      (See bash's documentation for this feature, called "ANSI C Quoting").



      Another option, that should work in any shell compatible with bourne shell is to insert an actual newline:



      $ mkdir 'foo
      '


      That's an actual Return at the end of the first line, only closing the single quote on the second line.






      share|improve this answer



























        20












        20








        20







        The problem is not in find, but in how you're creating this directory. The single quoted string 'foon' is actually a 5-character string, of which the last two are a backslash and a lowercase "n".



        Double-quoting it doesn't help either, since double-quoted strings in shell use backslash as an escape character, but don't really interpret any of the C-style backslash sequences.



        In a shell such as bash or zsh, etc. (but not dash from Debian/Ubuntu), you can use $'...', which interprets those sequences:



        $ mkdir $'foon'


        (See bash's documentation for this feature, called "ANSI C Quoting").



        Another option, that should work in any shell compatible with bourne shell is to insert an actual newline:



        $ mkdir 'foo
        '


        That's an actual Return at the end of the first line, only closing the single quote on the second line.






        share|improve this answer















        The problem is not in find, but in how you're creating this directory. The single quoted string 'foon' is actually a 5-character string, of which the last two are a backslash and a lowercase "n".



        Double-quoting it doesn't help either, since double-quoted strings in shell use backslash as an escape character, but don't really interpret any of the C-style backslash sequences.



        In a shell such as bash or zsh, etc. (but not dash from Debian/Ubuntu), you can use $'...', which interprets those sequences:



        $ mkdir $'foon'


        (See bash's documentation for this feature, called "ANSI C Quoting").



        Another option, that should work in any shell compatible with bourne shell is to insert an actual newline:



        $ mkdir 'foo
        '


        That's an actual Return at the end of the first line, only closing the single quote on the second line.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 23 at 6:44

























        answered Feb 23 at 6:38









        filbrandenfilbranden

        10.6k21646




        10.6k21646























            6














            Let's make a directory named foo plus a newline:



            $ mkdir $'foon'


            Now, let's use find:



            $ find . -print0 | od -c
            0000000 . . / f o o n
            0000011


            n is not escaped.



            The issue is that mkdir 'foon' is the name is interpreted as foo followed by followed by n. We can verify that with:



            $ printf '%s' 'foon' | od -c
            0000000 f o o n
            0000005





            share|improve this answer




















            • 1





              I appreciate showing the verification part!

              – pabouk
              Feb 23 at 21:58















            6














            Let's make a directory named foo plus a newline:



            $ mkdir $'foon'


            Now, let's use find:



            $ find . -print0 | od -c
            0000000 . . / f o o n
            0000011


            n is not escaped.



            The issue is that mkdir 'foon' is the name is interpreted as foo followed by followed by n. We can verify that with:



            $ printf '%s' 'foon' | od -c
            0000000 f o o n
            0000005





            share|improve this answer




















            • 1





              I appreciate showing the verification part!

              – pabouk
              Feb 23 at 21:58













            6












            6








            6







            Let's make a directory named foo plus a newline:



            $ mkdir $'foon'


            Now, let's use find:



            $ find . -print0 | od -c
            0000000 . . / f o o n
            0000011


            n is not escaped.



            The issue is that mkdir 'foon' is the name is interpreted as foo followed by followed by n. We can verify that with:



            $ printf '%s' 'foon' | od -c
            0000000 f o o n
            0000005





            share|improve this answer















            Let's make a directory named foo plus a newline:



            $ mkdir $'foon'


            Now, let's use find:



            $ find . -print0 | od -c
            0000000 . . / f o o n
            0000011


            n is not escaped.



            The issue is that mkdir 'foon' is the name is interpreted as foo followed by followed by n. We can verify that with:



            $ printf '%s' 'foon' | od -c
            0000000 f o o n
            0000005






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Feb 23 at 6:44

























            answered Feb 23 at 6:39









            John1024John1024

            47.7k5112126




            47.7k5112126







            • 1





              I appreciate showing the verification part!

              – pabouk
              Feb 23 at 21:58












            • 1





              I appreciate showing the verification part!

              – pabouk
              Feb 23 at 21:58







            1




            1





            I appreciate showing the verification part!

            – pabouk
            Feb 23 at 21:58





            I appreciate showing the verification part!

            – pabouk
            Feb 23 at 21:58


            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay