There are many files in the folder with the names in the form of numbers in parentheses:
(123).txt (757823).txt Tell me how to massively remove parentheses from file names? To become:
123.txt 757823.txt There are many files in the folder with the names in the form of numbers in parentheses:
(123).txt (757823).txt Tell me how to massively remove parentheses from file names? To become:
123.txt 757823.txt So far it has worked out for a long time, but it seems safe from the point of view of special characters:
find -name '(*).txt' -print | sed 's/$/\x0/;p;s/[()]//g' | tr -d '\n' | xargs -0 -n2 mv Attention : before you execute in combat mode, execute the command with replacing mv with echo to check which arguments will be passed to the mv command.
The following happens in the find : find finds all matching files and prints one per line. sed adds a 0-character before the end of the line and prints the line, then deletes all the brackets in the name and prints the line again (default action). After it, tr deletes the carriage returns. xargs executes the specified command, passing in pairs of 2 arguments from the input stream, separated by a 0-character. In this mode, xargs guarantees the correct transfer of parameters with any special characters (spaces and quotes)
#!/bin/bash for f1 in `find /temp -name '*'`; do f2=${f1/(/} f2=${f2/)/} echo "$f1 -> $f2" mv $f1 $f2 done Team
$ rename 's/[\(\)]//g' *.txt renames all .txt files by removing the parentheses.
util-linux package, which is one of my own and which cannot do this. And the other one comes with perl (in fact, it is generally a link to the perl executable file), so she understands this syntax - MikeSource: https://ru.stackoverflow.com/questions/687915/
All Articles