LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Unix scripting renaming files (https://www.linuxquestions.org/questions/linux-newbie-8/unix-scripting-renaming-files-630222/)

Jay5487 03-24-2008 08:36 AM

Unix scripting renaming files
 
I have probably been working on this for 5+ hours (since im learning and trying to do this) but im trying to copy and rename all the files (and sub files) in a directory to include the date in them and move them to a folder. But only files that have the .pl4 extensions... I have it going through files but errors when i rename

Any help is appriciated.

This is probably the furthest i have gotten..

Update: A little better....

#! /bin/sh
for file in *.pl4; do STR=$file
echo $STR
CLEANSTR=$( date +%m-%d-%y )"$STR"
echo $CLEANSTR
cp ${file} pathloss/$CLEANSTR
done;

Linville79 03-24-2008 11:36 AM

I threw this together in about 20 min, so I definitely haven't had time to see how it handles large numbers of files:


#! /bin/sh
for file in *.pl4; do
mv ${file} "<path_to_new_dir>`date +%Y%m%d`${file}"
done;


I believe that should take care of it.

Jay5487 03-24-2008 12:49 PM

Thanks a bunch, one thing though... It doesnt go recursively through sub folders... I may be able to find this but i feel its easy.. Ill look it up and if I find ill delete this but some help would be nice.

Thanks again

H_TeXMeX_H 03-24-2008 02:31 PM

Maybe something like:

Code:

for file in $(find -name '*.pl4')
do
  mv "$file" "../test2/$(date +%Y%m%d)$(basename $file)"
done


Jay5487 03-24-2008 02:41 PM

awesome thanks a bunch


All times are GMT -5. The time now is 09:01 AM.