BASH fairy dust

Mounting a windows share using CIFS

mount -t cifs //{target_host}/{share_path} {mount_point} -o username={user_name}

Batch renaming photos using jhead

Using jhead, rename all files with extension .JPG

jhead -n"%Y%m%d_%H%M%S_%03i" *.JPG

Append file creation date

For any files that matches the pattern GOP*.MP4, append its creation date to the original file name; i.e. GOPRO1234.MP4 –> 20170101_122201_GOPRO1234.MP4

for f in GOP*.MP4; 
do 
  mv -n ${f} $(date -r ${f} +"%Y%m%d_%H%M%S")_${f};
done

Ammend the latest commit message (not yet pushed)

git commit --amend

Git goodness

Add hunks interactively

Did you make all your changes at once, but want to keep your commits nice, tidy and grouped logically? No problem…

git add {files} --patch

Got something more complex? Read on.


SQL Serv…errrr

List all running processes

Pull up a list of SQL Server PIDs running on the active instance, including CPU & memory counters, login and host PID information as well

select * from sys.sysprocesses;

List all databases and data/log files on-disk sizes

Pretty nifty and useful when trying to gauge disk footprint; can be easily adapted when the need to (re)distribute databases across volumes arises

select 
    d.name as database_name,
    sum(case 
      when f.type_desc = 'rows' then (f.size*8/1024) 
      when f.type_desc = 'log'  then 0 
    end) as data_file_mbytes,
  sum(case 
      when f.type_desc = 'rows' then 0 
      when f.type_desc = 'log'  then (f.size*8/1024) 
    end) as log_file_mbytes,
    f.state_desc as online_status,
    sum((f.size*8/1024)) as file_mbytes
from sys.master_files f
inner join sys.databases d on d.database_id = f.database_id
group by d.name, f.state_desc