というファイルがあり、35554842200284685106000166550020003504201637715423.xml
名前を次のように変更するだけです42200284685106000166550020003504201637715423.xml
(最後の48文字の前のすべての項目を削除)。この単純な正規表現()は最後の48文字を抽出できますが、Bashでは動作させることは.{48}$
できません。rename
rename
この正規表現を使用して名前を最後の48文字に変更するにはどうすればよいですか?
編集する:
出力rename --help
[root@ip-000-00-0-000 tmp]# rename --help
Usage:
rename [options] <expression> <replacement> <file>...
Rename files.
Options:
-v, --verbose explain what is being done
-s, --symlink act on the target of symlinks
-n, --no-act do not make any changes
-h, --help display this help and exit
-V, --version output version information and exit
For more details see rename(1).
ありがとうございます。
ベストアンサー1
実際にはこれは必要ありませんrename
。問題を解決できます。
$ file=35554842200284685106000166550020003504201637715423.xml
$ newname=$(sed -E 's/.*(.{48})/\1/'<<<"$file");
$ mv -v "$file" "$newname"
renamed '35554842200284685106000166550020003504201637715423.xml' -> '42200284685106000166550020003504201637715423.xml'