A Linux shell script to rename files with a counter and copy them

As a brief note today, I was recently looking for all Messages/iMessage files that are stored on my Mac, and I used this shell script to copy all of those files — many of which have the same name — into a directory named tmpdir, giving them all new names during the copy process:

for i in `cat myfiles`
    fname=`basename $i`
    cp $i tmpdir/${count}-${fname}
    count=`expr $count + 1`

How to rename members on import in Scala

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a short recipe, Recipe 7.3, “How to rename members on import in Scala.”


You want to rename members when you import them to help avoid namespace collisions or confusion.


Give the class you’re importing a new name when you import it with this import syntax:

import java.util.{ArrayList => JavaList}

Then, within your code, refer to the class by the alias you’ve given it:

Typesafe - What is in a name?

(The image shows some comments from the Typesafe page that I linked to in the next paragraph.)

When I first heard that some people at Typesafe wanted to rename their company, I thought, “That’s interesting, but I wonder why?” As I thought about it I came up with names like Concurrence and Datastream.

But then the more I thought about it, I thought, “This is a really bad idea.” A lot of people who know and love Scala and Akka and the Play Framework know the company as Typesafe. The company name takes nothing away from that.

I think everyone’s biggest fear is that they’ll name the company as something related to “reactive,” which is just a marketing buzzword that sounds dumb to a lot of people today and will sound even worse next year. My personal second fear is shown in the comments in the image, that they’ll go from a name like Borland to Inprise, which was a horrible decision (and the company disappeared shortly thereafter).

Think about this for a moment: Apple is the biggest company in the world, and what does the name “Apple” have to do with any product they make?

Scala packaging and import examples

This article is a collection of Scala packaging and import examples. I created most of these examples when I was writing the Scala Cookbook. I share them here without much discussion, but for more examples and discussion, please check out the Cookbook.

Packages imported by default

By default, three packages are implicitly imported for you:

Scala: How to rename a class when you import it (a 'rename on import' syntax example)

Scala offers a cool feature where you can rename a class when you import it, including both Scala and Java classes. The basic syntax to rename a class on import looks like this:

import scala.collection.mutable.{Map => MMap}

and this:

import java.util.{HashMap => JavaMap}

If all you needed to know, I hope those "rename on import" syntax examples were helpful.

Move Linux files and directories with the mv command

Linux move/rename files FAQ: How do I rename or move Linux files and directories?

You use the Linux mv command to rename or move Linux files and directories. Let's look at some move/rename examples.

Using Linux mv to rename files and directories

At its most basic, here's how you rename a Linux file:

mv Chapter1 Chapter1.old

This mv command renames the file Chapter1 to the new filename Chapter1.old. (Renaming a file is the same as moving it.)

Linux mv command man page

This page shows the contents of the Linux mv command man page. The Linux and Unix mv command is used to move and rename files and directories.

This mv command output was created on a CentOS Linux system. You can see this same mv command man page output by entering this command on your own Linux system:

A Unix shell script to rename many files at one time

Summary: A Unix/Linux shell script that can be used to rename multiple files (many files) with one shell script command.


You're on a Mac OS X, Unix, or Linux system, and you'd like to be able to rename a large number of files at once. In particular, you'd like to be able to change the extensions of a large number of files, such as from *.JPG to *.jpg (changing the case of each file extension from upper case to lower case).