Доброго времени суток!
Подскажите как решить задачку.
Есть много файлов file[X] где X какое-то число.
Нужно переименовать file[X] в new[X], число должно остаться неизменным.
LinuxForum.Fans
групповое переименование файлов
Автор: v0id
7 сообщений
3086 просмотров
как то так
[console]find /some/dir -name "*file*"|xargs rename file new[/console]
v0id,
DESCRIPTION
rename will rename the specified files by replacing the first occurrence of expression in
their name by replacement.
OPTIONS
-v, --verbose
Give visual feedback which files where renamed, if any.
-V, --version
Display version information and exit.
-h, --help
Display help text and exit.
EXAMPLES
Given the files foo1, ..., foo9, foo10, ..., foo278, the commands
rename foo foo0 foo?
rename foo foo0 foo??
will turn them into foo001, ..., foo009, foo010, ..., foo278. And
rename .htm .html *.htm
will fix the extension of your html files.
Так не работает
text
Bareword "file" not allowed while "strict subs" in use at (eval 1) line 1.
xargs: rename: exited with status 255; aborting
Немного грубо но для вашей задачи подойдет:
[console]#!/bin/bash
_SOURCEDIR="/home/user/test" # в какой папке ищем
_FROMNAME="file" # что нужно заменить в файле
_TONAME="new" # на что нужно заменить
find $_SOURCEDIR/$_FROMNAME* -type f | while read F; do
mv -vf "$F" "$(dirname "$F")/$(basename "$F" | sed 's|'$_FROMNAME'|'$_TONAME'|')";
done[/console]
man rename читали? Ну вот и не работает.Так не работает
Всем спасибо!
Решил задачу, с помощью команды:
text
rename 's/file/new/' *file*Войдите или зарегистрируйтесь, чтобы ответить.