bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strange behaviour of -fprintf in find?


From: Thomas Otterbein
Subject: Strange behaviour of -fprintf in find?
Date: Sun, 16 May 2004 20:05:26 -0500
User-agent: KMail/1.5.4

Hi,

this is the first time a send something to this list, so I'm not sure whether 
this is the right place and the right way how to do it. Let me know.

I tried to write some scripts sorting out ownership and attributes of files. 
Hereby I found some unexpected behaviour of -fprintf in the find command. I'm 
not sure whether I understood something wrong or this is really a bug, so any 
type of hint is welcome. In principle it looks like, that "-fprintf" and 
"-fprint0" and "-fls" do not work correctly.

Here is the test case to show it, including comments about the strange 
behaviour. The user doing this is root.

klavier:/abc # ls /abc
.  ..  aa1  aa2  aa3  ab1  ab2  ab3  ac1  ac2  ac3
# So these nine files are in this directory

klavier:/abc # find /abc -name 'a*' -print0 > /tmp/AllFileNames
# This finds all files starting with "a" in directory /abc and stores the name
# in temporary file /tmp/AllFileNames with a 0x00 as separator.

klavier:/abc # ll /tmp/AllFileNames
-rw-r--r--    1 root     root           86 May 16 19:40 /tmp/AllFileNames
klavier:/abc # cat /tmp/AllFileNames
/abc/abc/aa1/abc/aa2/abc/aa3/abc/ab1/abc/ab2/abc/ab3/abc/ac1/abc/ac2/abc/ac3
# Yes, there is the file, and it has all the nine file names. It looks 
strange, because cat does not but a blank for the 0x00 separators.

klavier:/abc # xargs -0 -i -r < /tmp/AllFileNames find '{}' -type d -prune -o 
-name 'aa*' -fprintf /tmp/FirstSet '%m %p \n' -print0 | xargs -0 -r echo
/abc/aa1 /abc/aa2 /abc/aa3
# OK, we got the three filenames 'aa*' as expected. The part "-type d prune"
# is to avoid searching in the directory itself, because we only want to look
# at the specific files. But what about the generated file?

klavier:/abc # ll /tmp/FirstSet
-rw-r--r--    1 root     root            0 May 16 19:47 /tmp/FirstSet
klavier:/abc # cat /tmp/FirstSet
# The file is empty, instead of having in every line the access mode bits and 
the file names of the three files!!! So let's look at some variations. First 
of all put away all that piping

klavier:/abc # xargs -0 -i -r < /tmp/AllFileNames find '{}' -type d -prune -o 
-name 'aa*' -fprintf /tmp/FirstSet '%m %p \n'
klavier:/abc # ll /tmp/FirstSet
-rw-r--r--    1 root     root            0 May 16 19:54 /tmp/FirstSet
klavier:/abc # cat /tmp/FirstSet
# Still, the file is empty instead of having the lines.
# Let's look, whether it prints the names correct to stdout

klavier:/abc # xargs -0 -i -r < /tmp/AllFileNames find '{}' -type d -prune -o 
-name 'aa*' -printf '%m %p \n'
644 /abc/aa1
644 /abc/aa2
644 /abc/aa3
# Looks good, here we have the lines being expected. So what would happen if
# we just print it to a file, without formatting? Looks like, that "-printf"
# works, while "-fprintf" fails.

klavier:/abc # xargs -0 -i -r < /tmp/AllFileNames find '{}' -type d -prune -o 
-name 'aa*' -fprint /tmp/FirstSet
klavier:/abc # ll /tmp/FirstSet
-rw-r--r--    1 root     root            0 May 16 19:57 /tmp/FirstSet
klavier:/abc # cat /tmp/FirstSet
# So again, no output to the file. The -print version works:

klavier:/abc # xargs -0 -i -r < /tmp/AllFileNames find '{}' -type d -prune -o 
-name 'aa*' -print
/abc/aa1
/abc/aa2
/abc/aa3
# So again, fprint does not work, but print works

I also tried "-ls" and "-fls". "-ls" works as expected, "-fls" does not. Has 
anybody seen something like this before?

Best regards

Thomas
-- 
Thomas Otterbein                address@hidden
4608 Portrait Lane              Plano, Tx, 75024
USA                             Tel.: +1 972 618 0555





reply via email to

[Prev in Thread] Current Thread [Next in Thread]