LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 11-12-2008, 11:14 AM   #1
mahmoud
Member
 
Registered: Apr 2006
Location: UK
Distribution: Mandriva, Debain, Redhat, Fedora, Ubuntu, FreeBSD
Posts: 269

Rep: Reputation: 30
rename in script


hi i am trying to look for a file in a folder which is less than 1 day old and rename if
the are a lot of files with the same name but appended with the date and hour at the end and they are all in the same folder i have tried this command but its giving me an its not doing what i want
find /server_backups/ -type f -name backups* +mtime +1 -print | xargs /bin/mv backup_dump.sql
 
Old 11-12-2008, 11:31 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You can try:
Code:
find /server_backups -type f -name backups\* -mtime -1 -exec /bin/mv {} backup_dump.sql \;
or:
Code:
find /server_backups -type f -name backups\* -mtime -1 -print0 | xargs -0 -I{} /bin/mv {} backup_dump.sql
but beware that more than one file is found, they will be overwritten by each other.
 
Old 11-12-2008, 11:43 AM   #3
mahmoud
Member
 
Registered: Apr 2006
Location: UK
Distribution: Mandriva, Debain, Redhat, Fedora, Ubuntu, FreeBSD
Posts: 269

Original Poster
Rep: Reputation: 30
Quote:
Code:

find /server_backups -type f -name backups\* -mtime -1 -exec /bin/mv {} backup_dump.sql \;

or:
Code:

find /server_backups -type f -name backups\* -mtime -1 -print0 | xargs -0 -I{} /bin/mv {} backup_dump.sql

but beware that more than one file is found, they will be overwritten by each other.
the files in the folder have the same name e.g
backups1112200806
backups1113200806
backups1114200806
and so on thats why i am trying to use backup11*
 
Old 11-12-2008, 11:54 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Hmmm, I don't really understand what you're trying to do, now. Are you looking for the last and only file modified in the last 24 hours and rename it? Please, clarify a bit.
 
Old 11-12-2008, 12:04 PM   #5
mahmoud
Member
 
Registered: Apr 2006
Location: UK
Distribution: Mandriva, Debain, Redhat, Fedora, Ubuntu, FreeBSD
Posts: 269

Original Poster
Rep: Reputation: 30
yes i am looking for the last file that was created within the last 24hrs and rename it
the dump happens once a day so its only 1
but because of alot of other scripts i cant rename on dumping it i need to look for the last dumped file
and rename it
 
  


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
To rename files in a directory should I use Bash script or a Perl Script ? jamtech Programming 7 01-23-2008 12:25 AM
Rename script superior888 Programming 2 07-31-2006 12:53 PM
Help with script to rename shilo Slackware 10 02-04-2006 09:58 AM
Script to rename directories superior88 Linux - Newbie 4 02-15-2005 11:31 PM
Need script to rename files joe_stevensen Programming 5 12-05-2003 07:12 PM


All times are GMT -5. The time now is 04:43 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration