【发布时间】:2020-09-23 07:33:02
【问题描述】:
任务:编写一个脚本,将子目录(以及其中的所有文件)从目录 A 复制到目录 B。只应复制包含 pdf、tif、jpg 文件的目录。应复制包含子目录和文件的整个父目录。目录名称可能包含服务符号。 问题:不知道如何指定父目录而不是当前目录。
#!/bin/bash
IFS=$'/n'
#mentioning to move the string as a delimiter instead of a space
for file -name "*.pdf" -o "*.tif" -o "*.jpg" in catalog_A/*
#loop "for" for files with a name ending in ".pdf" or ".tif" or ".jpg" in directory A
do
#loop body
echo $(pwd)
#current absolute path output
dirname="$dirname"
#upload the name of the current directory for a holistic view of its name, which may contain system symbols
cp -a . catalog_B/
#copy the current directory with attached files to directory B
done
#end of cycle
【问题讨论】:
-
我建议分小步完成任务。目前,您的脚本存在语法错误,无法按预期工作。如果前面的步骤还没有解决,请不要尝试解决下一步。从修复循环开始。一切准备就绪后,您可以使用
path/..访问path的父目录。