Batch Rename

Is there a way I can rename certain files in a folder.
e.g.
A folder full of different format video files, mpeg, mkv,mp4, divx.
I want to rename a certain type to avi say all the divx to avi, how do I do it other than each one individually, bearing in mind that I want to keep the original name.

Firstly … you are aware that file extensions don’t mean anything to Linux ? … it gets its file “type” in a different way to Windows.

But if you still want to rename a directory of .jpeg files to .jpg: … the following example is to rename all file name.divx to file_name.avi

First change directory to the directory containing the files you want to change the extension of :

cd /path/to/directory/containing/files

Next you’ll have to remove any spaces from the file names … so my movie.divx becomes my_movie.divx :

rename 'y/ /_/' *.divx

Then to rename the .divx extension to .avi :

rename 's/\.divx/.avi/' *.divx

[b] Or for a GUI method[/b] -

Install prefixsuffix

sudo apt-get install prefixsuffix

You’ll then find PrefixSuffix in the menus … use the Suffix section to -
Replace: .divx
With: .avi

in a given Folder.

Thanks for that, I used the GUI method (I bet you knew I would :))
Wow… it’s quick.

Is the recursive into folders supposed to do inside the folders too… cos it didn’t do it?

Yeh, I suppose I did … but here’s nothing wrong with that … use whatever suits :wink:

Well yeh, I would have thought so ??? … just a thought, but do you have write permission for the sub-directories ?

I would have thought so, they do not have padlocks on them and I did create them???

They won’t necessarily have padlocks on them … you can see /etc can’t you and that hasn’t got a padlock on it, but you cannot write to it without root permission.

what is the output from:

ls -l /path/to/sub/directory

?

peter@Petes-ubuntu-pc:~$ ls -l /media/Drive3/Porn/Porn_B
total 13239840
-rwxrwxrwx 1 peter peter 261948290 2010-06-11 05:14 All That’s listed here is .avi files
-rwxrwxrwx 1 peter peter 4745018 2010-07-09 10:32
-rwxrwxrwx 1 peter peter 144406582 2010-07-13 19:21
-rwxrwxrwx 1 peter peter 151841420 2010-07-13 20:04
-rwxrwxrwx 1 peter peter 151876242 2010-07-13 20:40
-rwxrwxrwx 1 peter peter 280297794 2010-08-02 23:37
-rwxrwxrwx 1 peter peter 266655114 2010-07-07 11:33
-rwxrwxrwx 1 peter peter 375599668 2010-07-13 22:10
-rwxrwxrwx 1 peter peter 85249810 2010-07-13 22:27
-rwxrwxrwx 1 peter peter 366895488 2010-07-13 23:40
-rwxrwxrwx 1 peter peter 82427970 2010-06-11 13:03
drwxrwxrwx 2 peter peter 4096 2012-05-02 17:20
drwxrwxrwx 2 peter peter 4096 2012-04-15 21:26
-rwxrwxrwx 1 peter peter 10729820 2011-09-02 01:13
-rwxrwxrwx 1 peter peter 585396006 2011-09-02 05:36
-rwxrwxrwx 1 peter peter 60288740 2010-07-13 23:55
drwxrwxrwx 2 peter peter 4096 2012-04-15 21:28
-rwxrwxrwx 1 peter peter 252268774 2011-01-28 22:06
-rwxrwxrwx 1 peter peter 391326338 2010-10-07 11:16
-rwxrwxrwx 1 peter peter 880512 2010-07-13 23:55
-rwxrwxrwx 1 peter peter 391490910 2010-07-14 02:09
-rwxrwxrwx 1 peter peter 210503670 2010-07-14 02:53
-rwxrwxrwx 1 peter peter 9317106 2010-07-14 02:55
-rwxrwxrwx 1 peter peter 193991758 2010-07-10 19:51
-rwxrwxrwx 1 peter peter 164895128 2010-07-10 19:16
-rwxrwxrwx 1 peter peter 336258132 2010-07-14 04:02
-rwxrwxrwx 1 peter peter 377241014 2010-07-14 06:39
-rwxrwxrwx 1 peter peter 206986182 2010-08-03 13:18
-rwxrwxrwx 1 peter peter 207144174 2011-01-28 22:41
drwxrwxrwx 2 peter peter 4096 2012-04-15 21:30
-rwxrwxrwx 1 peter peter 280058334 2010-07-14 08:25
-rwxrwxrwx 1 peter peter 400122904 2010-07-14 09:59
-rwxrwxrwx 1 peter peter 355505340 2010-07-14 11:15
-rwxrwxrwx 1 peter peter 1629698 2010-07-09 10:32
-rwxrwxrwx 1 peter peter 54876218 2010-07-09 02:09
-rwxrwxrwx 1 peter peter 60964312 2010-07-09 10:04
-rwxrwxrwx 1 peter peter 81278384 2010-07-09 03:12
drwxrwxrwx 2 peter peter 4096 2012-04-15 21:21
-rwxrwxrwx 1 peter peter 186653636 2010-07-11 17:07
-rwxrwxrwx 1 peter peter 170895292 2010-07-11 14:44
-rwxrwxrwx 1 peter peter 204297786 2010-07-11 16:17
-rwxrwxrwx 1 peter peter 2300108 2010-07-11 16:17
drwxrwxrwx 2 peter peter 4096 2012-04-15 21:31
-rwxrwxrwx 1 peter peter 234939292 2011-01-31 11:43
-rwxrwxrwx 1 peter peter 268185782 2011-08-29 01:47
drwxrwxrwx 2 peter peter 4096 2012-04-15 21:32
-rwxrwxrwx 1 peter peter 106313888 2011-01-29 03:57
-rwxrwxrwx 1 peter peter 166931456 2010-07-14 12:45
-rwxrwxrwx 1 peter peter 108903790 2011-01-29 05:09
-rwxrwxrwx 1 peter peter 91363860 2011-08-29 02:06
-rwxrwxrwx 1 peter peter 304870700 2010-07-14 14:16
-rwxrwxrwx 1 peter peter 190097174 2010-07-14 14:47
-rwxrwxrwx 1 peter peter 318581526 2010-07-14 16:07
-rwxrwxrwx 1 peter peter 110195054 2011-01-29 06:20
-rwxrwxrwx 1 peter peter 177844676 2011-01-29 07:13
-rwxrwxrwx 1 peter peter 128654184 2010-07-14 16:50
-rwxrwxrwx 1 peter peter 3639182 2010-07-09 10:06
-rwxrwxrwx 1 peter peter 187511834 2010-07-14 17:37
-rwxrwxrwx 1 peter peter 162239690 2010-07-14 18:09
-rwxrwxrwx 1 peter peter 161978892 2010-07-14 18:43
-rwxrwxrwx 1 peter peter 167166646 2010-07-14 19:15
-rwxrwxrwx 1 peter peter 359254602 2010-07-14 20:37
-rwxrwxrwx 1 peter peter 175587914 2010-07-14 21:22
-rwxrwxrwx 1 peter peter 180623782 2010-07-14 22:02
-rwxrwxrwx 1 peter peter 109935938 2010-07-14 22:37
-rwxrwxrwx 1 peter peter 102084854 2010-07-14 23:01
-rwxrwxrwx 1 peter peter 124796268 2010-07-14 23:29
-rwxrwxrwx 1 peter peter 179226782 2011-01-29 08:03
-rwxrwxrwx 1 peter peter 179236886 2011-01-29 08:51
-rwxrwxrwx 1 peter peter 212939748 2011-01-29 10:02
-rwxrwxrwx 1 peter peter 8203926 2011-01-29 08:54
-rwxrwxrwx 1 peter peter 502460098 2010-07-15 01:45
-rwxrwxrwx 1 peter peter 136483292 2010-07-15 02:14
drwxrwxrwx 2 peter peter 4096 2012-04-15 21:33
-rwxrwxrwx 1 peter peter 201250000 2010-07-15 15:07
-rwxrwxrwx 1 peter peter 527442274 2010-07-15 16:59
-rwxrwxrwx 1 peter peter 48534420 2010-07-15 17:11
-rwxrwxrwx 1 peter peter 102575160 2010-07-15 17:31
-rwxrwxrwx 1 peter peter 146239772 2010-07-15 17:51
-rwxrwxrwx 1 peter peter 1855564 2010-07-09 10:06
peter@Petes-ubuntu-pc:~$

Must be sommat to do with the app then ???

Confused.com :o

Have you looked on the Gui (under options) and see if you can put a check mark into
the box by “Recurse into folders”. Or is that option not available anymore?
http://www.ubuntugeek.com/prefixsuffix-gui-application-that-renames-batches-of-files-in-ubuntu.html

Sorry didn’t reply earlier, been busy.
Here’s a screenshot of my settings

What’s the output from:

la -l /media/Drive3

and

la -l /media/Drive3

and

la -l /media/Drive3/Films

peter@Petes-ubuntu-pc:~$ la -l /media/Drive3
total 48
drwxrwxr-x 3 peter peter 4096 2012-05-03 10:20 Catherine Cooksom
drwxrwxrwx 31 peter peter 12288 2012-05-01 16:15 Films
drwx------ 2 peter root 16384 2012-04-15 18:04 lost+found
drwxrwxrwx 31 peter peter 12288 2012-05-02 18:17 Porn :o
drwx------ 5 peter peter 4096 2012-04-17 01:12 .Trash-1000
peter@Petes-ubuntu-pc:~$

la -l /media/Drive3

[/quote]
Same as above

la -l /media/Drive3/Films

[/quote]
peter@Petes-ubuntu-pc:~$ la -l /media/Drive3/Films
total 116
drwxrwxrwx 6 peter peter 4096 2012-04-30 02:20 Classic Disney Movies 1
drwxrwxrwx 4 peter peter 4096 2012-04-29 16:51 Films 0-9
drwxrwxrwx 9 peter peter 4096 2012-04-22 10:44 Films A
drwxrwxrwx 7 peter peter 4096 2012-04-22 10:42 Films B
drwxrwxrwx 4 peter peter 4096 2012-04-22 10:46 Films C
drwxrwxrwx 5 peter peter 4096 2012-04-22 10:59 Films D
drwxrwxrwx 3 peter peter 4096 2012-04-22 11:01 Films E
drwxrwxrwx 8 peter peter 4096 2012-04-22 11:02 Films F
drwxrwxrwx 3 peter peter 4096 2012-04-22 11:04 Films G
drwxrwxrwx 5 peter peter 4096 2012-04-21 22:32 Films H
drwxrwxrwx 6 peter peter 4096 2012-04-21 22:32 Films I
drwxrwxrwx 4 peter peter 4096 2012-04-21 22:32 Films J
drwxrwxrwx 4 peter peter 4096 2012-04-21 22:32 Films K
drwxrwxrwx 4 peter peter 4096 2012-04-21 22:33 Films L
drwxrwxrwx 6 peter peter 4096 2012-05-02 02:21 Films M
drwxrwxrwx 4 peter peter 4096 2012-04-22 11:52 Films N
drwxrwxrwx 4 peter peter 4096 2012-05-01 19:53 Films O
drwxrwxrwx 29 peter peter 4096 2012-04-21 22:37 Films Off TV
drwxrwxrwx 5 peter peter 4096 2012-04-21 22:37 Films P
drwxrwxrwx 2 peter peter 4096 2010-10-24 23:43 Films Q
drwxrwxrwx 4 peter peter 4096 2012-04-21 22:37 Films R
drwxrwxrwx 12 peter peter 4096 2012-05-01 19:52 Films S
drwxrwxrwx 8 peter peter 4096 2012-04-23 01:05 Films T
drwxrwxrwx 2 peter peter 4096 2012-04-21 22:19 Films U
drwxrwxrwx 2 peter peter 4096 2012-04-23 02:33 Films V
drwxrwxrwx 4 peter peter 4096 2012-04-22 11:15 Films W
drwxrwxrwx 3 peter peter 4096 2012-04-22 11:05 Films X
drwxrwxrwx 2 peter peter 4096 2012-04-22 11:07 Films Y
drwxrwxrwx 2 peter peter 4096 2012-04-21 22:22 Films Z
peter@Petes-ubuntu-pc:~$

Sorry it’s been a few days to reply, been busy.

OK, it’s not a permission issue then ???

Just a though … but try renaming the say, /media/Drive3/Films/Films Off TV directory to /media/Drive3/Films/Films_Off_TV (ie. removing the spaces in the directory name) … then see if the “recursive” option works, but only in that directory (ie. it works in that directory, but not in the ones with the spaces left in their names).

ie. Try to work out if it’s the spaces in the directory names that’s causing the recursing problem.

Spaces in directory and file names can sometimes be a PITA, try to get into the habit of not using them :wink:

Question - why do you want to change the extension in the first place ?

Tried it, no difference, won’t rename

Dunno then … app must be broken :o

Question - why do you want to change the extension in the first place ?

Will it help to uninstall then re-install?

Question - why do you want to change the extension in the first place ?

Dunno really, don’t like the extension, kinda reminds me of Window$ and I Window$ (And the hassle I had with the makers of DivX)

I doubt if a reinstall will work … it’s more likely the app ust doesn’t work as it should … but you can try if you wish:

sudo apt-get install --reinstall prefixsuffix

.divx files are opening in the right application aren’t they ? … ie. you’re not doing this because you think you have* to are you ?