Tuesday, December 25, 2018

Image Rotation in Bulk

We have been having problems with rotating images.  All the software so far rotate correctly on our system or at least it seems so but they all leave the metadata intact.  Here is how I rotated in bulk with the assumption that i grouped all the wrong ones that needed rotation of the same orientation.

Use exiftool to accomplish this task
Navigate to the directory of all the wrong images that needed rotation
cd needRotate90CW
# Remove all metadata from the images
exiftool -all= *.jpg# Rotate them 90 degrees counter clockwise and overwrite
exiftool -orientation="Rotate 90 CW" -overwrite_original *.jpg

The above seemed to work but did not change the metadata to the width and height.  It only rotated.

SOLUTION! 
I found the easiest method is to use Nautilus file manager and 
Nautilus Image Converter

Monday, December 10, 2018

Find Differences Between Two Files Using Bash

grep -v -F -x -f file1 file2
The problem with the above command is that you dont know which way is the differences.  Here is a better way to accomplish this.  I have a directory of ID cards named MASTER_ID and is mounted remotely.  I host a local MYSQL database with all the accounts.  The problem we are trying to solve is move all the ID cards that are no longer in the database to the !Graveyard directory for consideration of permanently removal by a human.

if [[ $EUID -ne 0 ]]; then
 echo "This script must be run as root"
 exit 1
fi

MASTER_ID_DIR="/home/projects/mount_directory/srvr-file/SchoolPhotos/MASTER_ID/"
MASTER_ID_LST="/tmp/master_id.lst"
CAS_LST="/tmp/cas.lst"

# Generate list of all users within CAS by ID
if [ -f $CAS_LST ]; then
 rm $CAS_LST
fi
mysql -u cas_god -p <dbpasswd> -D cas -e "select id_number from cardinfo_cardinfo into outfile '/tmp/cas.lst'"

# Get listing of MASTER_ID regardless of the file extension case
echo "" > $MASTER_ID_LST
for x in `ls $MASTER_ID_DIR`; do
 echo $(basename $x .[Jj][Pp][Gg]) >> $MASTER_ID_LST
done

# Find extras in MASTER_ID that is NOT in CAS
for y in `cat $MASTER_ID_LST`; do
 if [ `grep $y $CAS_LST|wc -l` -eq 0 ]; then
   echo mv $MASTER_ID_DIR${y}.* $MASTER_ID_DIR!Graveyard/${y}_delete.jpg
   mv $MASTER_ID_DIR${y}.* $MASTER_ID_DIR!Graveyard/${y}_delete.jpg
 fi
done

Monday, December 3, 2018

Find Digit in Filename & Bulk Rename

Extracted from StackOverflow: https://stackoverflow.com/questions/428109/extract-substring-in-bash
Generic solution where the number can be anywhere in the filename, using the first of such sequences:
number=$(echo $filename | egrep -o '[[:digit:]]{5}' | head -n1)
Another solution to extract exactly a part of a variable:
number=${filename:offset:length}
If your filename always have the format stuff_digits_... you can use awk:
number=$(echo $filename | awk -F _ '{ print $2 }')
Yet another solution to remove everything except digits, use
number=$(echo $filename | tr -cd '[[:digit:]]')
I need to loop through the directory and take the filename and crop off the name assuming that the first 6 numbers are the ID number then change it to the final form.  I had to ignore all the spacing and junk after the number and just made the assumption that all I needed was the numbers in front of the file.

find . -print0 | while read -d $'\0' file; do number=$(echo $file | egrep -o '[[:digit:]]{6}' | head -n1); mv ${number}* ${number}.jpg ; done

I had some problems with files with the hyphen.

ls > /tmp/list

I needed to export a list of file then manipulate with VIM, keeping only the first work in each line then use the file list to iterate through

:1,$s/\(\s*\w\+\).*/\1/g

for x in `cat /tmp/list`; do  number=$(echo $x | egrep -o '[[:digit:]]{6}' | head -n1); mv ${number}* ${number}.jpg; done 



Sunday, December 2, 2018

Bulk Rename of Filename

Bulk change of file extension.  For an example, change the JPG to jpg

for x in `ls *JPG`; do mv $x $(basename $x .JPG).jpg; done

To find all basename case insensitive

$(basename $x .[Jj][Pp][Gg])

Friday, November 2, 2018

Linux Must Have Applications

Must Have for My Need


  1. TimeShift
    System backup with snapshots for easy rollback
    Other backup solution Grsync and Back in Time
  2. Graphics Software
    Inkscape, Gimp, Krita, 
  3. Web Browser
    Google Chrome, Mozilla Firefox
  4. Productivity Suite
    LibreOffice, Google Apps
  5. Audio & Video Editing
    Audacity, KdenLive
  6. VLC Media Player
    Obviously VLC has dominated the market with the codec compatibility, but more importantly for me was the ease of creating your own theme.  I have a killer theme customized for me so I love using it and provide me with some pride and accomplishment.  "Self pad on the back so to speak"
  7. Veracrypt
    Disk encryption software
  8. KeepassXC
    Password manager to help manage your hundreds if not thousands of passwords
  9. FontBase
    There are literally thousands of fonts in the world and will be in the millions soon so it's important to have a font manager to help in the graphics designing.  The most important is that you dont need to install the font onto your system which in turn will help with performance overall since the system does not need to preload all those fonts.

Nice to Have


  1. PlayOnLinux
    Install Windows application using Wine with ease 
  2. Windows Games
    Lutris.net has tweeked Wine and uses things like forStarcraft II  uses DX9 to OpenGL - 64 bit - Wine Staging + Esync.  Other games will have other dependencies to optimize that particular game.
  3. Thunar Bulk Rename
    Just like the name suggested, it gives you the ability to rename filenames in bulk based on patterns 
  4. Konsole
    Terminal with the special ability to clone your commands from one session to another.
  5. BeyondCompare
    Find and merge differences in files
This list is not complete.  I will be updating throughout the next month as I see the regular use of some of these tools.