Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How do you rename, or change permissions on many files?

**Note** there are SUDO commands here that can potentially wreck up your system. If you have questions about this stuff, post in the forum or ask someone verbally to help. The sudo command can really cause problems if you're not entirely sure what you're doing.

I had an issue a while ago where I had to rename about 400 pictures all in the same folder. They were all named by a students PEN #. I needed an incremental number starting at 001.jpg. I was hoping to figure out a script either in apple script or in terminal that would do the job. I called a friend of mine at another school with my problem (he's a windows guy) and he had this great idea.


First of all, using terminal list all the files.

The command is simply "ls" without the quotes.


Select all the files that the ls command outputs and copy it. (command c)

Next, open up excel or numbers or any spreadsheet program, select cell B1 and paste the list of files in question.

When I type SPACE below, I mean hit the space bar.

Now comes the fun part.

In cell A1 type mv SPACE

In Cell C1 type SPACE

In Cell D1 type 001

In Cell E1 type .jpg

In Cell F1 type the following.

Fill down each of the columns to the bottom of the list of file names.


A B C D E F
G
mv pennumber1.jpg 001 .jpg =CONCATENATE(A1..E1)

mv

pennumber2.jpg 002 .jpg =CONCATENATE(A2..E2)
mv pennumber3.jpg 003 .jpg =CONCATENATE(A3..E3)
mv pennumber4.jpg 004 .jpg =CONCATENATE(A4..E4)
mv pennumber5.jpg 005 .jpg =CONCATENATE(A5..E5)


Now Select all of column F and copy it.

Open up terminal and navigate to the folder that's containing all your files to be renamed.

Hit paste and press enter.

This will paste in the contents of each cell in the f column followed by an enter.

Voila!


Now, if you wanted to change ownership of a set of folders, you could use the same process.

I'm assuming that the folder's that your changing are home folders here. In other words, the home folder name should be the same as the shortname of your user.

It might look something like this:


Navigate to the folder that conains your user folders. **CAUTION ----SUDO AHEAD*** This command can BREAK YOUR COMPUTER if you're not careful.

Type: sudo -s

type your password.

Copy the list of Folders from terminal.

Paste them into some column way on the right in excel or numbers or whatever. Maybe column F or something.

Now, in A1 type chmod SPACE and fill it down all the way.

In B1 type -R SPACE and fill it down all the way

In C1 type =F1 SPACE and fill it down all the way

In D1 type =F1 and fill it down all the way

In E1 type =CONCATENATE(A1..D1) and fill it down all the way

The spreadsheet might look like this:


A B C D E F
chmod -R =F1 =F1 =CONCATENATE(A1..D1) thor
chmod -R =F2 =F2 =CONCATENATE(A2..D2) incrediblehulk


Again, just copy and paste column E into terminal and poof! It should work!


*Note, it might be a good idea to run a trial on a folder that's not important to you before you start. These commands you're running can wreck things up pretty good. So ensure things are set up properly before hand!


HTH

-Graham

MacBook Pro, Mac OS X (10.7.3), 13" 2.8 GHz Intel Core i7

Posted on May 14, 2012 10:33 PM

Reply

There are no replies.

How do you rename, or change permissions on many files?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.