What is wrong with my use of “find -print0”? [closed]
Clash Royale CLAN TAG#URR8PPP
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
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
|
show 5 more comments
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
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
14
You made a directory called literallyfoon
, 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 anls
you would have seen that.
– Bakuriu
Feb 23 at 10:32
@Bakuriu, no becausels
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
|
show 5 more comments
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
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
find filenames
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
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
14
You made a directory called literallyfoon
, 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 anls
you would have seen that.
– Bakuriu
Feb 23 at 10:32
@Bakuriu, no becausels
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
|
show 5 more comments
14
You made a directory called literallyfoon
, 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 anls
you would have seen that.
– Bakuriu
Feb 23 at 10:32
@Bakuriu, no becausels
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
|
show 5 more comments
2 Answers
2
active
oldest
votes
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.
add a comment |
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
1
I appreciate showing the verification part!
– pabouk
Feb 23 at 21:58
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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.
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.
edited Feb 23 at 6:44
answered Feb 23 at 6:38
filbrandenfilbranden
10.6k21646
10.6k21646
add a comment |
add a comment |
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
1
I appreciate showing the verification part!
– pabouk
Feb 23 at 21:58
add a comment |
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
1
I appreciate showing the verification part!
– pabouk
Feb 23 at 21:58
add a comment |
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
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
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
add a comment |
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
add a comment |
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