Find the answer to your Linux question:
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 21
Yes I did read the man pages and I can not figure out how to do something. I have a list of files wls01 wls02 wls03 .... etc. I need ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2004
    Posts
    85

    Using the Rename Command?


    Yes I did read the man pages and I can not figure out how to do something. I have a list of files wls01 wls02 wls03 .... etc. I need to rename them to wls01.mp3 ... etc. Basically I need to add a .mp3 extension to all files that start with wls. The command I tried to use is as such:

    rename wls** wls**.mp3 wls**

    But it does nothing. No errors, nothing. What's wrong. How would I go about doing this?

    - Bogdan

  2. #2
    Linux Engineer
    Join Date
    Nov 2004
    Location
    Montreal, Canada
    Posts
    1,267
    I never used this renaming command.

    I may be wrong, but this command (like you've put it) cannot be done it this sense.

    Renaming a file must be done to a specific name... so wls**.mp3 doesnt meen nothing to the command line.

    Unless im on crack, this cannot be executed as-is...

    There is a solution thou... its called bash command.
    \"Meditative mind\'s is like a vast ocean... whatever strikes the surface, the bottom stays calm\" - Dalai Lama
    \"Competition ultimatly comes down to one thing... a loser and a winner.\" - Ugo Deschamps

  3. #3
    Just Joined!
    Join Date
    Jul 2004
    Posts
    85
    Don't you think that's kind of stupid. This thing that I am trying to do is quite commonly done, especially on webservers. There has to be a way to do this the easy way. On win copy wls* wls*.mp3 would do the trick. I refuse to believe that it would, or should be harder on linux.

    - Bogdan

  4. #4
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by x0054
    Don't you think that's kind of stupid. This thing that I am trying to do is quite commonly done, especially on webservers. There has to be a way to do this the easy way. On win copy wls* wls*.mp3 would do the trick. I refuse to believe that it would, or should be harder on linux.
    It's common for people to refer to something they aren't familiar with as "stupid". Perhaps there's another command that's more commonly used on Linux. To rename files, for instance, I use the mv command. I'm not entirely sure if it would work for wildcards, but it's worth a shot.
    Registered Linux user #270181
    TechieMoe's Tech Rants

  5. #5
    Just Joined!
    Join Date
    Jul 2004
    Posts
    85
    I did not mean that linux is stupid Just me being pissed after trying to do this for few days now.

    Yeah, I tried mv, the problem is mv can not move multiple files to multiple destinations, it can only move a file to a destination or multiple files to a destination directory. Thus mv could be used like this:

    mv wls* newdir/

    but not like this:

    mv wls* wls*.mp3

    In using the rename command I need a way to append the name instead of changing part of it, and in that lies the problem

    - Bogdan

  6. #6
    Linux Engineer
    Join Date
    Nov 2004
    Location
    home
    Posts
    796
    You could write up a bash function to do it

  7. #7
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by valan
    You could write up a bash function to do it
    That's what I was thinking. You might be able to string together several command-line operations into a shell script.
    Registered Linux user #270181
    TechieMoe's Tech Rants

  8. #8
    Just Joined!
    Join Date
    Jul 2004
    Posts
    85
    I know, and that's not a problem, I can write a loop for it if I wanted to. I just think that I should not have to. I can not believe that something so simple should take half a page of code to do. And I do this all the time, so would probably try to write a generic version, and that's going to be longer.

    - Bogdan

  9. #9
    Linux Engineer
    Join Date
    Nov 2004
    Location
    Montreal, Canada
    Posts
    1,267
    Quote Originally Posted by techieMoe
    Quote Originally Posted by valan
    You could write up a bash function to do it
    That's what I was thinking. You might be able to string together several command-line operations into a shell script.
    Quote Originally Posted by UgoDeschamps
    There is a solution thou... its called bash command.
    But again that's stupid no?
    sorry to sound ironic mate but if it was that stupid wouldnt be the one giving the answer and not asking for it?

    the answer is, No it's no dumb, stupid or strange... as Microsoft windows simply made a "nicer" version of "CP" It doesnt take a full page to write this. I'll explain the very simple algorith behind all this, and you'll be able to use it in no time

    Code:
    I have some files in a directory, called
    prefix-file1, prefix-file2, etc
    
    lets rename them to 
    file1.mp3, file2.mp3, etc
    
    for file in prefix-* ; 
    do
    mv "$file" "${file##prefix-}"
    Fairly simple took 3 line of code, hopefully this isnt that hard and not to "stupid"
    \"Meditative mind\'s is like a vast ocean... whatever strikes the surface, the bottom stays calm\" - Dalai Lama
    \"Competition ultimatly comes down to one thing... a loser and a winner.\" - Ugo Deschamps

  10. #10
    Just Joined!
    Join Date
    Jul 2004
    Posts
    85
    You of course realize that that does not actually work. Perhaps I am missing something.

Page 1 of 3 1 2 3 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •