LINUX.ORG.RU

shell script


0

0
В общем, может кто подкинет шелл скрипт который припишет к именам всех файлов в директории некоторое слово (несколько слов) ? :) Если не трудно конечно, а то сам я буду долго писать это =)
★★★★★
Ответ на: комментарий от anonymous
reanme вроде немного не то делает, хотя хз
roy ★★★★★
() автор топика
Ответ на: комментарий от anonymous
Да, оно работает. Я правда забыл уточнить, что прибавить надо к началу файла, а find возвращает имя фалйа вместе с его путем..
roy ★★★★★
() автор топика
Ответ на: комментарий от roy
rename 's/(.*)/YourWord\.$1/' * 

################################

$ cat /usr/bin/rename

#!/usr/bin/perl -w
use strict;

use Getopt::Long;
Getopt::Long::Configure('bundling');

my ($verbose, $no_act, $force, $op);

die "Usage: rename [-v] [-n] [-f] perlexpr [filenames]\n"
    unless GetOptions(
        'v|verbose' => \$verbose,
        'n|no-act'  => \$no_act,
        'f|force'   => \$force,
    ) and $op = shift;

$verbose++ if $no_act;

if (!@ARGV) {
    print "reading filenames from STDIN\n" if $verbose;
    @ARGV = <STDIN>;
    chop(@ARGV);
}
for (@ARGV) {
    my $was = $_;
    eval $op;
    die $@ if $@;
    next if $was eq $_; # ignore quietly
    if (-e $_ and !$force)
    {
        warn  "$was not renamed: $_ already exists\n";
    }
    elsif ($no_act or rename $was, $_)
    {
        print "$was renamed as $_\n" if $verbose;
    }
    else
    {
        warn  "Can't rename $was $_: $!\n";
    }
}

__END__
###########################################################
renames the filenames supplied according to the rule specified
as the first argument.
The argument is a Perl expression which is expected to modify the
string in Perl for at least some of the filenames specified.
If a given filename is not modified by the expression, 
it will not be renamed.
If no filenames are given on the command line, 
filenames will be read via standard input.

For example, to rename all files matching *.bak to strip the extension, you might say
        rename 's/\.bak$//' *.bak
anonymous
()
Ответ на: комментарий от anonymous
Большое спасибо, то, что надо :)
roy ★★★★★
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.