長いファイル名の拡張子をすばやく変更するには?

長いファイル名の拡張子をすばやく変更するには?

ソースファイル:a really really long name with spaces.ext
ターゲットファイル:the same name.new-ext

注文する:mv *part of the name that'll give a unique answer.ext $(echo $(ls -l | grep -i *.ext | cut -d ' ' -f 11-))

結果:mv: target 'last word of the name.ext': No such file or directory

私は何が間違っていましたか?

PS:リモートシステムではこれだけを許可するのでsh(bashも許可しない)、タブの完成は不可能です。

ベストアンサー1

次のことができます。

for f in *long*.ext; do mv -- "$f" "${f%.ext}.new-ext"; done

あるいは、ダッシュやbusybox ash(hushではない)を含む複数のシェルで、前のコマンド$_の最後の引数に展開されます。

echo *long*

正しいファイルが表示されていることを確認したら、次の手順を実行します。

mv -- "$_" "${_%.ext}.new-ext"

おすすめ記事