Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 20 May 2013, 12:48
All times are UTC - 4
 Forum index » House Training » Beginners Help ( Start Here)
How to rename many files to a unique name?
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [23 Posts]   Goto page: 1, 2 Next
Author Message
shoutcrown

Joined: 12 Mar 2011
Posts: 77

PostPosted: Sat 21 Apr 2012, 21:44    Post subject:  How to rename many files to a unique name?
Subject description: for Lucid - Slacko Puppy linux
 

hello!

Can anybody tell me how to rename many files?.

For example if I had 3 files: tv.mp3, radio.mp3, movie.mp3, then how could I rename them to multimedia-1.mp3, multimedia-2.mp3, multimedia-3.mp3?

That is I just want to change the 3 names (not the extension) to a unique name (the numbers i guess can be added automatically). But i want to keep their own extension.

I would like to rename them at once (not 3 times)

thank you!
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 2199
Location: Gatineau (Qc), Canada

PostPosted: Sat 21 Apr 2012, 23:37    Post subject:  

Hello shoutcrown.

There is an utility called PRename under submenu "FileSystems" that will help you do that in one fell swoop. Smile

Alternatively, cd to the directory where your files are, open a console and copy in it the following:
Code:

rename tv.mp3 multimedia-1.mp3;rename radio.mp3 multimedia-2.mp3;
rename movie.mp3 multimedia-3.mp3


You could also do it with a "for... do" bash loop, but that would be a little involved for only three files.

Regards.

_________________
Wink "...l'industrie de l'informatique n'aura besoin que de très peu de temps pour ramener l'humanité aux dessins rupestres." (M. Goebbel, Order of the Command Line; [ma trad.])
Back to top
View user's profile Send private message Visit poster's website 
postfs1


Joined: 27 Mar 2010
Posts: 831

PostPosted: Sun 22 Apr 2012, 12:20    Post subject: Re: How to rename many files to a unique name?
Subject description: for Lucid - Slacko Puppy linux
 

shoutcrown wrote:
hello!

Can anybody tell me how to rename many files?.

For example if I had 3 files: tv.mp3, radio.mp3, movie.mp3, then how could I rename them to multimedia-1.mp3, multimedia-2.mp3, multimedia-3.mp3?

That is I just want to change the 3 names (not the extension) to a unique name (the numbers i guess can be added automatically). But i want to keep their own extension.

I would like to rename them at once (not 3 times)

thank you!


= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Example-1:
= = = = = = = = = = = = = = = = = = =
find /archive -type f -name "tv*" | sort >lst-1.txt ;
find /archive -type f -name "radio*" | sort >>lst-1.txt ;
find /archive -type f -name "movie*" | sort >>lst-1.txt ;
sleep 0.1s ;
echo multimedia-1.mp3 >lst-2.txt ;
echo multimedia-2.mp3 >>lst-2.txt ;
echo multimedia-3.mp3 >>lst-2.txt ;
sleep 0.1s ;
echo '#!bin/bash' >/archive/lst-1and2.sh ;
paste -d ' ' /archive/lst-1.txt /archive/lst-2.txt | sed 's/^/mv /' | sed 's/$/ ;/' | sed 's/multimedia-/\/archive\/multimedia-/' >>/archive/lst-1and2.sh ;
chmod 0100 /archive/lst-1and2.sh ;
sh /archive/lst-1and2.sh ;

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

_________________
  • I don't know why laboratories are named a hospitals.
  • The alive personage is like a tea bag with granules of unknown density inside, at that one the packet was made of organic material and was placed in the evaporated liquid or liquid.


Last edited by postfs1 on Mon 23 Apr 2012, 05:21; edited 1 time in total
Back to top
View user's profile Send private message 
shoutcrown

Joined: 12 Mar 2011
Posts: 77

PostPosted: Sun 22 Apr 2012, 23:34    Post subject: thank you!  

thank you guys!

Nevertheless I thought there was a short way to rename the files (to rename many files, using Windows, just select them, right click, write a name, and every file could have the same name ordered with a number)

I think musher0 method is shorter than spostfs1

Thank you anyway! I appreciate your skills!

Bye
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 2199
Location: Gatineau (Qc), Canada

PostPosted: Mon 23 Apr 2012, 00:18    Post subject:  

Hi, shoutcrown.

Yeah, some copy operations are less intuitive in Linux, but then, it's part of what makes it more secure.

Thanks for the compliment, BTW.

TWYL.

Chris

_________________
Wink "...l'industrie de l'informatique n'aura besoin que de très peu de temps pour ramener l'humanité aux dessins rupestres." (M. Goebbel, Order of the Command Line; [ma trad.])
Back to top
View user's profile Send private message Visit poster's website 
postfs1


Joined: 27 Mar 2010
Posts: 831

PostPosted: Mon 23 Apr 2012, 05:20    Post subject:  

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Example-2:
= = = = = = = = = = = = = = = = = = =

#Requires the sorting --->>
#find /archive -name tv*.mp3 -or -name radio*.mp3 -or -name movie*.mp3 >/archive/l1 ;
#<<--- Requires the sorting.
ls -1 -R -U /archive/*/tv*.mp3 /archive/*/*/tv*.mp3 /archive/*/radio*.mp3 /archive/*/*/radio*.mp3 /archive/*/movie*.mp3 /archive/*/*/movie*.mp3 >/archive/l1 ;
echo -e "`grep tv /archive/l1|rev|cut -d/ -f2-|rev|uniq`/multimedia-1.mp3\n" "`grep radio /archive/l1|rev|cut -d/ -f2-|rev|uniq`/multimedia-2.mp3\n" "`grep movie /archive/l1|rev|cut -d/ -f2-|rev|uniq`/multimedia-3.mp3"|sed 's/ //' >/archive/l2 ;
paste -d ' ' /archive/l1 /archive/l2 | sed 's/^/mv /' | sed 's/$/ ;/' >/archive/l1andl2 ;
bash -c "`cat /archive/l1andl2`" ;
rm /archive/l1 /archive/l2

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Example-3:
= = = = = = = = = = = = = = = = = = =

find /archive -name tv.mp3 -exec rename tv multimedia-1 {} \;
find /archive -name radio.mp3 -exec rename radio multimedia-2 {} \;
find /archive -name movie.mp3 -exec rename movie multimedia-3 {} \;

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Example-4:
= = = = = = = = = = = = = = = = = = =
#When there is no care about sorting --->>
find /archive -name *.mp3 >/archive/l1 ;
cat /archive/l1|rev|cut -d/ -f2-|rev|sed 's/$/\/.mp3/'|awk '{print $0 NR}'|sed 's/.mp3/multimedia-/'|sed 's/$/.mp3/' >/archive/l2 ;
paste -d ' ' /archive/l1 /archive/l2 | sed 's/^/mv /' | sed 's/$/ ;/' >/archive/l1andl2 ;
bash -c "`cat /archive/l1andl2`" ;
rm /archive/l1 /archive/l2
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

"Quote" mode can help to see the programmatic text

_________________
  • I don't know why laboratories are named a hospitals.
  • The alive personage is like a tea bag with granules of unknown density inside, at that one the packet was made of organic material and was placed in the evaporated liquid or liquid.

Back to top
View user's profile Send private message 
shoutcrown

Joined: 12 Mar 2011
Posts: 77

PostPosted: Mon 23 Apr 2012, 10:24    Post subject: strenght vs facility
Subject description: I prefer the first
 

Hi musher0!, I believe you are right. Everybody needs a powerful operating system like "linux", although there are some things which require a long process.

postfs1 example 3 is getting short, that's great

gracias nuevamente!
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 2199
Location: Gatineau (Qc), Canada

PostPosted: Mon 23 Apr 2012, 22:21    Post subject:  

Hello again, shoutcrown.

To come back on the loop idea, I think this could work.

Code:

# rename loop
# You must run this in the proper folder, where you have ONLY the files to be renamed. Otherwise all the files on your computer might be renamed to "multimedia-[number]" ...  :twisted:
# This is presented for testing purposes only. Use at your own risk.

RN=rename
for i in . # [or put name of folder instead of the dot]
do
 $RN *.mp3 multimedia-$i.mp3
done
#


This has to be refined. I have not tried it. I do not have a big collection of music or movies on my computer!

BFN.

_________________
Wink "...l'industrie de l'informatique n'aura besoin que de très peu de temps pour ramener l'humanité aux dessins rupestres." (M. Goebbel, Order of the Command Line; [ma trad.])
Back to top
View user's profile Send private message Visit poster's website 
shoutcrown

Joined: 12 Mar 2011
Posts: 77

PostPosted: Tue 24 Apr 2012, 14:51    Post subject: hi musher0!
Subject description: applying your method...
 

Well, it's an excellent way to change names, but it doesn't work

I have been trying many times:

- I have tried with Slacko Puppy Linux 531 and Lucid Puppy Linux 528

- I opened the terminal with ("terminal here")

- Also I entered to the directory using commands like "cd...")

- I wrote the commands you say (rename loop...)

After entering the commands there is no change (also terminal doesn't show any error message). So maybe there is some specific charaters or spaces that I can't see when you write

please could you write it again? showing exactly the characteres and spaces

thank you! bye
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 2199
Location: Gatineau (Qc), Canada

PostPosted: Tue 24 Apr 2012, 15:58    Post subject:  

I'll give it another shot. The example I gave was somewhat "theoretical".
Stay tuned.

_________________
Wink "...l'industrie de l'informatique n'aura besoin que de très peu de temps pour ramener l'humanité aux dessins rupestres." (M. Goebbel, Order of the Command Line; [ma trad.])
Back to top
View user's profile Send private message Visit poster's website 
WillM

Joined: 30 Dec 2009
Posts: 99
Location: Oakland, California

PostPosted: Tue 24 Apr 2012, 16:10    Post subject:  

See how this works for you shoutcrown.
Might want to test in another directory with a few files.
Code:

#!/bin/bash

i=1
for file in *.mp3
do
mv "$file" "multimedia-$((i++)).${file#*.}"
done

${file#*.} strip everything from the dot backward
multimedia-$((i++)). rename the files to multimedia-(increment by numbers), and add the dot back into the filename
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 2199
Location: Gatineau (Qc), Canada

PostPosted: Tue 24 Apr 2012, 16:40    Post subject:  

You probably do not need the loop.

The syntax for rename is
rename .txt .text *.txt

In human language:
rename .txt to .text all *.txt files

OR
rename b c b*
rename from b to c all files beginning with b* (the first letter of all files).

It's a bit tricky. But it's a good programming exercise.

That's all the time I have for now. Sorry.
BFN.

_________________
Wink "...l'industrie de l'informatique n'aura besoin que de très peu de temps pour ramener l'humanité aux dessins rupestres." (M. Goebbel, Order of the Command Line; [ma trad.])
Back to top
View user's profile Send private message Visit poster's website 
shoutcrown

Joined: 12 Mar 2011
Posts: 77

PostPosted: Tue 24 Apr 2012, 19:31    Post subject: IT'S ME!
Subject description: IT WORKS!
 

Hi WillM!:

Your method works! Thank you very much!
As you say I tested using a directory with files which aren't important, and I could rename them, keeping their extension, at once (even I didn't need to try 2 times!).

Hi Musher0!

Unfortunately, I can't do it with your method yet. But as I described I don't want to change the extension. Also some times I want to change the names which have completely different names (even there are no letters in common). Thank you anyway

Well this question is really solved! (a short way to rename many files at once, keeping their own extension)

Thank you guys!
Back to top
View user's profile Send private message 
don570


Joined: 10 Mar 2010
Posts: 2457
Location: Ontario

PostPosted: Wed 25 Apr 2012, 17:26    Post subject:  

I wrote a right click utility 'rename-files'

Just right click on a folder.


http://murga-linux.com/puppy/viewtopic.php?t=76919

_______________________________________________
Back to top
View user's profile Send private message 
shoutcrown

Joined: 12 Mar 2011
Posts: 77

PostPosted: Wed 25 Apr 2012, 22:24    Post subject: ABOUT package Rename files
Subject description: Testing!
 

Hi don570!

The method using terminal works fine, I think this package is different, because I can see the options:

- change extension to a new extension...
- Add characters to the file name...
- Number files in the folder...
- Replace white space... with underscore...

But I don't want to change the extension, also It's better to change to whole name than to add characters and numbers or replacing white spaces

Thank you anyway!
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [23 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Beginners Help ( Start Here)
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0739s ][ Queries: 12 (0.0052s) ][ GZIP on ]