mst*_*e91 2 linux windows bash ubuntu copy
我在Ubuntu 16.04 LTS的/ media中安装了Windows HDD 。在我的终端中,我已导航到路径/ media / me / OS / Users / Me / Music。从这里,我运行find命令来搜索此Windows路径中的所有MP3:
find . -type f -name *.mp3
Run Code Online (Sandbox Code Playgroud)
这将返回一堆.mp3文件路径(颜色没有任何意义;必须通过Wiki格式化已发生):
./iTunes/iTunes Music/Yeah Yeah Yeahs/It's Blitz/01 Skeletons.mp3
./iTunes/iTunes Music/Yeah Yeah Yeahs/It's Blitz/Gold Lion.mp3
./iTunes/iTunes Music/Yeah Yeah Yeahs/It's Blitz/Heads Will Roll.mp3
./iTunes/iTunes Music/Yeah Yeah Yeahs/It's Blitz/Maps.mp3
Run Code Online (Sandbox Code Playgroud)
如您所见,文件名中有空格。我的目标是将列表中的所有文件(包括560个左右)复制到我的Ubuntu HDD的/ home / me / Music目录中。以下是我尝试过的所有操作的清单,最终导致终端对我大喊:找不到“ ./iTunes/iTunes”,“音乐/是”,“是” ...理念。
我尝试过的事情:
for f in $(find . -name *.mp3); do cp $f ~/Music/WindowsMP3s/; donefind . -type f -name *.mp3 > output.txt 然后 while read file; do cp $file ~/Music/WindowsMP3s/; done <output.txt我试过在for循环和output.txt文件本身中使用重音符号(`)包围文件名。我什至尝试编辑每个空格前带有1和2个反斜杠的output.txt。
任何想法都很棒!
PS:是的,我知道我可以通过文件管理器来完成所有操作,然后将它们复制到外部硬盘驱动器,然后将它们复制到Ubuntu,但是这样做的乐趣何在?!:)
小智 5
尝试“ -exec”如何
find . -type f -name "*.mp3" -exec cp {} ~ \;
Run Code Online (Sandbox Code Playgroud)
将波浪号替换为预期的复制目标。
参考:https : //unix.stackexchange.com/questions/243095/how-does-find-exec-pass-file-names-with-spaces