LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 03-24-2008, 09:36 AM   #1
Jay5487
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"
echo $CLEANSTR
cp ${file} pathloss/$CLEANSTR
done;

Last edited by Jay5487; 03-24-2008 at 09:51 AM.
 
Old 03-24-2008, 12:36 PM   #2
Linville79
Member
 
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}"
done;


I believe that should take care of it.
 
Old 03-24-2008, 01:49 PM   #3
Jay5487
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 01:57 PM.
 
Old 03-24-2008, 03:31 PM   #4
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
Maybe something like:

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

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

Original Poster
Rep: Reputation: 0
awesome thanks a bunch
 
  


Reply


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 01:38 PM
unix scripting lapthorn Programming 7 03-11-2004 10:03 AM
Renaming files in one go saurya_s Linux - Software 1 01-12-2004 02:16 PM
php and unix scripting murshed Programming 3 06-26-2003 04:56 PM
scripting the unix command script lmcthbe Linux - General 7 05-28-2003 03:49 PM


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

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