When I am using xargs
sometimes I do not need to explicitly use the replacing string:
find . -name \"*.txt\" | xargs rm -rf
In oth
the files should be renamed/moved from
to
.txt /foo/
.bar.txt
You can use rename
utility, e.g.:
rename s/\.txt$/\.txt\.bar/g *.txt
Hint: The subsitution syntax is similar to sed
or vim
.
Then move the files to some target directory by using mv
:
mkdir /some/path
mv *.bar /some/path
To do rename files into subdirectories based on some part of their name, check for:
-p
/--mkpath
/--make-dirs
Create any non-existent directories in the target path.
Testing:
$ touch {1..5}.txt
$ rename --dry-run "s/.txt$/.txt.bar/g" *.txt
'1.txt' would be renamed to '1.txt.bar'
'2.txt' would be renamed to '2.txt.bar'
'3.txt' would be renamed to '3.txt.bar'
'4.txt' would be renamed to '4.txt.bar'
'5.txt' would be renamed to '5.txt.bar'