![无法将搜索到的文件移动到目录](https://linux22.com/image/217691/%E6%97%A0%E6%B3%95%E5%B0%86%E6%90%9C%E7%B4%A2%E5%88%B0%E7%9A%84%E6%96%87%E4%BB%B6%E7%A7%BB%E5%8A%A8%E5%88%B0%E7%9B%AE%E5%BD%95.png)
以下命令的输出是:
$ rga --heading -l --context 3 --sort path -i -e "use cases?" -e "user stor(y|ies)" -e "Technical debt"
Stepanek G. - Software Project Secrets (The Expert's Voice in Project Management) - 2012.pdf
Strategic Project Management Made Simple Solution Tools for Leaders and Teams (Terry Schmidt) (z-lib.org).pdf
Succeeding with Agile Software Development Using Scrum.pdf
Team Topologies Organizing Business and Technology Teams for Fast Flow (Matthew Skelton Manuel Pais [Skelton etc.) (z-lib.org).epub
The Agile Samurai How Agile Masters Deliver Great Software (Jonathan Rasmusson) (z-lib.org).pdf
The Art of Agile Development - James Shore & Shane Warden.pdf
The Art of Lean Software Development a Practical and Incremental Approach (Curt Hibbs Steve Jewett Mike Sullivan) (z-lib.org).pdf
The Art of Project Management - By Scott Berkun.pdf
The Complete Software Project Manager Mastering Technology from Planning to Launch and Beyond by Anna P. Murray (z-lib.org).pdf
The Enterprise and Scrum (Ken Schwaber) (z-lib.org).pdf
The Fast Forward MBA in Project Management 3rd Edition (2008) (Portable Mba Series) (Eric Verzuh) (z-lib.org).pdf
The Making of a Manager (Julie Zhuo) (z-lib.org).pdf
The Manager’s Path A Guide for Tech Leaders Navigating Growth and Change (Camille Fournier) (z-lib.org).epub
The PMI Guide to Business Analysis (Project Management Institute) (z-lib.org).epub
The Phoenix Project.pdf
The Rational Unified Process An Introduction (Philippe Kruchten) (z-lib.org).pdf
The Scrum Field Guide Agile Advice for Your First Year and Beyond (Lacey Mitch.) (z-lib.org).pdf
The Unicorn Project A Novel about Developers, Digital Disruption, and Thriving in the Age of Data by Gene Kim (z-lib.org).epub
The rational unified process made easy a practitioners guide to the RUP (Per Kroll Philippe Kruchten) (z-lib.org).pdf
Tim_Brizard-Broken_Agile-EN.pdf
Visualizing Project Management - Models and Frameworks for Mastering Complex Systems by Kevin Forsberg, Hal Mooz, Howard Cotterman (z-lib.org).pdf
essential-scrum-a-practical-guide-to-the-most-popular-agile-process.9780137043293.57714.pdf
succeeding-with-agile-software-development-using-scrum.9780321579362.53099.pdf
我正在尝试将这些文件移至单独的目录。
我尝试过的命令是:
rga --heading -l --context 3 --sort path -i -e "use cases?" -e "user stor(y|ies)" -e "Technical debt" | xargs -I {} mv {} DEST
和
rga --heading -l --context 3 --sort path -i -e "use cases?" -e "user stor(y|ies)" -e "Technical debt" > files.txt
for file in $(cat files.txt); do mv "$file" DEST; done
我正进入(状态xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
和
rga --heading -l --context 3 --sort path -i -e "use cases?" -e "user stor(y|ies)" -e "Technical debt" | xargs -r0 mv -t DEST
和
for file in $(cat temp.adoc); do mv "$file" "DEST/$file"; done
它说mv: cannot stat '''Stepanek ...
答案1
使用 GNUxargs
和mv
shell ( bash
),您可以:
xargs -rd '\n' -a <(rga...) mv -t DEST/ --
如果没有-d
(或-0
的缩写-d '\0'
),xargs
仍然将'
,"
和理解\
为引用运算符。
使用xargs -a <(...) cmd
(需要具有 ksh 样式进程替换的 shell,如 zsh 或 bash,尽管其他 shell 类似rc
,es
或者fish
也具有不同语法的功能)比 using 更好,... | xargs cmd
因为它允许cmd
与 stdin 交互,并且mv
可能会提示用户在某些情况下。
使用mv -t /DEST ...
意味着我们可以传递多个文件,mv
而不必生成一个进程并mv
为每个文件执行。
答案2
您尝试过的所有这些变体都使用cat file.txt
.这最终会展开每个文件名,并且会受到分割$IFS
(通常是空格)的影响。例如,“The Phoenix Project.pdf”则变为三个单词“The”、“Phoenix”、“Project.pdf”。显然,这些都不以文件形式存在,因此无法移动。
我不熟悉rga
,但鉴于您的输出,这就是您可以如何解决的方法:
rga … |
while IFS= read -r file
do
mv -- "$file" DEST/
done
或者,如果您可以保证每个文件名都单独占一行,
rga … | tr '\n' '\0' | xargs -0r -n1 -I{} mv -- {} DEST/