【发布时间】:2022-07-26 22:10:56
【问题描述】:
大家好,我正在构建一个脚本来订购与我的研究文件相关的文件,但我不明白为什么提示会给我这个错误
错误 1.1
mv: cannot stat 'filefilefilefilefilefilefilefilefilefilefilefile.pdf'$'\n': File name too long
这意味着我必须重命名所有长文件?是否存在其他方法来防止此错误? 下面的例子是产生错误的脚本
脚本 1 - 将所有包含业务的 greped 文件移到其名称文件中,并将它们移到 auto_folder_business 中
mkdir -p /mnt/c/Users/alber/Desktop/testfileorder/auto_folder_business
ls /mnt/c/Users/alber/Desktop/testfileorder | egrep -i 'business.' | xargs -0 -I '{}' mv '{}' /mnt/c/Users/alber/Desktop/testfileorder/auto_folder_business
在上面的示例中,我也遇到了其他错误
错误 1.2
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
我解决了插入 -0 选项, 尽管如此,我试图概括这个过程写这个sn-p
脚本 2 - 将所有包含插入关键字的 greped 文件移动到其名称文件中,并将它们移动到 auto_folder_business 中
#!/bin/sh
read -p "file to order: --> " fetching_keyword
mypath=/mnt/c/Users/alber/Desktop/testfileorder/auto_folder_$fetching_keyword/
echo $mypath
mkdir -p $mypath
ls /mnt/c/Users/alber/Desktop/testfileorder |
egrep -i "$fetching_keyword" |
xargs -0 -I {} mv -n {} $mypath
这里我还有一个错误,我认为它们是相关的
错误 2
mv: cannot stat 'Statino (1).pdf'$'\n''Statino (2).pdf'$'\n''Statino (3).pdf'$'\n''Statino (4).pdf'$'\n''Statino.pdf'$'\n''auto_folder_statino'$'\n': No such file or directory
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
我不明白我做错了什么......
【问题讨论】:
标签: bash file automation script productivity-power-tools