Tuesday, October 18, 2022

Batch Renaming Files with Wildcards

First make sure you've got your files version controlled, because this has a way of going horribly wrong and you want to be able to reset to your starting state when it does.

On debian 11, you want the rename package

sudo apt install rename

This provides the perl renamer. Check you've got the right one, because there are many different rename commands provided by different packages!

$ rename -V
/usr/bin/rename using File::Rename version 1.13, File::Rename::Options version 1.10

find a way to isolate all the files you want to rename using shell wildcards

$ ls account*

'accounts 2008-2009.ods'  'accounts 2011-2012.ods'  'accounts 2014-2015.ods'

Now come up with a perl/sed replacement expression that changes the spaces to dashes

$ rename 's/\ /-/' account*

$ ls account*
accounts-2008-2009.ods  accounts-2011-2012.ods  accounts-2014-2015.ods

 

Thursday, April 8, 2021

Using feh to move images from Desktop to Screensaver images directory

feh -FZ --no-jump-on-resort --draw-actions --draw-filename ~/Desktop -A "mv --backup=t %F /home/john/Desktop/unison/screensaver-images"
 

Package Suggestions for Debian Command Not Found

sudo apt-get install command-not-found
sudo update-command-not-found

Using ffmpeg to batch convert images from webp to png

for i in *.webp; do ffmpeg -i "$i" "${i%.*}.png"; done

Saturday, February 15, 2020

Linux Diff Tools for Python and how to use them with Git

The differencer in git gui / gitk is usually good enough for me, but occasionally
a commit diff can be really confusing, in which case

git difftool 

will start up a graphical differ.

Note that the syntax for looking at the last commit, which is often what you want not least because git gui won't show that, is:

git difftool HEAD~1

(Here's a nice explanation of what the ~ and ^ mean http://www.paulboxley.com/blog/2011/06/git-caret-and-tilde)

With python xxdiff can get confused by indentation changes. If this happens go to Options and tell it to ignore whitespace.

That makes the comparison work better, (although at that point it won't highlight the whitespace changes, but you can still see them).


-----------------------

Other diff tools

For me the graphical differ is always xxdiff, which I love, because it's fast and does the business.


That appears to be set in my git config, which I can look at with:
git config -l

the relevant line is:

merge.tool=xxdiff

Sometimes, a commit can be particularly confusing, at which point I feel the need to try out different diff tools.

This is a pointless but fun merry-go round, I always end up going back to xxdiff.

However, this is how to do it.

Install them all:

sudo apt install colordiff wdiff kompare meld kdiff3 xxdiff diffuse tkdiff

Try them out:


git difftool --extcmd=kdiff3 HEAD~1  #shows whitespace by default, isn't confused by it
git difftool --extcmd=xxdiff HEAD~1 
git difftool --extcmd=diffuse HEAD~1 #shows whitespace by default, isn't confused by it, syntax colouring! This would be the best one, except that the very syntax colouring makes it hard to see what's going on

git difftool --extcmd=meld HEAD~1 #really beautiful, has same whitespace problems as xxdiff, and solution is the same, but it's a persistent preference which I don't like (state!!)


git difftool --extcmd=colordiff HEAD~1 # same as git diff HEAD~1

git difftool --extcmd=tkdiff HEAD~1       #noisy display, hard to read

git difftool --extcmd=diff HEAD~1         # like git diff HEAD^, but no colours
git difftool --extcmd=wdiff HEAD~1       # no colours, can't work out what it's doing

Thursday, January 23, 2020

Is a Package Installed?

Is cryptsetup installed?

Most generally useful is:

apt search cryptsetup

Or to concentrate on cryptsetup exactly:

apt list cryptsetup

To get all the details of the package

apt show cryptsetup

There are various other ways in which we can interrogate both dpkg and apt


dpkg --status cryptsetup

apt-cache policy cryptsetup

apt-cache search cryptsetup

Which Package Provides a File?

Which package will give me a java compiler?

apt search java


gives endless output

apt-file search "javac"

falls over in various ways:



Fail Better:

sudo apt update ; sudo apt install apt-file; sudo apt update

apt-file search "javac "