我有一个巨大的电影文件目录结构。为了分析这种结构,我想复制整个目录结构,即文件夹和文件,但是我不想复制所有的电影文件,而我想保留它们的文件名。理想情况下,我得到的是带有原始电影文件名的零字节文件。
我尝试然后rsync到我的远程机器,它没有获取链接文件。
有什么想法可以在不写脚本的情况下做到这一点吗?
发布于 2012-08-14 20:46:30
您可以使用find:
find src/ -type d -exec mkdir -p dest/{} \; \
-o -type f -exec touch dest/{} \;在(src/)下找到目录(-d)并在dest/下创建(mkdir -p),或(-o)在dest/下找到文件(-f)并对其执行touch操作。
这将导致:
dest/src/<file-structre>您可以创造性地使用mv来解决此问题。
其他(部分)解决方案可以通过rsync实现:
rsync -a --filter="-! */" sorce_dir/ target_dir/这里的诀窍是--filter=RULE选项,它排除(-)不是(!)目录(*/)的所有内容
发布于 2012-08-14 13:59:48
在ubuntu上,你可以尝试:
cp -r --attributes-only <source_dir> <target_dir>它不会复制文件数据。来自cp的手册页
--attributes-only
don't copy the file data, just the attributes注意:我不确定此选项是否适用于其他发行版,如果有人可以确认,请更新答案。
发布于 2022-01-21 09:56:09
我需要一个替代方案来仅同步文件结构:
rsync --recursive --times --delete --omit-dir-times --itemize-changes "$src_path/" "$dst_path"我是这样认识到这一点的:
# sync source to destination
while IFS= read -r -d '' src_file; do
dst_file="$dst_path${src_file/$src_path/}"
# new files
if [[ ! -e "$dst_file" ]]; then
if [[ -d "$src_file" ]]; then
mkdir -p "$dst_file"
elif [[ -f $src_file ]]; then
touch -r "$src_file" "$dst_file"
else
echo "Error: $src_file is not a dir or file"
fi
echo -n "+ "
ls -ld "$src_file"
# modification time changed (files only)
elif [[ -f $dst_file ]] && [[ $(date -r "$src_file") != $(date -r "$dst_file") ]]; then
touch -r "$src_file" "$dst_file"
echo -n "+ "
ls -ld "$src_file"
fi
done < <(find "$src_path" -print0)
# delete files in destination if they disappeared in source
while IFS= read -r -d '' dst_file; do
src_file="$src_path${dst_file/$dst_path/}"
# file disappeard on source
if [[ ! -e "$src_file" ]]; then
delinfo=$(ls -ld "$dst_file")
if [[ -d "$dst_file" ]] && rmdir "$dst_file" 2>/dev/null; then
echo -n "- $delinfo"
elif [[ -f $dst_file ]] && rm "$dst_file"; then
echo -n "- $delinfo"
fi
fi
done < <(find "$dst_path" -print0)如您所见,我使用echo和ls来显示更改。
https://stackoverflow.com/questions/11946465
复制相似问题