bash - Finding multiple files recursively and renaming in linux -
i having files a_dbg.txt, b_dbg.txt ...
in suse 10
system. want write bash shell script should rename these files removing "_dbg" them.
google suggested me use rename
command. executed command rename _dbg.txt .txt *dbg*
on current_folder
my actual current_folder
contains below files.
current_folder/a_dbg.txt current_folder/b_dbg.txt current_folder/xx/c_dbg.txt current_folder/yy/d_dbg.txt
after executing rename
command,
current_folder/a.txt current_folder/b.txt current_folder/xx/c_dbg.txt current_folder/yy/d_dbg.txt
its not doing recursively, how make command rename files in subdirectories. xx
, yy
having many subdirectories name unpredictable. , current_folder
having other files also.
you can use find
find matching files recursively:
$ find . -iname "*dbg*" -exec rename _dbg.txt .txt '{}' \;
edit: '{}'
, \;
are?
the -exec
argument makes find execute rename
every matching file found. '{}'
replaced path name of file. last token, \;
there mark end of exec expression.
all described nicely in man page find:
-exec utility [argument ...] ; true if program named utility returns 0 value exit status. optional arguments may passed utility. expression must terminated semicolon (``;''). if invoke find shell may need quote semicolon if shell otherwise treat control operator. if string ``{}'' appears anywhere in utility name or argu- ments replaced pathname of current file. utility executed directory find executed. utility , arguments not subject further expansion of shell patterns , constructs.
Comments
Post a Comment