гm currently working on в рукописный шрифт that allows я to move any file thats older than 5 days into an сохранил в архиве folder with the same path, except for the root folder which changes. So something like: root/subdir1/subdir2/file
to rootarchive/subdir1/subdir2/file
. It should work recursivly.
гve already tried creating в foreach for all the поля of the "root" folder:
#!/bin/bash
find . -type f -name '*.*' -print0 | while IFS= read -r -d '' file; do
mv $file ../rootarchive/"$file"
done
But this didn't work properly схвати I the mv command couldnt find the specified destination ../rootarchive/"$file"
. Идея - anyone of you an how I could solve this problem?
Вы должны создать дерево каталогов от subdir1/subdir2/
- mv
, не сделает этого для Вас. Вы могли сделать, например:
find . -type f -mtime +5 -print0 | while IFS= read -r -d '' file; do
dir="${file%/*}"
mkdir -p ../rootarchive/"$dir"
mv "$file" ../rootarchive/"$file"
done
<час> Вы могли rsync
. Это может воссоздать структуру каталогов и сделать удаление скопировало файлы:
find . -type f -mtime +5 -print0 |
rsync -0avP --remove-source-files --files-from=- ./ ../rootarchive
Для rsync
:
-0
указывает, что списки файла отделены от пустого указателя. Это затрагивает: --files-from=
читает список файлов, которые будут скопированы (от stdin: -
). -a
позволяет способ архива, который сохраняет разрешения файла, собственность, и т.д. --remove-source-files
удаляет файлы, которые были скопированы успешно из источника. -vP
позволяют многословный способ и информацию о прогрессе.