linux - 列出所有扩展的简单 bash 脚本

标签 linux bash

我正在寻找一个 linux bash 脚本,它执行以下操作:它将一个文件夹作为输入,并输出该文件夹中出现的所有扩展名。

例如 脚本输入:包含 3 个 mp3 文件和 2 个 png 的文件夹路径。 脚本的输出:“mp3,png”

最佳答案

通过以下方式查找当前目录中的所有扩展名:

find . -maxdepth 1 -type f|perl -ne 'print $1 if m/\.([^.\/]+)$/'|sort -u|xargs|sed 's/ /, /g'

输出

jpg, log, mp3, mp4, png, we, web, webp

关于linux - 列出所有扩展的简单 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53577058/

相关文章:

linux - Vsfp 用户看不到任何数据 linux Rhel/Centos

python - 如何修复错误 : command 'x86_64-linux-gnu-gcc' failed with exit status 1

bash - 在 Bash 的单行命令中定义变量

linux - 运行 shell 脚本时出现 PAM 对话错误

Linux 排序命令

bash - Shell 脚本未通过 crontab 运行,但手动运行良好

python - 使用子进程将参数传递给 bash 脚本

linux - 使用 bash 脚本的 BusyBox 文件上传 [POST]

arrays - bash:缺少数组的第一个元素

ruby - 32 位 ruby 1.9.2p290 时间无法处理 2038?