LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 08: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 08:51 AM.
 
Old 03-24-2008, 11:36 AM   #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, 12: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 12:57 PM.
 
Old 03-24-2008, 02:31 PM   #4
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
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 02:34 PM.
 
Old 03-24-2008, 02:41 PM   #5
Jay5487
LQ Newbie
 
Registered: Mar 2008
Posts: 5

Original Poster
Rep: Reputation: 0
awesome thanks a bunch
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:01 PM.

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
Open Source Consulting | Domain Registration