Вы хотите что-то вроде этого?
#!/usr/bin/env bash
## This is the target path, the directory
## you want to copy to.
target="some/path with/spaces";
## Find all files and folders in the current directory, sort
## them reverse alphabetically and iterate through them
find . -maxdepth 1 -type f | sort -r | while IFS= read -r file; do
## Set the counter back to 0 for each file
counter=0;
## The counter will be 0 until the file is moved
while [ $counter -eq 0 ]; do
## If the directory has no files
if find "$target" -maxdepth 0 -empty | read;
then
## Move the current file to $target and increment
## the counter.
mv -v "$file" "$target" && counter=1;
else
## Uncomment the line below for debugging
# echo "Directory not empty: $(find "$target" -mindepth 1)"
## Wait for one second. This avoids spamming
## the system with multiple requests.
sleep 1;
fi;
done;
done
Этот сценарий будет работать, пока все файлы не были скопированы. Это только скопирует файл в $target
если цель пуста, таким образом, она зависнет навсегда, если другой процесс не удалит файлы, поскольку они входят.
Это повредится если Ваши файлы или $target
имя содержит новые строки (\n
) но должен согласиться с пробелами и другими странными символами.
Предположим, ваша временная метка находится в переменной timestamp
и в миллисекундах с начала эпохи:
fiveminutesbefore=$((timestamp - 5 * 60 * 1000))
Здесь используется арифметическое расширение для вычитания 5 лотов из 60 (секунд в минуту) много 1000 (миллисекунд в секунду) от вашего значения timestamp
, что дает время на пять минут раньше, чем вы ожидали.
5 минут по 60 секунд по 1000 миллисекунд каждая дает 300000.
Вы можете вычесть это из переменной, которая содержит текущую дату в миллисекундах, используя $ (())
:
dd=$(($(date +'%s * 1000 + %-N / 1000000')))
ddmin5=$(($dd - 300000))
echo $ddmin5
Расчет миллисекунд происходит из этого ответа
Слишком много способов:
fiveminutesbefore=$[$timestamp - 5 * 60 * 1000]
или
fiveminutesbefore=`echo "$timestamp - 5 * 60 * 1000" | bc -l`
или
fiveminutesbefore=`echo "$timestamp" | python -c 'import sys; t=sys.stdin.read(); print int(t) - 5 * 60 * 1000'`
и т.д....
print solaris sun os minus 10min
dt="$(date +%H:"$(( `date +%M`-10))":%S)"
Использование GNU awk для функции strftime ()и переменной FIELDWIDTHS.
$ awk -v FIELDWIDTHS='10 3' '{ print strftime("%s" $2, $1-5*60) }' <<<'1623660409789'
1623660109789