Terminal command to rename files in bulk with wild cards?

I had a group of files that had double extensions in the name and I wanted to strip the second extension:
myfile.r01.1
myfile.r02.1
so that the new names were
myfile.r01
myfile.r02
In DOS this would be accomplished easily by using the command line:
rename myfile.r??.1 myfile.r??
In OS X Terminal/Bash shell, though I couldn't find a command that has similar function that allows the use of wild cards in the file names.
I tried both the 'mv' abd 'cp' commands along the lines of:
mv myfile.r??.1 myfile.r??
but nothing worked, even using the * for the wildcard.
I did manage to use the Automator to accomplish the task by using some of its Finder options, but really, a simple command line would have been simpler and easier than building an Automator workflow for this.
Can anyone point me to a unix command that would have done what I am looking for, and the proper syntax for it?
Thanks.

From this page: http://www.faqs.org/faqs/unix-faq/faq/part2/section-6.html
How do I rename "*.foo" to "*.bar", or change file names to lowercase?
Why doesn't "mv *.foo *.bar" work? Think about how the shell
expands wildcards. "*.foo" and "*.bar" are expanded before the
mv command ever sees the arguments. Depending on your shell,
this can fail in a couple of ways. CSH prints "No match."
because it can't match "*.bar". SH executes "mv a.foo b.foo
c.foo *.bar", which will only succeed if you happen to have a
single directory named "*.bar", which is very unlikely and almost
certainly not what you had in mind.
Depending on your shell, you can do it with a loop to "mv" each
file individually. If your system has "basename", you can use:
C Shell:
foreach f ( *.foo )
set base=`basename $f .foo`
mv $f $base.bar
end
Bourne Shell:
for f in *.foo; do
base=`basename $f .foo`
mv $f $base.bar
done
Some shells have their own variable substitution features, so
instead of using "basename", you can use simpler loops like:
C Shell:
foreach f ( *.foo )
mv $f $f:r.bar
end
Korn Shell:
for f in *.foo; do
mv $f ${f%foo}bar
done
If you don't have "basename" or want to do something like
renaming foo.* to bar.*, you can use something like "sed" to
strip apart the original file name in other ways, but the general
looping idea is the same. You can also convert file names into
"mv" commands with 'sed', and hand the commands off to "sh" for
execution. Try
ls -d *.foo | sed -e 's/.*/mv & &/' -e 's/foo$/bar/' | sh
A program by Vladimir Lanin called "mmv" that does this job
nicely was posted to comp.sources.unix (Volume 21, issues 87 and
88) in April 1990. It lets you use
mmv '*.foo' '=1.bar'
Shell loops like the above can also be used to translate file
names from upper to lower case or vice versa. You could use
something like this to rename uppercase files to lowercase:
C Shell:
foreach f ( * )
mv $f `echo $f | tr '[A-Z]' '[a-z]'`
end
Bourne Shell:
for f in *; do
mv $f `echo $f | tr '[A-Z]' '[a-z]'`
done
Korn Shell:
typeset -l l
for f in *; do
l="$f"
mv $f $l
done
If you wanted to be really thorough and handle files with `funny'
names (embedded blanks or whatever) you'd need to use
Bourne Shell:
for f in *; do
g=`expr "xxx$f" : 'xxx(.*)' | tr '[A-Z]' '[a-z]'`
mv "$f" "$g"
done
The `expr' command will always print the filename, even if it
equals `-n' or if it contains a System V escape sequence like `c'.
Some versions of "tr" require the [ and ], some don't. It
happens to be harmless to include them in this particular
example; versions of tr that don't want the [] will conveniently
think they are supposed to translate '[' to '[' and ']' to ']'.
If you have the "perl" language installed, you may find this
rename script by Larry Wall very useful. It can be used to
accomplish a wide variety of filename changes.
#!/usr/bin/perl
# rename script examples from lwall:
# rename 's/.orig$//' *.orig
# rename 'y/A-Z/a-z/ unless /^Make/' *
# rename '$_ .= ".bad"' *.f
# rename 'print "$_: "; s/foo/bar/ if <stdin> =~ /^y/i' *
$op = shift;
for (@ARGV) {
$was = $_;
eval $op;
die $@ if $@;
rename($was,$_) unless $was eq $_;

Similar Messages

  • Remote ssh commands with wild cards

    I am trying to send a remote command via ssh - need to get a file listing in a directory using a wild card. However, the ssh command will not return results using a wild card:
    ssh [email protected] sudo ls -l /var/audit-files/201110* (directory requires root permission)
    /var/audit-files/201110*: No such file or directory
    I've tried quoting the command, the directory, the file names, etc - same results. It will only work with a specific name that exists, but not with a wild card. Is there a way to make this work?

    This is a rather complex situation. The problem is that you need to quote the '*' character; however, quoting it once may not be enough. Every time the command goes through a shell you'll strip out a set of quotes. It isn't clear to me how many times this will go through the shell but I'm guessing you'll have to at least double quote it.
    ssh [email protected] sudo ls -l "/var/audit-files/201110\*"
    I won't guarantee that this will work but it might. I don't know what the permissions are on /var/audit_files. If you need root to read that you may need to triple quote it. I've never had much luck getting the quotes right in complicated situations like this.

  • How to create in house distribution provisional profile with wild card?

    Hi,
    I have enrolled for iOS enterprise distribution and created distribution certificate and App-id with wild card (e.g. com.companyname.*) from the portal (not from the xcode).
    When I am trying to create the in house distribution provisional profile from portal, it is not listing the App-id with wild card. I can only create the profile with explicit App-id. I checked with other enterprise account but they are able to create such profiles.
    How can I get in-house distribution profile linked with wild card App-id?
    Thank you.

    Did you find a solution for this? I encounter the same issue.

  • Renaming files in LR5 with the correct date

    I am getting the wrong date when I rename files in LR5. How do I fix it? I hae always used a custom preset
    date (YYYYMMDD)_Custom Text_Sequence #(0001)
    Everything works except the date. What I get is 20130128
    I am using a Nikon Df . I checked the date and time and it is set correctly.
    What should I do?

    If you select one of these "wrongly-dated" photos and look in the Metadata panel (set to display EXIF), what dates do you see listed for Date Time Original, Date Time Digitized and Date Time?

  • Set Bookmark Open Options to Open File with Wild Cards

    Hi there Guys. I need help with something. I work on manuals with various table of contents that contain bookmarks and a lot of them are basically cookie cutter.
    Here is what I am wondering:
    The bookmarks are in numerical order and need to link to an individual PDF
    file in the same folder:
    Example:
    Bookmark 1: "1. Office Hour Files for ABC company dated 10/01/07." needs to link to a file called "Office Hour Files for ABC company dated 10/01/07.PDF".
    Bookmark 2: "1. Healthcare Benefits for ABC company dated 09/30/07."
    needs to link to a file called "1. Healthcare Benefits for ABC company
    dated 09/30/07.PDF".
    ETC.
    Also, the file names -- not the bookmark names -- need to be shortened to 75 characters or less most of the time due to cd burning software. So soemtimes (or most of the time) the file name is much shorter than the original bookmark name.
    Is there code that I can use to batch process the Table of
    Contents file to find bookmark in TOC file that starts with "1. [bookmark name]" and open file the corresponding file in the same folder that starts with "1. [truncated bookmark name].PDF"
    then
    with "2. [full bookmark name]" and open file that starts with "2.
    [truncated bookmark name].PDF"
    and so on maybe through
    with "200. [full bookmark name]" and open file that starts with "200.
    [truncated bookmark name].PDF"
    THANKS SO MUCH... ANY HELP AT ALL WILL BE AWESOME. Also, let me know how
    much it would cost if you know someone who could write the code for me.
    PS: I can use ARTS-PDF software for batchprocessing. I use Acrobat 5.0.
    I really have no reason to upgrade for my purposes, but will if needed. I
    use a lot of keystroke features in 5.0 that are easier to use than in the
    later versions.
    later!!
    THANKS AGAIN!!!!! BE WELL
    KEN

    Hi Dylan,
    I have been searching along our forum, and found a similar question for using wildcards in selecting files. An active user (unclebump) replied on this request with a VI, with which you can select a folder on your computer which is scanned for certain files. I've adjusted this VI for selecting the CALDB_* files. Enclosed you will find this file (zipped) including my test folder.
    Maybe this will be helpfull for your application.
    Best regards,
    Peter Schutte
    Message Edited by Peter S on 10-14-2008 03:22 AM
    Attachments:
    File selecting.zip ‏12 KB

  • QUERY ERROR WITH WILD CARD ON FORM WHEN NO DATA WWC-49102

    Portal 30985 ; database 9014 on sun solaris
    Same server : two databases 9014 : db1 with portal and db2(used here as remote database);
    Step1 ; Create public database link; db_link on db1 through Portal interface;
    Step2 ; create public synonym emp_syn for table emp@db_link through Portal interface;
    Step3 :create form based on emp_syn;
    the form is generated OK and also is behaving OK when Insert,Update,Delete from
    underlying table ;but when I am quering for 758% into the empno field I've got the same error:
    Error: An unexpected error occurred: ORA-00000: normal, successful completion (WWV-16016)
    No conversion performed for type NUMBER, value 758%. (WWC-49102) INSTEAD OF RETURNING EMPTY FORM(NO ROWS)
    I have tryed to query on other fields ;
    querying on a numeric field will give the above message;
    querying on a varchar or date field with or without wild card will raise the following error:Error: An unexpected error occurred: ORA-00000: normal, successful completion (WWV-16016)
    An unexpected error occurred: ORA-00000: normal,successful completion (WWV-16016).
    Lawrence

    Hi Mike,
    You can actually just check for the existence of the cell:
    var l_Cell = $x(pId);
    if (l_Cell)
    rest of the code to hide the column
    }As long as l_Cell refers to a valid page item, then the if test passes and the rest of your code can run.
    Andy

  • Excel opens when i command a .csv file to open with numbers. How can i get numbers to be my default application?

    I am sharing a Macbook Pro with my girlfriend. She runs Microsoft Office Excel for her work and I perfer Numbers in my work. Logged into my user account, I command an email attachment (.csv) to open with numbers. Excel launches every time. I can open numbers first. Excel still launches and opens the .csv document. i tried to trash the excel in my user account, no go. any suggestions?

    Hi joric,
    In Finder, right click or control click on the document and Open With > Numbers.  You may have to navigate from Other...
    Or, a permanent solution:
    In Finder, click once on a .csv document to select it. Get Info (command i) Towards the bottom of that info window, is Open With. It probably shows Excel. Change it to Numbers. Again, you may have to navigate from Other... Then click on Change All.
    I can open numbers first. Excel still launches and opens the .csv document.
    Are you opening from within Numbers (File > Open)?
    Regards,
    Ian.

  • Need terminal command to list files

    i want to find all files of a given kind within a directory, including subdirectories, and list them according to their size. i've looked into the ls and find commands, but i'm totaly new to terminal. could anyone help me?
    to be just a bit more specific:
    i have a folder containing up to three levels of subfolders, and within these, i got some .fbx files.
    i need a list of these, sorted by size

    Works perfect for me. Here's a snapshot of the listing from my MacBook running 10.5.6 using
    ls -RSl | grep '\.txt' | sort -n -k5
    from the HOME folder
    -rw-rw-rw-@ 1 boxerflat4 admin 1569 30 Sep 12:11 log-bb-2008-09-26-stats.txt.submitted
    -rw-r--r-- 1 boxerflat4 admin 1574 24 Jun 2007 layer-stamp.txt
    -rw-rw-rw-@ 1 boxerflat4 admin 1576 22 Sep 11:22 log-bb-2008-09-17-stats.txt.submitted
    -rw-rw-rw-@ 1 boxerflat4 admin 1746 28 Jul 2008 log-bb-2008-07-26-stats.txt.submitted
    -rw-rw-rw-@ 1 boxerflat4 admin 1759 11 Sep 23:53 log-bb-2008-09-10-stats.txt.submitted
    -rw-rw-rw-@ 1 boxerflat4 admin 1819 16 Sep 12:16 log-bb-2008-09-15-stats.txt.submitted
    -rw-rw-rw-@ 1 boxerflat4 admin 1977 21 Jul 2008 log-bb-2008-07-19-stats.txt.submitted
    -rw-rw-rw-@ 1 boxerflat4 admin 1981 21 Jul 2008 log-bb-2008-07-20-stats.txt.submitted
    -rw-r--r-- 1 boxerflat4 admin 2167 8 Jun 2007 readme.txt
    -rw-rw-rw-@ 1 boxerflat4 admin 2309 1 Sep 09:20 log-bb-2008-08-29-stats.txt.submitted
    -rw-rw-rw-@ 1 boxerflat4 admin 2428 12 Sep 22:05 log-bb-2008-09-11-stats.txt.submitted
    -rw-rw-rw-@ 1 boxerflat4 admin 2443 5 Aug 2008 log-bb-2008-08-03-stats.txt.submitted
    -rw-r--r-- 1 boxerflat4 admin 3280 29 Nov 13:22 AMRestoreLog.txt
    -rw-r--r--@ 1 boxerflat4 admin 4082 15 Jul 2007 broadcast email list.txt
    -rw-r--r--@ 1 boxerflat4 boxerflat4 4306 13 Dec 2007 2008MotorsportCalendar.txt
    -rw-r--r-- 1 boxerflat4 admin 7274 5 Aug 2008 MySQLReadMe.txt
    -rw-r--r--@ 1 boxerflat4 boxerflat4 8588 18 Nov 2007 CocktailLogFile.txt
    -rw-r--r--@ 1 boxerflat4 admin 12966 16 Dec 09:46 cookies.txt
    -rw-r--r-- 1 boxerflat4 admin 16500 7 Nov 2007 FileInfoLibPrefs.txt
    -rw-rw-rw- 1 boxerflat4 admin 18211 4 Sep 10:55 rgb.txt
    -rw-r--r-- 1 boxerflat4 admin 19005 14 Jun 2007 VelaCrashDump.txt
    -rw-r--r-- 1 boxerflat4 admin 8973661 9 Dec 12:05 mysqlinfo.txt
    Chris

  • What is the terminal command to rename a folder?

    If someone could tell me this it would awesome.
    thx to all replies

    Use the mv command with the current and desired paths supplied. For example:
    mv ~/Desktop/34 ~/Desktop/35
    for a folder on the desktop.
    (32999)

  • Find Command with Wild Cards

    I have a very specific issue that I need to resolve.....I have the following directory structures on my Linux system
    Test
    ..File 1
    .....Ready
    ........File 1.txt
    ..File 2
    .....Ready
    ........File 2.txt
    ..ect
    These directories will be created dynamically by another process. I need to be able to find all files that are currently under a Ready directory....
    I've tried the following command...
    find -path /Test/*/Ready/* -type f
    find / -path /Test/*/Ready/* -type f
    find -wholename /Test/*/Ready/* -type f
    All of these return the first file's full path, but as part of an error message..The message says "paths must precede expressioons"
    Any ideas on how I can get the following results:
    /Test/File 1/Ready/File 1.txt
    /Test/File 2/Ready/File 2.txt
    Thanks in advance for any help....
    Jay

    Jay,
    I've tried the following command...
    find -path /Test/*/Ready/* -type f
    find / -path /Test/*/Ready/* -type f
    find -wholename /Test/*/Ready/* -type fI think you got the point, but you need quote around the pattern.
    find -path "/Test/*/Ready/*" -type f
    Tiger Zhang
    .

  • Needing assistance with wild card in Crystal 11

    I need a report that captures only certain Employers in our database.   I've used the following criteria with no luck.
    (CH_EMP_NAME)  in ["ACADEMY", "BRISTOL", "WELLMONT"]
    Please advise
    Thanks
    Jack

    Hi Jack,
    The following may help you.
    if {Employee.Last Name} like ["Brid\","chan\"] then // open square bracket of "Brid" , "* chan *" close square bracket
    "B"
    else "C"
    in the group expert select formula field to group.
    Thanks,
    Praveen G

  • Dynamic query with wild card

    Hi,
    I have a table1 like below
    Id (NUMBER) , Keyword (VARCHAR2)
    1,A
    2,B
    3,C
    another table2
    name(VARCHAR2)
    Alice
    Bob
    Jack
    I need to write a stored procedure to check whether name of table 2 mactched any of the keyword char of table1. How to I write dynamic query in my PL/SQL stored procedure so that i can generate query similar to
    SELECT * from table2 where name like '%X%' where i need to replace X with the char in table1
    Please help.
    Thanks in advance,
    Marutha

    I need to write a stored procedure to check whether name of table 2 mactched any of the keyword char of table1You might simply join the tables:
    SQL> with table1  as
    select 1 id, 'A' keyword from dual union all
    select 2 id, 'B' keyword from dual union all
    select 3 id, 'C' keyword from dual
    table2 as (
    select 'Alice' name from dual union all
    select 'Bob' name from dual union all
    select 'Jack' name from dual
    select * from table1, table2 where name like '%' || keyword  || '%'
            ID KEYWORD NAME
             1 A       Alice
             2 B       Bob 
    2 rows selected.

  • How to query with wild card

    hi friends
    we have a requirement where if the user enters a letter in a field of selection-screen, he is supposed to get the fields details with its prefix entered in the selection-screen
    eg: if user enters P and give execute
    he needs to get the details of the particular field starting with P
    how to code this
    with regards
    s.janagar

    Hi,
    Here wildcard character '%' can be used as pattern code. Character and then the '%' sign signifies that all values with character as first letter will be searched upon.
    In your case use of like 'P%' in the where clause of the select statementr should solve the issue. e.g.,
    select * from <tabname> into table <internal table> where <fieldname> like 'P%'.
    searches all entries from table <tabname> and places them in internal table <internal table> where the field <fieldame> begin with P.
    Thanks and Regards,
    Sachin

  • Passwing Parameters with Wild card Charactars

    Using Reports and Forms server, I am passing parameters from a ASP page to a Report.
    When I pass the full parameter to the report, like the word ORACLE, things are great.
    When I try to add a wild card to the parameter, like OR%, things don't work so well. I receive an error:
    "Error: The requested URL was not found, or cannot be served at this time. Oracle Reports Server CGI - Your URL contains badly-formed escapes."
    Any Help?
    Thanks
    Rao

    use hexadecimal value ex. for space it is %20 or u can use
    urlencode function

  • Trying to automate a Terminal command with a password

    Hi,
    I'm a long time Mac user, but not a Terminal expert.
    I've come upon a simple hack that enables me to run two instances of Skype simultaneously. This enables me to use it with two different user names.
    The idea is to create another user on the computer and run the other Skype like this:
    sudo -u user "/Applications/Skype.app/Contents/MacOS/Skype"
    In order to simplify this for daily use, I'd like to create a small applet which runs this terminal command.
    Trying to do so with Automator's +Run Shell Script+ fails with an execution error, probably due to the fact that this sudo command requires an admin password.
    Is there any way to accomplish this?
    Thanks

    hmm... I'm afraid that didn't do the trick. It now opens the Terminal window and launches Skype with the message "another copy of Skype is already running".
    Maybe I should add another step to workflow instead?
    Thanks again, I really appreciate your help.
    Guy

Maybe you are looking for