【问题标题】:specify the file's parent directory [duplicate]指定文件的父目录[重复]
【发布时间】: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 的父目录。

标签: linux bash shell vim task


【解决方案1】:

使用命令“文件夹名”获取文件的父目录

【讨论】:

    【解决方案2】:

    ./ 是您的当前目录,../ 是您当前目录的父目录。

    我认为您应该将cp -a . catalog_B/ 更改为cp -a ../ catalog_B/

    【讨论】:

      猜你喜欢
      • 2020-11-24
      • 2023-03-07
      • 2017-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-20
      • 2015-03-21
      相关资源
      最近更新 更多