如何列出子文件夹中的文件并将此列表输出到本地文件?
How do I list the files in subfolders and output this list to a local file?
我正在使用 find
和 ls
列出子文件夹中包含的 mp3 文件。在每个子文件夹中,我想将它包含的文件列表输出到本地文件(存储在这个子文件夹中)。
我试过这个命令:
find . -type f -name \*.mp3 -execdir basename {} >> playlist.m3u \;
但是它写入的文件playlist.m3u
存放在根目录.
,而不是找到的mp3文件的子目录
有没有办法写入存储在子目录中的文件?
尝试以下命令,这会对您有所帮助:
find -type d -exec bash -c 'cd ; find -maxdepth 1 -not -name "." -name \*.mp3 -printf "%f," | awk "{print substr($0,0,length($0)-1)}" > playlist.m3u' bash "{}" \;
这将用逗号分隔文件列表,请相应更改。
我正在使用 find
和 ls
列出子文件夹中包含的 mp3 文件。在每个子文件夹中,我想将它包含的文件列表输出到本地文件(存储在这个子文件夹中)。
我试过这个命令:
find . -type f -name \*.mp3 -execdir basename {} >> playlist.m3u \;
但是它写入的文件playlist.m3u
存放在根目录.
,而不是找到的mp3文件的子目录
有没有办法写入存储在子目录中的文件?
尝试以下命令,这会对您有所帮助:
find -type d -exec bash -c 'cd ; find -maxdepth 1 -not -name "." -name \*.mp3 -printf "%f," | awk "{print substr($0,0,length($0)-1)}" > playlist.m3u' bash "{}" \;
这将用逗号分隔文件列表,请相应更改。