Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change the file extension with Linux bash recursion

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to change the file extension with Linux bash recursion. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

How to change the file extension recursively in Linux system? It is a good choice to use bash recursion when we need to change a lot of file extensions, which is very useful when debugging tests.

Use the find-exec and mv commands to recursively change the file extension find. -name "* .t1"-exec bash-c'mv "$1" ${1%.t1} ".t2'-'{}'+ for example: we want to find all the .spec.ts files in the src directory and change the extension

Find. / src-name "* .spec.ts"-type f bash-c'mv "$1"${1%.t1}" .T2'-'{}'+. / src/users/users.controller.spec.ts. / src/auth/auth.service.spec.ts. / src/auth/auth.controller.spec.ts. / src/roles/roles.controller.spec.ts. / src/roles/roles.service.spec.ts. / src/shared/prisma.service .spec.ts. / src/app.controller.spec.ts. / src/permissions/permissions.controller.spec.ts. / src/permissions/permissions.service.spec.ts' {}'is the source file name The package line is relative to the lookup location directory. / src/auth/auth.service.spec.ts, the reason for adding single quotation marks is that shell interprets {}, which normally means creating an array array in shell

A call in the form of + returns a non-zero value as the exit status, that is, find returns a non-zero exit status. If you find an error, exit immediately.

Bash-c executes the specified command

'mv "{1%.t1}" .t2' this is a mv command that accepts two arguments. The first argument is $1, which is the passed -'{}'.

Extra open brace or missing close brace1 is deconstructed, and the path part is assigned to 1%, where 1% is. / src/auth/auth.service

Use the find-exec and rename commands to change the file extension recursively to install rename in ubuntu and debian sudo apt install rename to install rename in Centos and RedHat

Sudo dnf install rename find. -name'* .t1'- exec rename .t1.t2 {} + find. -name "* .t1"-exec rename's /\ .t1 $/ .t2 /'{}'+ the above is how Linux bash recursively changes the file extension. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report