Convert from Nikon RAW .NEF to JPEG?

Why waste time with CPU/GPU consuming GUI apps on Linux to get your photos converted from Nikon RAW files to JPEG?

Here is how to do it:

  1. Create a folder on your Linux box in a file system free enough to hold the data to be copied x2, that is if you have 4 GB for example, make sure it can take around 9 GB, for the time being
  2. copy the NEF files into this folder
  3. run the following shell script

for i in `ls *.NEF`
exiftool -b -JpgFromRaw $i > $i.JPG
rm -rf $i

Now you have your photos converted into JPEG format with the names DSC_xxx.NEF.JPG

if you want to rename it to be DSC_xxx.jpg, then I know one lame method to do so as follows:

  1. Type: >process
  2. Then Type:
  3. for i in `ls *.JPG`
    echo “mv $i $i” > process

  4. Type: vi process
  5. Now you are editing a file containing all File Names
  6. Press Escape, then type the following:
  7. :0,$s/NEF\.JPG/jpg/g

  8. then press Enter, and wait for it to finish
  9. then press Esc
  10. then type :wq
  11. then enter
  12. now type chmod +x process
  13. then ./process

now your files are ready with the desired format



  1. Carl Williams Said:

    Good hint, but one thing struck me here right away which might
    cause some consternation, if people follow this without really
    understanding it and fail to notice the crucial word “copy” in
    step 2:

    Beware that the line ‘rm -rf $i’ will DELETE
    the .NEF files, so leave out this line if you
    haven’t got copies anywhere – it’s not a good idea to discard
    your “digital negatives”, JPEGs contain much less information

    Neither is it generally a good idea to stick rm -rf in for
    loops, these things can get messy (see below).

    Be aware that this general for loop approach to iterating over lists
    of files can present problems if the resulting file paths
    or names contain spaces, and it is limited to however many file
    names will fit on a single command line (the for i in … command).

    Oh, and with the for … construct, you don’t need the ls – the shell will
    expand *.NEF to a list of NEF file names by itself.

    For a more general approach, use xargs or find | while, xargs
    is easier. Further, to substitute the file names more elegantly,
    y’can use “basename”, e.g.

    for n in *.NEF ; do dcraw $n | cjpeg >`basename $n “.NEF”`.jpg ; done

    or if using bash, use shell string substitution, e.g.

    for n in *.NEF ; do dcraw $n | cjpeg >${n/%NEF/JPG} ; done

    Ohyeah, if you don’t have exiftool, y’can use dcraw (search for Dave Coffin’s
    dcraw) and cjpeg (or ImageMagick) instead, per the examples above.

    As always with *nix, there are hundreds of ways to skin any particular cat…

    But whichever you do, I wouldn’t recommend deleting your raw (NEF) files, and
    I’d be VERY wary of including rm -rf in a script which might run away and
    do things you weren’t expecting – e.g. if you have a file called “Picture of cat.nef”

    for n in *.png ; do convert $n ${n/%png/jpg} ; rm -rf $n ; done

    will do:

    convert Picture Picture; rm -rf Picture
    convert of of; rm -rf of
    convert cat.png cat.jpg ; rm -rf cat.png

    Which might not be what you want, especially if you also have a directory called “Picture”.

    • freeproudworld Said:

      Thanks for the hints, I will try it out next time

  2. Carl Williams Said:

    For “Picture of cat.nef” read “Picture of cat.png” in the last example, sorry.

{ RSS feed for comments on this post} · { TrackBack URI }

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: