Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  12] [ 0]  / answers: 1 / hits: 20958  / 3 Years ago, sat, october 30, 2021, 5:56:51

I found this answer how do i... but it simply doesn't work - it did not rename any file for unknown to me reason



Before I started to search around I thought that it should be easy task even for novice penguin, but it doesn't seem so for me.



For example, I simply can't tell ls to list all *.txt in all subfolders, which was surprise to me (without grep or similar).

Then I found find and find . -name name_1.txt lists files fine, but



for f in $(find . -name name_1.txt) ; do echo "$f" ; done



splits whole file paths with space as separator, so it's unusable to pass that output to some command like mv or rename



I want to ask whats wrong with above command and if possible some nifty oneliner so I can recursively rename name_1.txt to name_2.txt


More From » bash

 Answers
4

find . -name '*.txt' -print0 | xargs -0 -n1 bash -c 'mv "$0" "${0/oldname/newname}"'



Obviously, that rename pattern is just a simple example, but beware that as is it will edit the whole path, not just the filename.


[#41973] Saturday, October 30, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
confiorc

Total Points: 42
Total Questions: 121
Total Answers: 123

Location: India
Member since Wed, Aug 26, 2020
4 Years ago
confiorc questions
Fri, Jul 23, 21, 18:21, 3 Years ago
Tue, Mar 22, 22, 14:25, 2 Years ago
Thu, Feb 17, 22, 22:43, 2 Years ago
;