Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-24-2008, 08:36 AM   #1
LQ Newbie
Registered: Mar 2008
Posts: 5

Rep: Reputation: 0
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"
cp ${file} pathloss/$CLEANSTR

Last edited by Jay5487; 03-24-2008 at 08:51 AM.
Old 03-24-2008, 11:36 AM   #2
Registered: Nov 2006
Location: Indiana, U.S.A.
Distribution: Red Hat Enterprise Linux, Fedora, CentOS
Posts: 134

Rep: Reputation: 16
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}"

I believe that should take care of it.
Old 03-24-2008, 12:49 PM   #3
LQ Newbie
Registered: Mar 2008
Posts: 5

Original Poster
Rep: Reputation: 0
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

Last edited by Jay5487; 03-24-2008 at 12:57 PM.
Old 03-24-2008, 02:31 PM   #4
LQ Guru
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287
Maybe something like:

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

Last edited by H_TeXMeX_H; 03-24-2008 at 02:34 PM.
Old 03-24-2008, 02:41 PM   #5
LQ Newbie
Registered: Mar 2008
Posts: 5

Original Poster
Rep: Reputation: 0
awesome thanks a bunch


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
UNIX scripting question christianunix Linux - Software 2 10-07-2007 12:38 PM
unix scripting lapthorn Programming 7 03-11-2004 09:03 AM
Renaming files in one go saurya_s Linux - Software 1 01-12-2004 01:16 PM
php and unix scripting murshed Programming 3 06-26-2003 03:56 PM
scripting the unix command script lmcthbe Linux - General 7 05-28-2003 02:49 PM

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration