递归地将文件扩展名添加到所有文件 [英] recursively add file extension to all files

查看:135
本文介绍了递归地将文件扩展名添加到所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个目录和子目录包含没有文件扩展名的文件。我要向这些目录中包含的所有文件添加 .jpg 。我看过bash脚本更改文件扩展名,但不是只是添加一个。

I have a few directories and sub-directories containing files with no file extension. I want to add .jpg to all the files contained within these directories. I've seen bash scripts for changing the file extension but not for just adding one. It also needs to be recursive, can someone help please?

推荐答案

不带显式循环的替代命令( man find ):

Alternative command without an explicit loop (man find):

find . -type f -exec mv '{}' '{}'.jpg \;



说明:递归查找所有文件( -type f )从当前目录()开始,并应用move命令( mv )。还要注意 {} 周围的引号,以便正确处理带有空格(甚至换行符...)的文件名。

Explanation: this recursively finds all files (-type f) starting from the current directory (.) and applies the move command (mv) to each of them. Note also the quotes around {}, so that filenames with spaces (and even newlines...) are properly handled.

这篇关于递归地将文件扩展名添加到所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆