Ubuntu This forum is for the discussion of Ubuntu Linux. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
11-19-2008, 05:52 PM
|
#1
|
Member
Registered: Jan 2007
Distribution: Ubuntu
Posts: 59
Rep:
|
how to automatically rename files
I'm looking for a way to automatically rename (and possibly move) files. I have a server that downloads my favourite tv shows and I would like the files that show up in the download folder to be renamed (based on set rules). Is this possible? Do I have to write a script or is there a program that will already do this?
|
|
|
11-19-2008, 06:04 PM
|
#2
|
LQ Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Rep:
|
Yes it's possible, and I suspect you need to write a script.
What are the rules?
|
|
|
11-19-2008, 06:39 PM
|
#3
|
Member
Registered: Jan 2007
Distribution: Ubuntu
Posts: 59
Original Poster
Rep:
|
i want it to rename the file (which will look like Title.Title.S##E##.hdtv.eztv-lol.avi) to be Title Title ##x##.avi
|
|
|
11-19-2008, 06:41 PM
|
#4
|
LQ Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Rep:
|
That's pretty simple. Are you using a script to download the files?
|
|
|
11-20-2008, 02:10 AM
|
#5
|
Member
Registered: Aug 2005
Distribution: SuSE Linux / Scientific Linux / [K|X]ubuntu
Posts: 273
Rep:
|
There is a bulk rename app that you can download through synaptic. Just look for bulk rename and you'll find it.
|
|
|
11-20-2008, 11:18 PM
|
#6
|
Member
Registered: Jan 2007
Distribution: Ubuntu
Posts: 59
Original Poster
Rep:
|
will that automatically rename the files as they show up though?
|
|
|
11-20-2008, 11:50 PM
|
#7
|
LQ Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Rep:
|
Again, how are you downloading the files?
|
|
|
11-21-2008, 11:32 PM
|
#8
|
Member
Registered: Jan 2007
Distribution: Ubuntu
Posts: 59
Original Poster
Rep:
|
using miro to download the bittorrents from an rss feed
|
|
|
11-22-2008, 02:48 AM
|
#9
|
Member
Registered: Aug 2005
Distribution: SuSE Linux / Scientific Linux / [K|X]ubuntu
Posts: 273
Rep:
|
Quote:
will that automatically rename the files as they show up though?
|
It's not psychic, so it won't do that automatically! But if you say that you want to replace a certain string of (special) characters in lots of files with something else, then it works fine.
Or you could legally buy the DVDs of your favourite TV series and then watch them on you TV. No renaming there!
Last edited by unihiekka; 11-22-2008 at 02:49 AM.
|
|
|
11-22-2008, 04:17 AM
|
#10
|
LQ Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Rep:
|
For the renaming, I'd use a script along the lines of
Code:
cd /path/to/files
for filename in *"hdtv.eztv"* ;do
newfile=$(echo $filename | sed -e 's/\(.*\)\.\(.*\)\.S\(..\)E\(..\)\.hdtv\.eztv\-lol\.avi/\1 \2 \3x\4\.avi/')
echo $filename "|" $newfile
# mv $filename $newfile
done
(note the test mode of just echoing potential changes - comment that out and uncomment the "mv" if it works)
In terms of calling the script, you could run this regularly from a cron job (every 15 minutes for example), or if you are keen, there is a program called incron that is similar to cron, but rather than watching time, incron watches directories for changes. In other words, incron can trigger scripts when files are created in directories.
Cron wold be simpler, but let us know if you'd prefer to try incron.
|
|
|
11-22-2008, 11:27 PM
|
#11
|
Member
Registered: Jan 2007
Distribution: Ubuntu
Posts: 59
Original Poster
Rep:
|
thanks billymayday i will try that out. i think my idea was something like incron where any changes would trigger the event, but cron should work fine. i mean it's not like i need it to be instant (or even psychic).
have a great day and thanks again for your help!
|
|
|
11-22-2008, 11:43 PM
|
#12
|
LQ Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Rep:
|
No probs - just remember to come back and tell us what worked, how it went, etc.
|
|
|
11-24-2008, 05:19 AM
|
#13
|
Member
Registered: Mar 2006
Location: Singapore
Distribution: Ubuntu 10.10
Posts: 83
Rep:
|
Xfce's Thunar file manager includes a built-in rule-based file renaming utility. Particularly handy because it gives you a preview of what your renaming rule will do. You could either use regular expressions or do the renaming in stages (i.e., renaming the beginning part first, then the end, etc). You don't need to install complete Xfce, just Thunar.
|
|
|
All times are GMT -5. The time now is 09:18 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|