Monday, April 10, 2023

How to fix "E: You don't have enough free space in /var/cache/apt/archives/."

If the root directory is tight and

apt-upgrade 

is giving you:

E: You don't have enough free space in /var/cache/apt/archives/

then you can move apt's cache somewhere else:

mv /var/cache/apt/ /home
ln -s /home/apt/ /var/cache/apt
 

later undo with:

rm /var/cache/apt
mv /home/apt /var/cache

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

various housekeeping things

apt clean 

apt autoremove

journalctl --rotate

journalctl --vacuum-time=1s 

remove old logs

find /var/log -mtime +2 -type f -delete

rm /var/cache/locate/locatedb

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

other things that may help actually squeeze the root filesystem 


find all the files larger than 50M on the / partition (ignoring sub-mounts!)
find / -mount -type f -size +50M -exec du -h {} \; | sort -n
 
find installed packages in size order 
dpkg-query --show --showformat='${Package;-50}\t${Installed-Size}\n' | sort -k 2 -n | grep -v deinstall | awk '{printf "%.3f MB \t %s\n", $2/(1024), $1}'


Tuesday, February 14, 2023

How to Change the Default Browser in Debian Linux

xdg-open https://lichess.org/training/kAngL

xdg-settings get default-web-browser

xdg-settings set default-web-browser firefox.desktop

xdg-open https://lichess.org/training/kAngL

xdg-settings set default-web-browser debian-sensible-browser.desktop



Thursday, January 19, 2023

To Move the Most Recent Files

This command will move the five most recent files in the ~/Downloads directory to the current directory

 

find ~/Downloads -maxdepth 1 -type f -printf '%T@ %p\n' | sort -rn | cut -d' ' -f2- | head -n 5 | xargs -I{} echo mv {} .

 

to do a dry run! remove echo to actually do it.

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 "

Sunday, January 19, 2020

To Manually Install get_iplayer on Debian (version 9.9)

Instructions found here:

https://github.com/get-iplayer/get_iplayer




But all I needed to do was:

sudo apt-get install libwww-perl liblwp-protocol-https-perl libmojolicious-perl libxml-libxml-perl libcgi-pm-perl atomicparsley ffmpeg

wget https://raw.githubusercontent.com/get-iplayer/get_iplayer/master/get_iplayer

sudo install -m 755 ./get_iplayer /usr/local/bin






Test with:

get_iplayer --release-check

get_iplayer ".*"

To actually fetch something(s)

get_iplayer --get ".*Example.*"

Sunday, December 1, 2019

To Convert a Load of Document Files into Plain Text (In Order to Diff Them)

for i in * ; 
do 
  echo "$i" ;
  libreoffice --headless --convert-to txt:Text "$i" ; 
done

Saturday, July 6, 2019

To Play a Random Sound File in a Tree

mplayer "$(find . -name "*.3gp" | shuf -n1)"

To type Latin Macrons āēīōū

in X generally, you need to use the Compose key, most keyboards don't have one, so Compose is usually done with shift+Alt Gr,

Compose - a and Compose a - will both produce an ā

but it's more convenient to make the right Alt key (AltGr) be the compose key

to try it in a terminal
setxkbmap -option "compose:ralt"

to make it the system default:
sudo dpkg-reconfigure keyboard-configuration

you can also get it to work just in your desktop environment with e.g. in xfce, Applications/Settings/Keyboard/Layout

To play all the sound files in a tree

find . -name "*.3gp" -exec mplayer {} \;

Saturday, May 25, 2019

To Turn .midi Files Into .wav Files

for i in *.midi; do timidity -Ow -o  "${i%.midi}.wav" "$i" ; done

Thursday, March 28, 2019

Tuesday, March 19, 2019

To move the five most recent files to a subdirectory

ls -rt will show you the files most recent first.

To move the most recent five to a subdirectory:

mkdir -p recent && find -maxdepth 1 -type f -printf '%T@ %P\n' | sort -rn | cut -d' ' -f2- | head -n 5 | xargs -I{} mv {} recent

Monday, March 4, 2019

To Find the Most Recent Version of a File

Occasionally it so happens that you want to find the most recent version of thing.

Suppose that you're trying to find your most recent timesheet.

Then:

find ~ -type f -name "*timesheet*" -printf "%T@ %t %p\n" | sort -n 

does the business.

Output looks something like:

1519655146.5096155360 Mon Feb 26 14:25:46.5096155360 2018 /home/john/data/.~/timesheet.py.~86~
1519925511.1565392570 Thu Mar  1 17:31:51.1565392570 2018 /home/john/data/.~/timesheet.py.~87~
1520000595.5182763930 Fri Mar  2 14:23:15.5182763930 2018 /home/john/data/timesheet.py

Where the first column is a sortable version of the last modification time "%T@", and the second "%t" is the human readable form.

The last thing printed will be the most recent file in your home directory tree with timesheet in the name.

Monday, January 7, 2019

Linux Laptop Battery Level

sudo apt-get install acpi 
acpi -V

or:

upower -i `upower -e | grep 'BAT'`