Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

The question is completely rewritten due to things learned from the first two answers and comments that I was unaware of when first asking.


After a photo shoot I come home with files that look like _DSC1234.NEF. NEF is Nikon's camera raw file format, so EXIF data is present in the files.

I would like to automatically rename them with three parts:

  1. Creation date in the format YYYYMMDD
  2. Name of Shoot
  3. Number of Image

So the final file name should look like this

20140707_NameOfShoot_0001.NEF

There are a few issues:

ad 1. Creation date sometimes I can only copy and rename the files a few days after shooting, so the date should reflect the date the picture was taken, not the date it was copied. mtime seems like the best bet here or if possible creation date from EXIF.

ad 2: Name of Shoot This would ideally be a variable I could set as a parameter on calling the script.

ad 3. Number of Image This should reflect the age of the image, the oldest having the lowest number. The problem is that cameras usually restart numbering at 0000 after they hit 9999. So 9995-9999 can potentially be older than 0000-0004. I am looking for a solution that reflects file age and in this special case would rename

  • _DSC0000.NEF -> 20140707_FOO_0004.NEF
  • _DSC0001.NEF -> 20140707_FOO_0005.NEF
  • _DSC0002.NEF -> 20140707_FOO_0006.NEF
  • ...
  • _DSC9997.NEF -> 20140707_FOO_0001.NEF
  • _DSC9998.NEF -> 20140707_FOO_0002.NEF
  • _DSC9999.NEF -> 20140707_FOO_0003.NEF

Again, either mtime or if possible creation date from EXIF seem right.


From herehere I have a working solution which renames all .NEF-files in a folder by date:

find -name '*.NEF' | 
gawk 'BEGIN{ a=1 }{ printf "mv %s %04d.NEF\n", $0, a++ }' | 
bash 

Hard coding file-modification-date and the shootname works well, but it would be great if it could be automated.

For the timestamp I find articles on strftime(), mktime(), systime() but I don't understand how to use them to return file modification date. I also tried to add DATE=$(date +"%Y%m%d") and add $DATE to the gawk-line, which leads to deletion of all files in current folder (and probably is systime anyway and not change time).

For the variable, I tried

gawk 'BEGIN{ a=1 }{ printf "mv %s $1_%04d.NEF\n", $0, a++ }' | 

and call the script with ./rename FOO, but FOO is ignored in renaming.

The question is completely rewritten due to things learned from the first two answers and comments that I was unaware of when first asking.


After a photo shoot I come home with files that look like _DSC1234.NEF. NEF is Nikon's camera raw file format, so EXIF data is present in the files.

I would like to automatically rename them with three parts:

  1. Creation date in the format YYYYMMDD
  2. Name of Shoot
  3. Number of Image

So the final file name should look like this

20140707_NameOfShoot_0001.NEF

There are a few issues:

ad 1. Creation date sometimes I can only copy and rename the files a few days after shooting, so the date should reflect the date the picture was taken, not the date it was copied. mtime seems like the best bet here or if possible creation date from EXIF.

ad 2: Name of Shoot This would ideally be a variable I could set as a parameter on calling the script.

ad 3. Number of Image This should reflect the age of the image, the oldest having the lowest number. The problem is that cameras usually restart numbering at 0000 after they hit 9999. So 9995-9999 can potentially be older than 0000-0004. I am looking for a solution that reflects file age and in this special case would rename

  • _DSC0000.NEF -> 20140707_FOO_0004.NEF
  • _DSC0001.NEF -> 20140707_FOO_0005.NEF
  • _DSC0002.NEF -> 20140707_FOO_0006.NEF
  • ...
  • _DSC9997.NEF -> 20140707_FOO_0001.NEF
  • _DSC9998.NEF -> 20140707_FOO_0002.NEF
  • _DSC9999.NEF -> 20140707_FOO_0003.NEF

Again, either mtime or if possible creation date from EXIF seem right.


From here I have a working solution which renames all .NEF-files in a folder by date:

find -name '*.NEF' | 
gawk 'BEGIN{ a=1 }{ printf "mv %s %04d.NEF\n", $0, a++ }' | 
bash 

Hard coding file-modification-date and the shootname works well, but it would be great if it could be automated.

For the timestamp I find articles on strftime(), mktime(), systime() but I don't understand how to use them to return file modification date. I also tried to add DATE=$(date +"%Y%m%d") and add $DATE to the gawk-line, which leads to deletion of all files in current folder (and probably is systime anyway and not change time).

For the variable, I tried

gawk 'BEGIN{ a=1 }{ printf "mv %s $1_%04d.NEF\n", $0, a++ }' | 

and call the script with ./rename FOO, but FOO is ignored in renaming.

The question is completely rewritten due to things learned from the first two answers and comments that I was unaware of when first asking.


After a photo shoot I come home with files that look like _DSC1234.NEF. NEF is Nikon's camera raw file format, so EXIF data is present in the files.

I would like to automatically rename them with three parts:

  1. Creation date in the format YYYYMMDD
  2. Name of Shoot
  3. Number of Image

So the final file name should look like this

20140707_NameOfShoot_0001.NEF

There are a few issues:

ad 1. Creation date sometimes I can only copy and rename the files a few days after shooting, so the date should reflect the date the picture was taken, not the date it was copied. mtime seems like the best bet here or if possible creation date from EXIF.

ad 2: Name of Shoot This would ideally be a variable I could set as a parameter on calling the script.

ad 3. Number of Image This should reflect the age of the image, the oldest having the lowest number. The problem is that cameras usually restart numbering at 0000 after they hit 9999. So 9995-9999 can potentially be older than 0000-0004. I am looking for a solution that reflects file age and in this special case would rename

  • _DSC0000.NEF -> 20140707_FOO_0004.NEF
  • _DSC0001.NEF -> 20140707_FOO_0005.NEF
  • _DSC0002.NEF -> 20140707_FOO_0006.NEF
  • ...
  • _DSC9997.NEF -> 20140707_FOO_0001.NEF
  • _DSC9998.NEF -> 20140707_FOO_0002.NEF
  • _DSC9999.NEF -> 20140707_FOO_0003.NEF

Again, either mtime or if possible creation date from EXIF seem right.


From here I have a working solution which renames all .NEF-files in a folder by date:

find -name '*.NEF' | 
gawk 'BEGIN{ a=1 }{ printf "mv %s %04d.NEF\n", $0, a++ }' | 
bash 

Hard coding file-modification-date and the shootname works well, but it would be great if it could be automated.

For the timestamp I find articles on strftime(), mktime(), systime() but I don't understand how to use them to return file modification date. I also tried to add DATE=$(date +"%Y%m%d") and add $DATE to the gawk-line, which leads to deletion of all files in current folder (and probably is systime anyway and not change time).

For the variable, I tried

gawk 'BEGIN{ a=1 }{ printf "mv %s $1_%04d.NEF\n", $0, a++ }' | 

and call the script with ./rename FOO, but FOO is ignored in renaming.

Completely rewritten dur to things I learned from comments and first two answers
Source Link
jshlke
  • 177
  • 1
  • 6

Add Modification Date Batch rename image files by age plus add date and Variablevariable to Batch Renamefilename

The question is completely rewritten due to things learned from the first two answers and comments that I was unaware of when first asking.


After a photo shoot I wishcome home with files that look like _DSC1234.NEF. NEF is Nikon's camera raw file format, so EXIF data is present in the files.

I would like to batch-renameautomatically rename them with three parts:

  1. Creation date in the format YYYYMMDD
  2. Name of Shoot
  3. Number of Image

So the final file name should look like this

20140707_NameOfShoot_0001.NEF

There are a bunch offew issues:

ad 1. Creation date sometimes I can only copy and rename the files toa few days after shooting, so the date should reflect the date the picture was taken, not the date it was copied. mtime seems like the best bet here or if possible creation date from EXIF.

ad 2: Name of Shoot This would ideally be a variable I could set as a parameter on calling the script.

ad 3. Number of Image This should reflect the age of the image, the oldest having the lowest number. The problem is that cameras usually restart numbering at 0000 after they hit 9999. So 9995-9999 can potentially be older than 0000-0004. I am looking for a solution that reflects file age and in this formatspecial case would rename

<change-date>_<shootname>_<number auto-incremented by modification date>.NEF
  • _DSC0000.NEF -> 20140707_FOO_0004.NEF
  • _DSC0001.NEF -> 20140707_FOO_0005.NEF
  • _DSC0002.NEF -> 20140707_FOO_0006.NEF
  • ...
  • _DSC9997.NEF -> 20140707_FOO_0001.NEF
  • _DSC9998.NEF -> 20140707_FOO_0002.NEF
  • _DSC9999.NEF -> 20140707_FOO_0003.NEF

Again, either mtime or if possible creation date from EXIF seem right.


From here I have a perfectworking solution which renames all .NEF-files in a folder by date:

What I am looking for now is to add theHard coding file-modification-date and the shootname at the beginning. Hard coding it works well, but it would be great if it could be automated. In the the file name should look like this

20140707_NameOfShoot_0001.NEF

For the timestamp I find articles on strftime(), mktime(), systime() but I don't understand how to use them to return file modification date. I also tried to add DATE=$(date +"%Y%m%d") and add $DATE to the gawk-line, which leads to deletion of all files in current folder (and probably is systime anyway and not change time).

A little background on the reason behind this: Cameras usually restart numbering at 0000 after they hit 9999. So 9995-9999 are older than 0000-0004. I am looking for a solution that reflects file age and in this case renames

  • _DSC0000.NEF -> 20140707_FOO_0004.NEF
  • _DSC0001.NEF -> 20140707_FOO_0005.NEF
  • _DSC0002.NEF -> 20140707_FOO_0006.NEF
  • ...
  • _DSC9997.NEF -> 20140707_FOO_0001.NEF
  • _DSC9998.NEF -> 20140707_FOO_0002.NEF
  • _DSC9999.NEF -> 20140707_FOO_0003.NEF

It might happen that I copy and rename the files several days after shooting, so the date of this copy-operation needs to be irrelevant if possible. NEF is Nikon's camera raw format, so EXIF-information is available in the file.

FOO should be a variable I can specify depending on the shoot. I would use it to add the name of the shoot to the filename.


Add Modification Date and Variable to Batch Rename

I wish to batch-rename a bunch of files to this format

<change-date>_<shootname>_<number auto-incremented by modification date>.NEF

From here I have a perfect solution which renames all .NEF-files in a folder by date:

What I am looking for now is to add the file-modification-date and the shootname at the beginning. Hard coding it works well, but it would be great if it could be automated. In the the file name should look like this

20140707_NameOfShoot_0001.NEF

For the timestamp I find articles on strftime(), mktime(), systime() but I don't understand how to use them to return file modification date. I also tried to add DATE=$(date +"%Y%m%d") and add $DATE to the gawk-line, which leads to deletion of all files in current folder (and probably is systime anyway and not change time).

A little background on the reason behind this: Cameras usually restart numbering at 0000 after they hit 9999. So 9995-9999 are older than 0000-0004. I am looking for a solution that reflects file age and in this case renames

  • _DSC0000.NEF -> 20140707_FOO_0004.NEF
  • _DSC0001.NEF -> 20140707_FOO_0005.NEF
  • _DSC0002.NEF -> 20140707_FOO_0006.NEF
  • ...
  • _DSC9997.NEF -> 20140707_FOO_0001.NEF
  • _DSC9998.NEF -> 20140707_FOO_0002.NEF
  • _DSC9999.NEF -> 20140707_FOO_0003.NEF

It might happen that I copy and rename the files several days after shooting, so the date of this copy-operation needs to be irrelevant if possible. NEF is Nikon's camera raw format, so EXIF-information is available in the file.

FOO should be a variable I can specify depending on the shoot. I would use it to add the name of the shoot to the filename.


Batch rename image files by age plus add date and variable to filename

The question is completely rewritten due to things learned from the first two answers and comments that I was unaware of when first asking.


After a photo shoot I come home with files that look like _DSC1234.NEF. NEF is Nikon's camera raw file format, so EXIF data is present in the files.

I would like to automatically rename them with three parts:

  1. Creation date in the format YYYYMMDD
  2. Name of Shoot
  3. Number of Image

So the final file name should look like this

20140707_NameOfShoot_0001.NEF

There are a few issues:

ad 1. Creation date sometimes I can only copy and rename the files a few days after shooting, so the date should reflect the date the picture was taken, not the date it was copied. mtime seems like the best bet here or if possible creation date from EXIF.

ad 2: Name of Shoot This would ideally be a variable I could set as a parameter on calling the script.

ad 3. Number of Image This should reflect the age of the image, the oldest having the lowest number. The problem is that cameras usually restart numbering at 0000 after they hit 9999. So 9995-9999 can potentially be older than 0000-0004. I am looking for a solution that reflects file age and in this special case would rename

  • _DSC0000.NEF -> 20140707_FOO_0004.NEF
  • _DSC0001.NEF -> 20140707_FOO_0005.NEF
  • _DSC0002.NEF -> 20140707_FOO_0006.NEF
  • ...
  • _DSC9997.NEF -> 20140707_FOO_0001.NEF
  • _DSC9998.NEF -> 20140707_FOO_0002.NEF
  • _DSC9999.NEF -> 20140707_FOO_0003.NEF

Again, either mtime or if possible creation date from EXIF seem right.


From here I have a working solution which renames all .NEF-files in a folder by date:

Hard coding file-modification-date and the shootname works well, but it would be great if it could be automated.

For the timestamp I find articles on strftime(), mktime(), systime() but I don't understand how to use them to return file modification date. I also tried to add DATE=$(date +"%Y%m%d") and add $DATE to the gawk-line, which leads to deletion of all files in current folder (and probably is systime anyway and not change time).

further clarified file names and format, explained FOO
Source Link
jshlke
  • 177
  • 1
  • 6

I wish to batch-rename a bunch of files to this format

<change-date>_<shootname>_<number auto-incremented by modification date>.NEF

From here I have a perfect solution which renames all .NEF-files in a folder by date:

find -name '*.NEF' | 
gawk 'BEGIN{ a=1 }{ printf "mv %s %04d.NEF\n", $0, a++ }' | 
bash 

What I am looking for now is to add the file-modification-date and the shootname at the beginning. Hard coding it works well, but it would be great if it could be automated. In the the file name should look like this

20140707_NameOfShoot_0001.NEF

For the timestamp I find articles on strftime(), mktime(), systime() but I don't understand how to use them to return file modification date. I also tried to add DATE=$(date +"%Y%m%d") and add $DATE to the gawk-line, which leads to deletion of all files in current folder (and probably is systime anyway and not change time).

A little background on the reason behind this: Cameras usually restart numbering at 0000 after they hit 9999. So 9995-9999 are older than 0000-0004. I am looking for a solution that reflects file age and in this case renames

  • 0000_DSC0000.NEF -> 000420140707_FOO_0004.NEF
  • 0001_DSC0001.NEF -> 000520140707_FOO_0005.NEF
  • 0002_DSC0002.NEF -> 000620140707_FOO_0006.NEF
  • ...
  • 9997_DSC9997.NEF -> 000120140707_FOO_0001.NEF
  • 9998_DSC9998.NEF -> 000220140707_FOO_0002.NEF
  • 9999_DSC9999.NEF -> 000320140707_FOO_0003.NEF

It might happen that I copy and rename the files several days after shooting, so the date of this copy-operation needs to be irrelevant if possible. NEF is Nikon's camera raw format, so EXIF-information is available in the file.

FOO should be a variable I can specify depending on the shoot. I would use it to add the name of the shoot to the filename.


For the variable, I tried

gawk 'BEGIN{ a=1 }{ printf "mv %s $1_%04d.NEF\n", $0, a++ }' | 

and call the script with ./rename FOO, but FOO is ignored in renaming.

I wish to batch-rename a bunch of files to this format

<change-date>_<shootname>_<number auto-incremented by modification date>.NEF

From here I have a perfect solution which renames all .NEF-files in a folder by date:

find -name '*.NEF' | 
gawk 'BEGIN{ a=1 }{ printf "mv %s %04d.NEF\n", $0, a++ }' | 
bash 

What I am looking for now is to add the file-modification-date and the shootname at the beginning. Hard coding it works well, but it would be great if it could be automated. In the the file name should look like this

20140707_NameOfShoot_0001.NEF

For the timestamp I find articles on strftime(), mktime(), systime() but I don't understand how to use them to return file modification date. I also tried to add DATE=$(date +"%Y%m%d") and add $DATE to the gawk-line, which leads to deletion of all files in current folder (and probably is systime anyway and not change time).

A little background on the reason behind this: Cameras usually restart numbering at 0000 after they hit 9999. So 9995-9999 are older than 0000-0004. I am looking for a solution that reflects file age and renames

  • 0000 -> 0004
  • 0001 -> 0005
  • 0002 -> 0006
  • ...
  • 9997 -> 0001
  • 9998 -> 0002
  • 9999 -> 0003

It might happen that I copy and rename the files several days after shooting, so the date of this copy-operation needs to be irrelevant if possible.


For the variable, I tried

gawk 'BEGIN{ a=1 }{ printf "mv %s $1_%04d.NEF\n", $0, a++ }' | 

and call the script with ./rename FOO, but FOO is ignored in renaming.

I wish to batch-rename a bunch of files to this format

<change-date>_<shootname>_<number auto-incremented by modification date>.NEF

From here I have a perfect solution which renames all .NEF-files in a folder by date:

find -name '*.NEF' | 
gawk 'BEGIN{ a=1 }{ printf "mv %s %04d.NEF\n", $0, a++ }' | 
bash 

What I am looking for now is to add the file-modification-date and the shootname at the beginning. Hard coding it works well, but it would be great if it could be automated. In the the file name should look like this

20140707_NameOfShoot_0001.NEF

For the timestamp I find articles on strftime(), mktime(), systime() but I don't understand how to use them to return file modification date. I also tried to add DATE=$(date +"%Y%m%d") and add $DATE to the gawk-line, which leads to deletion of all files in current folder (and probably is systime anyway and not change time).

A little background on the reason behind this: Cameras usually restart numbering at 0000 after they hit 9999. So 9995-9999 are older than 0000-0004. I am looking for a solution that reflects file age and in this case renames

  • _DSC0000.NEF -> 20140707_FOO_0004.NEF
  • _DSC0001.NEF -> 20140707_FOO_0005.NEF
  • _DSC0002.NEF -> 20140707_FOO_0006.NEF
  • ...
  • _DSC9997.NEF -> 20140707_FOO_0001.NEF
  • _DSC9998.NEF -> 20140707_FOO_0002.NEF
  • _DSC9999.NEF -> 20140707_FOO_0003.NEF

It might happen that I copy and rename the files several days after shooting, so the date of this copy-operation needs to be irrelevant if possible. NEF is Nikon's camera raw format, so EXIF-information is available in the file.

FOO should be a variable I can specify depending on the shoot. I would use it to add the name of the shoot to the filename.


For the variable, I tried

gawk 'BEGIN{ a=1 }{ printf "mv %s $1_%04d.NEF\n", $0, a++ }' | 

and call the script with ./rename FOO, but FOO is ignored in renaming.

further explained numbering
Source Link
jshlke
  • 177
  • 1
  • 6
Loading
explained renumbering better
Source Link
jshlke
  • 177
  • 1
  • 6
Loading
changed request from "creation date" to "change date"
Source Link
jshlke
  • 177
  • 1
  • 6
Loading
Source Link
jshlke
  • 177
  • 1
  • 6
Loading