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

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

问题描述

我有几个目录和包含不带文件扩展名的文件的子目录。我想补充 .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?

推荐答案

替代命令没有明确的环路( 找人 ):

Alternative command without an explicit loop (man find):

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

说明:此递归找到的所有文件(型的F )从当前目录开始( )和适用于移动命令(​​ 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天全站免登陆