简体   繁体   English

复制包含在文本文件中的文件 (MacOS)

[英]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.

相关问题 将文本复制到剪贴板时 macOS 会更改文本 - macOS change text when you copy it to clipboard 用户homedir MacOS中的Bash复制文件 - Bash copy file in user homedir MacOS 相当于 MacOs 上的 robocopy - 复制完整的文件夹结构但包含空文件 - Equivalent to robocopy on MacOs - Copy full folder structure but with empty files 在 macOS 上使用 Intune 推送 plist 文件正在重命名文件 - Pushing plist files with Intune on macOS is renaming the file Python MacOS 循环文件 获取文件信息 - Python MacOS Loop Files Get File Info 如何在Win上正确打开MacOs文本文件? - How to open MacOs text file correctly on Win? macOS 中的特权文件复制(将帮助程序二进制文件安装到 /usr/local/bin) - Privileged file copy in macOS (Installing a helper binary to /usr/local/bin) 如何将视频作为文件从本地 URL (macOS) 复制到 NSPasteboard? - How to copy a video to NSPasteboard as a file from a local URL (macOS)? Swift MacOS,如何在转换为 NSFilePromiseReceiver 后复制原始文件 URL? - Swift MacOS, how copy original file URL after casting to NSFilePromiseReceiver? 如何在 macOS 上的 Sublime Text 中在同一窗口中打开文件和文件夹? - How to Open files and folders in same window in Sublime Text on macOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM