Rename multiple files

When we want to rename a file (with Linux or Mac OS), we  generally go to the directory of the file and we rename the file. Or for those who prefer doing with the terminal, we use mv

Capture d_écran 2017-04-27 à 22.55.03

And how about multiple file ? How about renaming all episode of Game of Throne ?Capture d_écran 2017-04-27 à 23.02.11

  • How can we remove [TOTO] for every file name ?
  • How can we rename secretFile for every file name ?
  • How can we remove the extension for every file name ?
  • How can we upper case every file name ?
  • and so on …

we generally do

  • one by one
  • or a bash script

are-you-serious-wtf-meme-baby-face

or

Boss-Baby-with-Briefcase01

To rename multiple files, we will use rename. But what’s rename ?

Rename is a program that renames files according to modification rules specified on the command line.

Install rename program

To install rename, we will use homebrew (a package manager for OSX. With homebrew we can install a lot of applications and libraries that would require manual compilation)

  1. open the terminal
  2. enter “brew install rename”
  3. done

Or use Cakebrew (The Mac App for Homebrew)

Capture d’écran 2017-04-27 à 22.27.10.png

Now let’s rename:

Append the string argument you supply to every filename: rename -a ‘ toto’ *
(-a: append the string argument you supply to every filename)

Capture d_écran 2017-04-27 à 23.17.09

Prepend the string argument you supply to every filename: rename -A ‘ toto’ *
(-A: prepend the string argument you supply to every filename)

Capture d’écran 2017-04-27 à 23.18.22.png

Convert file names to all lower case: rename -c -f *
(-c: convert file names to all lower case)
(-f: rename even when a file with the destination name already exists)

Capture d’écran 2017-04-27 à 23.20.15.png

Convert file names to all upper case: rename -C -f *
(-c: convert file names to all upper case)

Capture d’écran 2017-04-27 à 23.19.25.png

Remove the last extension from a filename, if there is any: rename -x *

Capture d’écran 2017-04-27 à 23.21.11.png

Replace all sequences of whitespace in the filename with single underscore characters: rename –nows *

Capture d’écran 2017-04-27 à 23.22.19.png

Replace each underscore in the filename with a space: rename –rews *

Capture d’écran 2017-04-27 à 23.23.21.png

Perform a simple textual substitution of “from” to “to”:
rename -s ‘want to change’ ‘to what we want’ *

Capture d’écran 2017-04-27 à 23.24.53.png

Add increment number for each file in the list from 1: rename -N …01 -X -e ‘$_ = “$_-$N”‘ *
(-X  stand for keep the extension)
(-e stand for expression)
($_ is the name of the file in the expression)
($N is the incrementation number in the expression)

Capture d’écran 2017-04-27 à 23.26.24.png

Add increment number for each file in the list from 3rename -N …03 -X -e ‘$_ = “$_-$N”‘ *

Capture d’écran 2017-04-27 à 23.27.29.png

Throw away all the existing filenames and simply number the files from 1rename -N …01 -X -e ‘$_ = “FileName-$N”‘ *

Capture d’écran 2017-04-27 à 23.28.43.png

That was only the surface of the iceberg. To see other parameter use:

man rename 

Cool isn’t it ?
So let rename it !
359207_m1469233525

Advertisements
Rename multiple files

How to immediately lock your screen in OSX

I never found a way to lock the screen convenient to prevent intrusive people to look at my documents. Actually this functionality present on Windows (windows-key+L) also exists on Mac. Here is the way:

To enable this feature, you will have to go to System Preferences -> Security & Privacy and to the tab General. Then check the box “required password”and set an interval that meets your needs.Screen Shot 2016-01-11 at 12.36.23.png

Now you can lock the screen; simutaneously press Ctrl + Shift + Power (or Ctrl + Shift + Eject for older Macs).

Another handy key combination is Cmd + Option + Power (respectively Cmd + Option + Eject for older Macs) to put your mac into sleep mode.

 

 

How to immediately lock your screen in OSX