[英]Copy Files Contained in a Text File (MacOS)
I have a text file containing.M4B filenames (including source path).我有一个包含 .M4B 文件名(包括源路径)的文本文件。 The file names contain spaces and quotes like:文件名包含空格和引号,例如:
/file/source/Ender's Game.m4b /文件/来源/安德的游戏.m4b
/file/source/Ender's Shadow.m4b /file/source/安德的影子.m4b
/file/source/Speaker for the Dead.m4b /file/source/Speaker for the Dead.m4b
I'm trying to pipe the file contents to cp the audiobooks to the same destination using the xargs command:我正在尝试使用 xargs 命令将文件内容 pipe cp 到同一目的地的有声读物:
cat /path/to/file/filenames.txt | xargs cp {} /destination/folder/ \;
The first time i ran the command it returned xargs: unterminated quote我第一次运行命令时返回 xargs: unterminated quote
I then put quotes around the filenames /file/source/"Ender's Game.m4b" and ran the command and it returned: cp: /file/source/Ender's Game.m4b is not a directory然后我在文件名周围加上引号 /file/source/"Ender's Game.m4b" 并运行命令并返回:cp: /file/source/Ender's Game.m4b is not a directory
Using zsh and macOS Ventura 13.0.1使用 zsh 和 macOS Ventura 13.0.1
A possible approach to overcome quotes' pain could be converting newlines to ascii nuls, then ab-using xargs -0
:克服引号痛苦的一种可能方法是将换行符转换为 ascii nul,然后使用xargs -0
ab-using:
cat /path/to/file/filenames.txt | tr '\n' '\000' | xargs -0 -I{} cp {} /destination/folder/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.