复制和粘贴命令时命令行中出现奇怪的重复/错误

Weird duplication/mistakes in command line when I copy and paste commands

提问人:D.R 提问时间:9/19/2019 最后编辑:D.R 更新时间:9/20/2019 访问量:44

问:

我有以下命令,当我单独运行它们时,它们会起作用。

find ./temp -name "Keller, Whitney" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Keller, Whitney_73618848766720/Student_Assignments/" ;) done ; find ./temp -name "Keller, Whitney" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Keller, Whitney_73618848766720/Student_Assignments/" ;) done ; cp -Rn "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Keller, Whitney_73618848766720/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Keller, Whitney_73618848766720/" ; 
find ./temp -name "Kim, Christina" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Christina_73618848766722/Student_Assignments/" ;) done ; find ./temp -name "Kim, Christina" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Christina_73618848766722/Student_Assignments/" ;) done ; cp -Rn "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Christina_73618848766722/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Christina_73618848766722/" ; 
find ./temp -name "Kim, Daniel" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Daniel_73618848766721/Student_Assignments/" ;) done ; find ./temp -name "Kim, Daniel" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Daniel_73618848766721/Student_Assignments/" ;) done ; cp -Rn "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Daniel_73618848766721/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Daniel_73618848766721/" ; 
find ./temp -name "Kim, Eunice" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Eunice_73618848767724/Student_Assignments/" ;) done ; find ./temp -name "Kim, Eunice" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Eunice_73618848767724/Student_Assignments/" ;) done ; cp -Rn "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Eunice_73618848767724/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Eunice_73618848767724/" ; 
find ./temp -name "Kim, Rebecca" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Rebecca_73618848766723/Student_Assignments/" ;) done ; find ./temp -name "Kim, Rebecca" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Rebecca_73618848766723/Student_Assignments/" ;) done ; cp -Rn "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Rebecca_73618848766723/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Rebecca_73618848766723/" ; 

但是,当我将所有 5 个复制并粘贴到我的命令行中(突出显示所有 5 个、command-C、command-V)时,命令行如下所示:

D-XXX-XX-XXX-XXX:renameFoldersProject oppeasnt$ find ./temp -name "Keller, Whitney" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Keller, Whitney_73618848766720/Student_Assignments/" ;) done ; find ./temp -name "Keller, Whitney" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Keller, Whitney_73618848766720/Student_Assignments/" ;) done ; cp -Rn "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Keller, Whitney_73618848766720/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Keller, Whitney_73618848766720/" ; 
find ./temp -name "Kim, Christina" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Christina_73618848766722/Student_Assignments/" ;) done ; find ./temp -name "Kim, Christina" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Christina_73618848766722/Student_Assignments/" ;) done ; cp -Rn "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Christina_73618848766722/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Christina_73618848766722/" ; 
find ./temp -name "Kim, Daniel" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Daniel_73618848766721/Student_Assignments/" ;) done ; find ./temp -name "Kim, Daniel" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Daniel_73618848766721/Student_Assignments/" ;) done ; D-XXX-XX-XXX-XXX:renameFoldersProject oppeasnt$ find ./temp -name "Kim, Christina" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Christina_73618848766722/Student_Assignments/" ;) done ; find ./temp -name "Kim, Christina" -type d | while readt/Desktop/RenameFoldersProject/temp/2016/Kim, Christina_73618848766722/Student_Assignments/" ;) done ; cp -Rn "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Christina_73618848766722/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Christina_73618848766722/" ; 
find ./temp -name "Kim, Daniel" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Daniel_73618848766721/Student_Assignments/" ;) done ; find ./temp -name "Kim, Daniel" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Daniel_73618848766721/Student_Assignments/" ;) done ; cpfiRn "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Daniel_73618848766721/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Daniel_73618848766721/" ; 
find ./temp -name "Kim, Eunice" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Eunice_73618848767724/Student_Assignments/" ;) done ; find ./temp -name "Kim, Eunice" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Eunice_73618848767724/Student_Assignments/" ;) done ; cp -Rn "/Users/oppD-XXX-XX-XXX-XXX:renameFoldersProject oppeasnt$ find ./temp -name "Kim, Daniel" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Daniel_73618848766721/Student_Assignments/" ;) done ; find ./temp -name "Kim, Daniel" -type d | w/RenameFoldersProject/temp/2016/Kim, Daniel_73618848766721/Student_Assignments/" ;) done ; cpfiRn "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Daniel_73618848766721/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Daniel_73618848766721/" ; 
find ./temp -name "Kim, Eunice" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Eunice_73618848767724/Student_Assignments/" ;) done ; find ./temp -name "Kim, Eunice" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Eunice_73618848767724/Student_Assignments/" ;) done ; cp -Rn "/Users/oppeafind ./ktop/RenameFoldersProject/temp/2016/Kim, Eunice_73618848767724/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Eunice_73618848767724/" ; 
find ./temp -name "Kim, Rebecca" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Rebecca_73618848766723/Student_Assignments/" ;) done ; find ./temp -name "Kim, Rebecca" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Rebecca_73618848766723/Student_Assignments/" ;) done ; cp -Rn "/Users-bash: cpfiRn: command not found
D-XXX-XX-XXX-XXX:renameFoldersProject oppeasnt$ find ./temp -name "Kim, Eunice" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Eunice_73618848767724/Student_Assignments/" ;) done ; find ./temp -name "Kim, Eunice" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Eunice_73618848767724/Student_Assignments/" ;) done ; cp -Rn "/Users/oppeafind ./ktop/RenameFoldersProject/temp/2016/Kim, Eunice_73618848767724/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Eunice_73618848767724/" ; 
find ./temp -name "Kim, Rebecca" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Rebecca_73618848766723/Student_Assignments/" ;) done ; find ./temp -name "Kim, Rebecca" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Rebecca_73618848766723/Student_Assignments/" ;) done ; cp -Rn "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Rebecca_73618848766723/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Rebecca_73618848766723/" ; cp: /Users/oppeafind ./ktop/RenameFoldersProject/temp/2016/Kim, Eunice_73618848767724/Student_Documents: No such file or directory
D-XXX-XX-XXX-XXX:renameFoldersProject oppeasnt$ find ./temp -name "Kim, Rebecca" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Rebecca_73618848766723/Student_Assignments/" ;) done ; find ./temp -name "Kim, Rebecca" -type d | while read path ; do (cp -Rn "$path/" "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Rebecca_73618848766723/Student_Assignments/" ;) done ; cp -Rn "/Users/oppeasnt/Desktop/RenameFoldersProject/temp/2016/Kim, Rebecca_73618848766723/Student_Documents" "/Users/oppeasnt/Desktop/RenameFoldersProject/Year_of_Entry_2016/Kim, Rebecca_73618848766723/" ; 

您可以看到有些行是重复的,并且比我的原始命令要长得多。

如果向右滚动更多,则会看到类似以下内容

cp -Rn "/Users/oppD-XXX-XX-XXX-XXX:renameFoldersProject oppeasnt$

cp -Rn "/Users/oppeafind ./ktop/RenameFoldersProject/temp/2016/Kim, Eunice_73618848767724/Student_Documents

看起来像不同命令之间的冲突/重叠。

为什么会这样?我该如何解决这个问题?

macOS 命令行 复制粘贴

评论

1赞 shellter 9/20/2019
在 *nix shell 中,您可以通过键入 来获取文件/脚本。源词也可以简化为char,所以,但我认为没有必要使用*nix shell的那个功能在另一个shell脚本中运行。您所需要的只是.如果脚本运行良好,它将退出,并显示“正常”或“错误”状态代码。如果你有这个,那么你可以写 如果需要的话,你可以在 和 块中做更多的事情。...source /path/to/script.. /path/to/script/path/to/script/path/to/scriptif /path/to/script ; then echo script exited OK ; else echo error running script ; fiifelse
1赞 shellter 9/20/2019
(恕我直言),您将通过将每个命令放在单独的行上来减少混淆。您的命令也很可能会生成错误或警告消息。我会使用 tmp 日志文件来捕获该信息,但首先将之前的任何运行归零。现在,在每个命令的末尾附加。在提示返回给您之前,您不应该得到任何输出。然后。查看大小不为零的任何文件。...findfind> /tmp/myFindLog.txt; > /tmp/myFindErrs.txt>> /tmp/myFindLog.txt 2>>/tmp/myFindErrs.txtfindls -l /tmp/myFind*
1赞 shellter 9/20/2019
现在,您可以确定哪一行脚本生成了哪个输出。如果需要进一步的帮助,请编辑 Q 以包含相关的日志文件信息。你承担了一个复杂的项目,所以你需要花时间分析系统的反馈并了解问题的根源。
1赞 shellter 9/20/2019
如果你真的想了解你的问题,你应该删除你以前运行创建的任何目录和文件(但要小心,不要删除已经存在的其他东西,花点时间确定)。最后,我不明白为什么有些命令在括号内,而另一些则不在。(考虑到您系统上无法从 Q 中看到的条件,也许这是对的,但我会感到惊讶)。效率,它几乎没有任何区别,但它可能会影响您的结果(或者可能全部)需要括号?....cp -Rn ...cp -Rn...s
1赞 shellter 9/20/2019
在最坏的情况下,运行命令,运行有问题的代码,键入 Ctr-D 字符(并回车),它应该退出 。它会告诉你它把成绩单保存到哪个文件,将该文件发布到文件共享网站(pastebay?,许多其他网站)。并在您的 Q 或发送给我的评论中添加一个链接。祝你好运。screenscreen

答: 暂无答案