I want to get list of files in current directory and its sub-directories (I want to use one-liner script):
IFS=$(echo -en "\n\b");
for FILE in $(find -type f); do echo "$FILE"; done
Usually, it works as expected, but recently, with my list of files:
file_.doc
file_0.doc
file_[2006_02_25].doc
file_[2016_06_16].odt
file_[2016_06_16].pdf
file_[16-6-2006].doc
file_.pdf
file_ 4-4-2006.doc
the output is:
./file_.doc
./file_0.doc
./file_0.doc
./file_[2016_06_16].odt
./file_[2016_06_16].pdf
./file_0.doc
./file_.pdf
./file_ 4-4-2006.doc
If I change the variable IFS to:
IFS=$(echo -en "\n");
then the output will be (corrected):
./file_.doc
./file_0.doc
./file_[2006_02_25].doc
./file_[2016_06_16].odt
./file_[2016_06_16].pdf
./file_[16-6-2006].doc
./file_.pdf
./file_ 4-4-2006.doc
I have read that '\b'
is neccesary, and found a solution that using printf
, instead of echo
.
My questions are:
1) Could you explain what made those outputs different?
2) A solution using printf
above could be an alternative to echo -en "\n\b"
?
-exec
to execute the needed code on each file, or group of files. I wasn't able to write anything more specific about this, because the question is not about how to do that but about why you get different results with your code. – Kusalananda Feb 28 '18 at 08:50