I created a script to list all the files in the directory and below it. I wanted to add some feedback for progression using pv, because I usually use it from the root directory.
The problem is a search that always includes fractional seconds in its time output (% TT), but I don't want to write down so many details.
If I write a script to do everything in one pass, I get the correct output. But if I use intermediate files for evaluation during the "second" pass, the result is changed and I do not understand why.
This version gives the correct result:
#!/bin/bash
find -printf "%11s %TY-%Tm-%Td %TT %p\n" 2> /dev/null |
colrm 32 42 |
pv -ltrbN "Enumerating files..." |
sort -k 4
But sorting can take a lot of time, so I tried something like this to have a bit more feedback:
#!/bin/bash
TMPFILE1=$(mktemp)
TMPFILE2=$(mktemp)
trap "rm $TMPFILE1 $TMPFILE2" EXIT
find -printf "%11s %TY-%Tm-%Td %TT %p\n" 2> /dev/null |
pv -ltrbN "Enumerating files..." > $TMPFILE1
LINE_COUNT="$(wc -l $TMPFILE1)"
awk -F".0000000000" '{print $1 $2}' $TMPFILE1 |
pv -lN "Removing fractional seconds..." -s $LINE_COUNT > $TMPFILE2
echo "Sorting list by filenames..." >&2
cat $TMPFILE2 |
sort -k 4
5 "" . ".0000000000" .
- , ?
. .