Read & Remove EXIF Data From the Command Line

Most digital cameras will insert metadata into images. This metadata is stored using the exchangeable image file format (EXIF) and can contain camera specifications, exposure settings, thumbnails, GPS coordinates and more. This article outlines some Linux command line tools you can use for reading, editing and removing EXIF metadata from images.

Reading and Editing EXIF Metadata with ExifTool

ExifTool is powerful a Perl program that can be used to read and edit EXIF metadata in images. To install ExifTool as /usr/bin/exiftool on Fedora, install the perl-Image-ExifTool package:

su -c 'yum install perl-Image-ExifTool'

Alternatively, you can use CPAN to install ExifTool in /usr/local/bin/exiftool.

su -c "perl -MCPAN -e'install Image::ExifTool'"

After installation, you will have the exiftool command available in /usr/bin or /usr/local/bin. To view the EXIF metadata in an image, just past the image as an argument to exiftool.

exiftool dsc_0790.jpg

Here is a snippet of the output from the above command:

ExifTool Version Number         : 7.60
File Name                       : dsc_0790.jpg
Directory                       : .
File Size                       : 4.4 MB
File Modification Date/Time     : 2008:07:16 09:45:20-07:00
File Type                       : JPEG
MIME Type                       : image/jpeg
Exif Byte Order                 : Big-endian (Motorola, MM)
Make                            : NIKON CORPORATION
Camera Model Name               : NIKON D200
Orientation                     : Horizontal (normal)
X Resolution                    : 300
Y Resolution                    : 300
Resolution Unit                 : inches
Software                        : Bibble 4.10a
Modify Date                     : 2007:06:23 22:00:14
Exposure Time                   : 1/40
F Number                        : 2.0
Exposure Program                : Aperture-priority AE
ISO                             : 100
.
.
.

ExifTool has many options for editing and removing EXIF metadata in images. To see the available options, use the –help switch or read the ExifTool documentation.

exiftool --help

Reading EXIF Metadata with Jhead

Jhead is a command line tool for displaying EXIF data embedded in JPEG images. On Fedora, use Yum to install Jhead:

su -c 'yum install jhead'

Now, use /usr/bin/jhead to read EXIF metadata:

jhead dsc_0790.jpg

Here is an example of the output produced by the jhead command:

File name    : dsc_0790.jpg
File size    : 4654488 bytes
File date    : 2008:07:16 09:45:20
Camera make  : NIKON CORPORATION
Camera model : NIKON D200
Date/Time    : 2007:06:23 22:00:14
Resolution   : 3880 x 2608
Flash used   : No
Focal length : 50.0mm  (35mm equivalent: 75mm)
Exposure time: 0.025 s  (1/40)
Aperture     : f/2.0
ISO equiv.   : 100
Exposure bias: 1.00
Whitebalance : Auto
Exposure     : aperture priority (semi-auto)
GPS Latitude : ? ?
GPS Longitude: ? ?
======= IPTC data: =======
(C)Flag       : 0
DateCreated   : 20070623
Time Created  : 220014
Record vers.  : 4

Removing EXIF Metadata with ImageMagick

If you need to strip the EXIF metadata from images, use ImageMagick’s mogrify command. To install ImageMagick on Fedora, use Yum:

su -c 'yum install ImageMagick'

After ImageMagick is installed, you will have /usr/bin/mogrify available. The mogrify command can be used to strip Exif data from images.

mogrify -strip imagename.jpg

If you need to process a large number of files, use find and xargs:

find ./folder_of_images -name '*.jpg' | xargs mogrify -strip

Fedora 10 Rar and Unrar

By default, Rar is not available in Fedora 10. If all you need to do is extract files from a Rar archive, unrar from RPM Fusion’s YUM repositories will work. If you need to create Rar archives, then you will have to download and install the complete Rar package from DAG. The instructions below show you how.

Only Need to Extract Files?

First, install RPM Fusion’s free and nonfree YUM repositories. For detailed information about installing RPM Fusion, see: http://rpmfusion.org/Configuration

su -c "rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm"
su -c "rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm"

Next, install the unrar packages from RPMFusion’s nonfree repository.

su -c "yum install unrar"

Done! You now have unrar in /usr/bin/unrar. This binary can only extract files from Rar archives. Use this command to see all available options:

/usr/bin/unrar -?

Need to Create Rar Archives?

First, download the source RPM from DAG: http://dag.wieers.com/rpm/packages/rar

wget -c http://dag.wieers.com/rpm/packages/rar/rar-3.5.1-1.rf.src.rpm

Now, install the source RPM. This will create a $HOME/rpmbuild tree. Please note that you do not need to be root.

rpm -iv  rar-3.5.1-1.rf.src.rpm

Next, build a binary package in $HOME/rpmbuild. Again, no need to be root.

rpmbuild -bb ~/rpmbuild/SPECS/rar.spec

Finally, install the built RPM as root:

su -c "rpm -Uvh $HOME/rpmbuild/RPMS/$(arch)/rar-3.5.1-1.rf.x86_64.rpm"

Done! You now have rar in /usr/bin/rar. This binary can build and extract Rar files. Use this command to see all available options:

/usr/bin/rar -?

iTunes on Linux with Wine

iTunes for Windows XP can be run on Fedora 9 using Wine, an Open Source implementation of the Windows API on top of X and OpenGL. Please note that iTunes runs a bit slow over Wine and I have yet to test an iPhone or iPod with this configuration.

First, install all the wine packages.

sudo yum install wine*

Now, install the pulseaudio alsa plugin for sound support

sudo yum install alsa-plugins-pulseaudio*

Next, download the Windows XP iTunesSetup.exe from Apple.

firefox http://www.apple.com/itunes/download/

Now, install iTunes using wine

/usr/bin/wine iTunesSetup.exe

You can now run iTunes manually like so:

env WINEPREFIX="$HOME/.wine" wine "C:\Program Files\iTunes\iTunes.exe"

If you get an error regarding the registry, ignore it by clicking OK.

Here is a screenshot of iTunes running on Fedora 9. Note that there is an icon for iTunes in Gnome’s Notification Area (system tray).

For more information see the iTunes application page at winehq.org.

Quick and Dirty MySQL Backup

So you need to backup all the MySQL databases on your system? This is easy with MySQL’s mysqldump. The quickest solution is to
dump all databases to one ugly file:

mysqldump -u root -p --all-databases > $(hostname)-everything.sql

A more organized approach is to loop through all your databases and dump individual files. A Bash script example:

#!/bin/bash
read -p  "Enter MySQL user: " -s DBUSER
read -p  "Enter MySQL $DBUSER password: " DBPASS
DATE=$(date +'%m%d%Y')
# dump all databases to current path
for DB in $(echo "show databases" | mysql -u$DBUSER -p$DBPASS | grep -v Database); do
   mysqldump -u$DBUSER -p$DBPASS $DB > $DB-$DATE.sql || exit $?
   gzip $DB-$DATE.sql || exit $?
done && exit $?

Sources

MySQL.com: MySQL AB :: MySQL 5.0 Reference Manual :: 8.13 mysqldump A Database Backup Program

Removing leading `/’ from member names

Have you ever seen this error when using tar?

tar -czf etc.tgz /etc
Removing leading `/' from member names

Tar is removing the leading / from the archive file, and warning you about it. Although you can redirect STDERR to /dev/null, doing so can result in missed errors. Instead, use tar with the -P or –absolute-names switch. They do the same thing: leave the leading / in the archived files.

tar -czPf etc.tgz /etc

When you untar the archive without -P, the leading / will still equate to your current working directory. Use the -P when untarring to restore from archive to the absolute path name. For example:

The following creates ./etc (dot, slash, etc)

tar -xzf etc.tgz

This overwrites /etc (slash, etc)!

tar -xzPf etc.tgz

Fedora Codec Installation

If you just need MP3 support, you might want to start here. Otherwise, I recommend using Livna.org‘s MPLayer package with the codecs found at http://www.mplayerhq.hu.

Install Livna’s release package for Fedora 9. This will provide you with access to Livna.org’s Fedora 9 YUM repository using /etc/yum.repos.d/livna.repo.

rpm -ivh http://rpm.livna.org/livna-release-9.rpm

Install mplayer from Livna.org.

sudo yum -y install mplayer

Now, visit the MPlayer Codecs Directory and download the latest ‘All’ tarball.

wget http://www.mplayerhq.hu/MPlayer/releases/codecs/all-20071007.tar.bz2

Next, prepare the codecs folder. MPlayer from Livna.org will use /usr/lib/codecs.

sudo mkdir -p /usr/lib/codecs

Other media players like Xine and avifile might use /usr/lib/win32, so create a symlink.

sudo ln -s /usr/lib/codecs /usr/lib/win32
ls -l /usr/lib/win32
lrwxrwxrwx 1 root root 15 2008-05-24 08:02 /usr/lib/win32 -> /usr/lib/codecs

Finally, extract the contents of the tarball and copy all files to /usr/lib/codecs.

tar -xjvf all-20071007.tar.bz2
sudo cp -a all-20071007/* /usr/lib/codecs/

See the MPlayer(1) man page for /usr/bin/mplayer usage.

man 1 mplayer

Mutt Addressbook

Need an address book program for Mutt? Look no further than abook. Use your distribution’s package manager to install abook.

yum install abook

The Config

Edit your ~/.muttrc file to include a macro for abook

set alias_file=~/.mutt-alias
source ~/.mutt-alias
set query_command= "abook --mutt-query '%s'" macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"

If you have no ~/.mutt-alias, be sure to create one before running mutt.

touch ~/.mutt-alias
mutt

Walkthrough of Usage

To use the addressbook, hit ‘a’. Accept the given alias, or replace with your own.

Mutt Address Book

Confirm the address.

Mutt Address Book

Give the contact a name. The name can contain spaces.

Mutt Address Book

Accept the entry.

Mutt Address Book

Finally, confirm the alias file.

Mutt Address Book

After doing this a few times, it will become second nature to hit <Enter> through most of the steps.

Accessing Contacts

To access the mutt addressbook, hit <Tab> at the to, cc or bcc line. You will be presented with a list of aliases from your ~/.mutt-alias file.

Mutt Address Book

See the abook SourceForge.net page for more information.

Convert YouTube Videos

So, you need to extract an audio WAV or MP3 file from a YouTube video? Or maybe create a portable AVI or MPEG video from a YouTube posting? This article will show you how.

Download the Original Flash Video File

First, you will need a file to convert. Use one of the many online video downloaders to extract an FLV from a YouTube (or MetaCafe, iFilm, etc) URL. Here are a few:

http://www.youtubex.com/
http://keepvid.com/
http://www.techcrunch.com/get-youtube-movie/

When you download the file from the specific URL, rename the file to include a .flv extention. Most of the web based download tools give you a file named something like "get_video".

bash$ mv get_video myvideo.flv

FYI: you can play flv files with the VideoLAN media player (VLC).

Install FFmpeg and Media Codecs

FFmpeg is a collection of libraries and tools that allow you to convert media files. Make sure you have ffmpeg installed with access to the proper codecs. Fedora and RedHat users can use Livna.org for src and binary RPMs. Ubuntu and Debian users can install ffmpeg with apt-get. Or, if you download the source code for ffmpeg, here are the options the Livna RPM for Fedora Code 6 are compiled with:

bash$ ffmpeg -version
FFmpeg version SVN-r8876, Copyright (c) 2000-2007 Fabrice Bellard, et al.
configuration: --prefix=/usr --incdir=/usr/include/ffmpeg --libdir=/usr/lib --shlibdir=/usr/lib --mandir=/usr/share/man --arch=x86_32 --extra-cflags=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables --enable-libmp3lame --enable-libogg --enable-libtheora --enable-libvorbis --enable-libfaad --enable-libfaac --enable-libgsm --enable-xvid --enable-x264 --enable-liba52 --enable-liba52bin --enable-libdts --enable-pp --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-opts --disable-strip 
libavutil version: 49.4.0
libavcodec version: 51.40.4
libavformat version: 51.12.1
built on May  3 2007 11:15:43, gcc: 4.1.1 20070105 (Red Hat 4.1.1-51)
ffmpeg      SVN-r8876
libavutil   3212288
libavcodec  3352580
libavformat 3345409

If you need codec libaries, download them from MPlayer’s Codec Releases.

bash$ wget http://www.mplayerhq.hu/MPlayer/releases/codecs/all-20061022.tar.bz2
bash$ tar -xjvf all-20061022.tar.bz2
bash$ sudo mkdir -p /usr/lib/codecs
bash$ sudo cp all-20061022/* /usr/lib/codecs/

Use FFmpeg to Convert Files

This is how you convert the flv to various audio and video formats:

# FLV to WAV -ac 2 is stereo, change to 1 for mono audio
ffmpeg -title "Custom Title" -i myvideo.flv -ac 2 -y myvideo.wav
# FLV to MP3  -ab 128 is the mp3 bit rate
ffmpeg -title "Custom Title" -i myvideo.flv -acodec mp3 -ac 2 -ab 128 -vn -y myvideo.mp3
# FLV to MPEG -s is geometry of video
ffmpeg -title "Custom Title" -i myvideo.flv -s 320x240 -y myvideo.mpeg
# FLV to AVI -ac 2 is stereo, change to 1 for mono audio
ffmpeg -title "Custom Title" -i myvideo.flv -ac 2 -y myvideo.avi

Use Gmail with Mutt

Mutt is a powerful text email client that can be used to access Gmail over IMAPS. Here are the relevant settings for your .muttrc.

Enable header caching

set header_cache=~/.mutt_cache

Configure IMAP over SSL

set from="FNAME LNAME <USERNAME@gmail.com>"
set imap_user=USERNAME@gmail.com
set imap_pass=PASSWORD
set folder=imaps://imap.gmail.com
set spoolfile=imaps://imap.gmail.com/INBOX
set record=imaps://imap.gmail.com/Sent
set postponed=imaps://imap.gmail.com/Drafts
set timeout=10
set mail_check=5
mailboxes =INBOX

Configure SMTP AUTH over SSL

set smtp_url="smtps://USERNAME\@gmail.com:PASSWORD@smtp.gmail.com/"