Announcement

Collapse
No announcement yet.

How Do You Rename Multiple Files Using Console?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How Do You Rename Multiple Files Using Console?

    I have a Podcast directory into which all my video podcasts go into. The directory itself has subdirectories. The file types are usually *.m4v but I have a need to rename all of them to *.mov. When I say "all" I mean everything in the main directory and sub directories.

    I have googled around and found various ways to rename but none of them seem to work for me. I would appreciate it if someone could show me the command / string that would accomplish this.

    Thanks,

    M
    sudo make me rich<br /><br />Kubuntu Gutsy 7.10<br />KDE 3.5<br />Compaq Presario 5000<br />Intel Celeron 1.2 Ghz<br />512 Ram, Riva TNT2 Video Card<br />All the above hardware is 7 year old junk but<br />Linux runs great on it.&nbsp; :&gt<br />Ham Radio Rules

    #2
    Re: How Do You Rename Multiple Files Using Console?

    Look at the command rename in a konsole with man rename

    NAME
    rename - renames multiple files

    SYNOPSIS
    rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

    DESCRIPTION
    "rename" renames the filenames supplied according to the rule specified
    as the first argument. The perlexpr argument is a Perl expression
    which is expected to modify the $_ string in Perl for at least some of
    the filenames specified. If a given filename is not modified by the
    expression, it will not be renamed. If no filenames are given on the
    command line, filenames will be read via standard input.
    Windows no longer obstructs my view.
    Using Kubuntu Linux since March 23, 2007.
    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

    Comment


      #3
      Re: How Do You Rename Multiple Files Using Console?

      You don't have to do any for loops anymore, you can use rename

      First in terminal window change to the directory with cd

      Code:
      cd pathtopodcastdirectory
      Let's do a pwd just to make sure you are, in fact, in the podcast directory.

      Code:
      pwd
      Now we'll execute the command twice. Once with the -n switch. This will give output about what will be changed but won't actually change it. Doublecheck the output to make sure it is correct.

      Code:
      rename -n 's/\.m4v$/\.mov/' *.m4v
      If the directory has a huge number of files you can run this instead and redirect the output to junkresults.txt file in the same directory and open it in a text editor to more conveniently check.

      Code:
      rename -n 's/\.m4v$/\.mov/' *.m4v > junkresults.txt
      Now we'll actually change the names with verbose for output and send results to file named changeresults

      Code:
      rename -v 's/\.m4v$/\.mov/' *.m4v > changeresults.txt

      Comment


        #4
        Re: How Do You Rename Multiple Files Using Console?

        I guess I should add that I tested the output I gave you on a junk directory on my own system but it is always best to backup before doing any major change just in case.

        Comment


          #5
          Re: How Do You Rename Multiple Files Using Console?

          As did I - tested it on a separate directory. Nice and easily understandable instructions. Thank you.
          Windows no longer obstructs my view.
          Using Kubuntu Linux since March 23, 2007.
          "It is a capital mistake to theorize before one has data." - Sherlock Holmes

          Comment


            #6
            Re: How Do You Rename Multiple Files Using Console?

            Ohhh that is sweeeeet!

            Man, I've got to learn how to use the shell more effectively. Thanks a ton!!

            M
            sudo make me rich<br /><br />Kubuntu Gutsy 7.10<br />KDE 3.5<br />Compaq Presario 5000<br />Intel Celeron 1.2 Ghz<br />512 Ram, Riva TNT2 Video Card<br />All the above hardware is 7 year old junk but<br />Linux runs great on it.&nbsp; :&gt<br />Ham Radio Rules

            Comment


              #7
              Re: How Do You Rename Multiple Files Using Console?

              Okay - I've got to ask. What does the syntax mean? In other words, if I were explaining this command to someone what would I tell them? rename -v 's/\.m4v$/\.mov/' *.m4v looks cool but I've not a clue as to what the syntax is saying. What is "-v"? What does " 's/" mean?

              I'm not a linux programmer - yet. Sure looks fun though!
              sudo make me rich<br /><br />Kubuntu Gutsy 7.10<br />KDE 3.5<br />Compaq Presario 5000<br />Intel Celeron 1.2 Ghz<br />512 Ram, Riva TNT2 Video Card<br />All the above hardware is 7 year old junk but<br />Linux runs great on it.&nbsp; :&gt<br />Ham Radio Rules

              Comment


                #8
                Re: How Do You Rename Multiple Files Using Console?

                Just open a konsole shell and type:
                Code:
                man rename
                But, for everyone else
                RENAME(1) Perl Programmers Reference Guide RENAME(1)

                NAME
                rename - renames multiple files

                SYNOPSIS
                rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

                DESCRIPTION
                "rename" renames the filenames supplied according to the rule specified
                as the first argument. The perlexpr argument is a Perl expression
                which is expected to modify the $_ string in Perl for at least some of
                the filenames specified. If a given filename is not modified by the
                expression, it will not be renamed. If no filenames are given on the
                command line, filenames will be read via standard input.

                For example, to rename all files matching "*.bak" to strip the exten‐
                sion, you might say

                rename ’s/\.bak$//’ *.bak

                To translate uppercase names to lower, you’d use

                rename ’y/A-Z/a-z/’ *

                OPTIONS
                -v, --verbose
                Verbose: print names of files successfully renamed.

                -n, --no-act
                No Action: show what files would have been renamed.

                -f, --force
                Force: overwrite existing files.

                ENVIRONMENT
                No environment variables are used.

                AUTHOR
                Larry Wall

                SEE ALSO
                mv(1), perl(1)

                DIAGNOSTICS
                If you give an invalid Perl expression you’ll get a syntax error.

                BUGS
                The original "rename" did not check for the existence of target file‐
                names, so had to be used with care. I hope I’ve fixed that (Robin
                Barker).

                perl v5.8.8 2007-03-06 RENAME(1)
                Windows no longer obstructs my view.
                Using Kubuntu Linux since March 23, 2007.
                "It is a capital mistake to theorize before one has data." - Sherlock Holmes

                Comment


                  #9
                  Re: How Do You Rename Multiple Files Using Console?

                  As snowhog said the overall syntax of rename is rename <perlexp to specify how to act on files> files_to_act_on

                  rename -v is verbose output.

                  The *.m4v at the end of the command specifies the files to act on.

                  's/\.m4v$/\.mov/' is the perl expression. Everything is in single quotes to make sure there is no bash shell expansion or substitution. In other words to make sure that the bash shell doesn't muck around with anything within the quotes before passing it to the rename command.

                  The perl expression is the substitution operator s/pattern/replacement/ ... The forward slashes are simply delimiters to separate the pattern from the replacement.

                  \.m4v$ is the pattern. The backslash is the escape character and forces the period after it to be treated as a literal. Otherwise the pattern would interpret the period as the special character which matches any single character except a newline. We want it to be treated literally as a period, not as as special character. The $ is a special character anchor specifying to match only if the .m4v is at the end of the string. For example it will match goof.m4v but not goof.m4vd. This wasn't absolutely necessary but you said that you wanted to match *.m4v and it is a good safety since I don't know what is in your directory and we want to be sure not to catch something unexpected.

                  The \.mov is explained similarly and is what we replace the previous pattern match with, a literal period followed by mov.

                  Comment


                    #10
                    Re: How Do You Rename Multiple Files Using Console?

                    Earlier:
                    Topic: Rename Multiple Files
                    http://kubuntuforums.net/forums/index.php?topic=12032.0

                    Topic: Sorting Files
                    http://kubuntuforums.net/forums/inde...opic=3085680.0

                    =>

                    gwenrename
                    Batch renamer tool for KDE

                    GwenRename is a series renamer tool. It was created as an external tool for GwenView, the image viewer for KDE, but can also be used from Konqueror. As that, the files to be renamed are passed to it as command line parameters, and there is no other way to load files into it. The main goal is to have a batch renaming tool that's easy and light enough for every day use. If you are looking for a more compound and featured renaming tool, you should have a look at Dominik Seichter's "KRename".
                    Kde-apps
                    http://www.kde-apps.org/content/show...?content=11844

                    GwenRename - An external tool for GwenView
                    http://members.hellug.gr/sng/gwenrename/


                    krename
                    Powerful batch renamer for KDE 3.x
                    This package contains a very powerful batch file renamer for KDE3
                    which can rename a list of files based on a set of expressions.
                    It can copy/move the files to another directory or simply rename
                    the input files.

                    Homepage: http://www.krename.net
                    Before you edit, BACKUP !

                    Why there are dead links ?
                    1. Thread: Please explain how to access old kubuntu forum posts
                    2. Thread: Lost Information

                    Comment

                    Working...
                    X