trying to find joy with the find command
You all are having so much fun with the find command, so I'll post some more questions. Basically, the challenge is to process any file name unix allows in bash when using the find filter. Is this possible? How hard is it. Almost seems that I need to look at the filename and write different code depending on what the file name is.
What I'm I missing?
#!/bin/bash
echo "in bash script $0"
ls -l '/Users/mac/exifinner/'
fileCount=$(ls -l '/Users/mac/exifinner/' | wc -l)
let fileCount--
echo "${fileCount} files found."
count=1
echo "starting finding files"
# Hexadecimal: numbers preceded by '0x' or '0X'
#let "hex = 0x00"
#IFS=${hex}
echo "xargs"
echo "I'm not sure how to use this command"
echo "I loose the flow because all the files are glommed together."
find '/Users/mac/exifinner/' -print0 -type f \( -iname "*.txt" \) | xargs -0 echo
echo "print0"
echo "0x00 isn't being inserted"
echo "notice how the path to the first file appears twice. brilliant. "
echo "bash variables cannot contain 0x00? Nothing like rubbish C strings."
theFiles=$(find '/Users/mac/exifinner/' -print0 -type f \( -iname "*.txt" \) )
echo $theFiles | hexdump -C
echo "print"
echo "separator seems to be a blank"
theFiles=$(find '/Users/mac/exifinner/' -print -type f \( -iname "*.txt" \) )
echo $theFiles | hexdump -C
echo "default"
echo "default seems to be to put in a blank. Why is thi done?"
echo "I find magic annoying. Why not just put in the lf? I could parse it out"
theFiles=$(find '/Users/mac/exifinner/' -type f \( -iname "*.txt" \) )
echo $theFiles | hexdump -C
echo "to terminal"
echo "How do I get terminal output to a string?"
echo "a lf is being inserted. Guess I could write out to a file. Seems to be a PITA."
echo "And I thought Unix was supposed to be consistent?"
find '/Users/mac/exifinner/' -type f \( -iname "*.txt" \)
echo "read loop"
echo " so my first file is \"\\ \\&.txt\", but where are the two backslashes?"
find '/Users/mac/exifinner/' -type f \( -iname "*.txt" \) | (
while read theFilePath
do
echo -n " ${count}: "
echo "processing file " ${theFilePath}
echo " file ${theFilePath}"
echo ${theFilePath} | hexdump -C
let count++
done
)
echo "leaving $0"
exit 0
Here are some test cases.
mac $ ~/config/groupReadFind#5.sh
in bash script /Users/mac/config/groupReadFind#5.sh
total 0
-rw-r--r-- 1 mac staff 0 Mar 1 19:13 \ \&.txt
-rw-r--r-- 1 mac staff 0 Mar 1 19:12 normal.txt
2 files found.
starting finding files
xargs
I'm not sure how to use this command
I loose the flow because all the files are glommed together.
/Users/mac/exifinner/ /Users/mac/exifinner//\ \&.txt /Users/mac/exifinner//normal.txt
print0
0x00 isn't being inserted
notice how the path to the first file appears twice. brilliant.
bash variables cannot contain 0x00? Nothing like rubbish C strings.
00000000 2f 55 73 65 72 73 2f 6d 61 63 2f 65 78 69 66 69 |/Users/mac/exifi|
00000010 6e 6e 65 72 2f 2f 55 73 65 72 73 2f 6d 61 63 2f |nner//Users/mac/|
00000020 65 78 69 66 69 6e 6e 65 72 2f 2f 5c 20 5c 26 2e |exifinner//\ \&.|
00000030 74 78 74 2f 55 73 65 72 73 2f 6d 61 63 2f 65 78 |txt/Users/mac/ex|
00000040 69 66 69 6e 6e 65 72 2f 2f 6e 6f 72 6d 61 6c 2e |ifinner//normal.|
00000050 74 78 74 0a |txt.|
00000054
print
separator seems to be a blank
00000000 2f 55 73 65 72 73 2f 6d 61 63 2f 65 78 69 66 69 |/Users/mac/exifi|
00000010 6e 6e 65 72 2f 20 2f 55 73 65 72 73 2f 6d 61 63 |nner/ /Users/mac|
00000020 2f 65 78 69 66 69 6e 6e 65 72 2f 2f 5c 20 5c 26 |/exifinner//\ \&|
00000030 2e 74 78 74 20 2f 55 73 65 72 73 2f 6d 61 63 2f |.txt /Users/mac/|
00000040 65 78 69 66 69 6e 6e 65 72 2f 2f 6e 6f 72 6d 61 |exifinner//norma|
00000050 6c 2e 74 78 74 0a |l.txt.|
00000056
default
default seems to be to put in a blank. Why is thi done?
I find magic annoying. Why not just put in the lf? I could parse it out
00000000 2f 55 73 65 72 73 2f 6d 61 63 2f 65 78 69 66 69 |/Users/mac/exifi|
00000010 6e 6e 65 72 2f 2f 5c 20 5c 26 2e 74 78 74 20 2f |nner//\ \&.txt /|
00000020 55 73 65 72 73 2f 6d 61 63 2f 65 78 69 66 69 6e |Users/mac/exifin|
00000030 6e 65 72 2f 2f 6e 6f 72 6d 61 6c 2e 74 78 74 0a |ner//normal.txt.|
00000040
to terminal
How do I get terminal output to a string?
a lf is being inserted. Guess I could write out to a file. Seems to be a PITA.
And I thought Unix was supposed to be consistent?
/Users/mac/exifinner//\ \&.txt
/Users/mac/exifinner//normal.txt
read loop
so my first file is "\ \&.txt", but where are the two backslashes?
1: processing file /Users/mac/exifinner// &.txt
file /Users/mac/exifinner// &.txt
00000000 2f 55 73 65 72 73 2f 6d 61 63 2f 65 78 69 66 69 |/Users/mac/exifi|
00000010 6e 6e 65 72 2f 2f 20 26 2e 74 78 74 0a |nner// &.txt.|
0000001d
2: processing file /Users/mac/exifinner//normal.txt
file /Users/mac/exifinner//normal.txt
00000000 2f 55 73 65 72 73 2f 6d 61 63 2f 65 78 69 66 69 |/Users/mac/exifi|
00000010 6e 6e 65 72 2f 2f 6e 6f 72 6d 61 6c 2e 74 78 74 |nner//normal.txt|
00000020 0a |.|
00000021
leaving /Users/mac/config/groupReadFind#5.sh
mac $
Mac mini, OS X Yosemite (10.10.5), Fall 2014; iPhone 4 7.1.2