tag:blogger.com,1999:blog-35729167685063339472024-03-13T07:53:10.466-07:00John's Unix TipsThese are mostly notes I'm leaving to myself. They're not meant in any generality, but what the hell, someone might find them useful, so they might as well be public.John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.comBlogger103125tag:blogger.com,1999:blog-3572916768506333947.post-43354460285515144062023-04-10T12:59:00.004-07:002023-04-10T16:15:46.613-07:00How to fix "E: You don't have enough free space in /var/cache/apt/archives/."<p>If the root directory is tight and</p><p><b>apt-upgrade </b></p><p>is giving you:</p><p><b>E: You don't have enough free space in /var/cache/apt/archives/<br /></b></p><p>then you can move apt's cache somewhere else:</p><p></p><p><b>mv /var/cache/apt/ /home<br />ln -s /home/apt/ /var/cache/apt</b> </p><p>later undo with: <br /></p><div style="text-align: left;">rm /var/cache/apt</div><div style="text-align: left;">mv /home/apt /var/cache</div><p>--------------------------------------------------------</p><p>various housekeeping things <br /></p><p>apt clean </p><p>apt autoremove</p><p>journalctl --rotate<br /></p><p>journalctl --vacuum-time=1s </p><p>remove old logs <br /></p><p>find /var/log -mtime +2 -type f -delete</p><p>rm /var/cache/locate/locatedb<br /><br /></p><p>-------------------------------------------------------<br /></p><p></p><p>other things that may help actually squeeze the root filesystem </p><p><br /></p><div class="fs-headline1 ow-break-word mb8 flex--item fl1" itemprop="name" style="text-align: left;">find all the files larger than 50M on the / partition (ignoring sub-mounts!)<br /></div><div style="text-align: left;">find / -mount -type f -size +50M -exec du -h {} \; | sort -n</div><div style="text-align: left;"> </div><div style="text-align: left;">find installed packages in size order <br /></div><div class="fs-headline1 ow-break-word mb8 flex--item fl1" itemprop="name" style="text-align: left;">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}'<br /></div><h1 class="fs-headline1 ow-break-word mb8 flex--item fl1" itemprop="name"><br /></h1>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-25392669164329783432023-02-14T10:57:00.006-08:002023-02-14T10:57:30.667-08:00How to Change the Default Browser in Debian Linux<p><b>xdg-open https://lichess.org/training/kAngL</b><br /></p><p><b>xdg-settings get default-web-browser<br /></b></p><p><b>xdg-settings set default-web-browser firefox.desktop</b></p><p></p><p><b>xdg-open https://lichess.org/training/kAngL<br /></b></p><p><b>xdg-settings set default-web-browser debian-sensible-browser.desktop</b></p><p><br /></p><p><br /></p>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-6042116657906458472023-01-19T08:16:00.004-08:002023-01-22T11:17:39.814-08:00To Move the Most Recent Files<p>This command will move the five most recent files in the ~/Downloads directory to the current directory<br /></p><p> </p><p><b>find ~/Downloads -maxdepth 1 -type f -printf '%T@ %p\n' | sort -rn | cut -d' ' -f2- | head -n 5 | xargs -I{} echo mv {} .</b></p><p> </p><p>to do a dry run! remove echo to actually do it. <br /></p>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-81908838315452730402022-10-18T04:37:00.000-07:002022-10-18T04:37:04.150-07:00Batch Renaming Files with Wildcards<p>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. <br /></p><p>On debian 11, you want the rename package <br /></p><p><b>sudo apt install rename</b></p><p>This provides the perl renamer. Check you've got the right one, because there are many different rename commands provided by different packages!<br /></p><p><b>$ rename -V</b><br />/usr/bin/rename using File::Rename version 1.13, File::Rename::Options version 1.10 <br /></p><p>find a way to isolate all the files you want to rename using shell wildcards<br /></p><p><b>$ ls account*</b></p><p><b>'accounts 2008-2009.ods' 'accounts 2011-2012.ods' 'accounts 2014-2015.ods'</b></p><p>Now come up with a perl/sed replacement expression that changes the spaces to dashes<br /></p><p><b>$ rename 's/\ /-/' account*</b></p><p><b>$ ls account*<br />accounts-2008-2009.ods accounts-2011-2012.ods accounts-2014-2015.ods</b></p><p><b> </b></p>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-37031562171176321272021-04-08T06:10:00.000-07:002021-04-08T06:10:02.475-07:00Using feh to move images from Desktop to Screensaver images directory<p><b>feh -FZ --no-jump-on-resort --draw-actions --draw-filename ~/Desktop -A "mv --backup=t %F /home/john/Desktop/unison/screensaver-images"<br /> </b></p>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-64296472012816784572021-04-08T06:07:00.000-07:002021-04-08T06:07:07.864-07:00Package Suggestions for Debian Command Not Foundsudo apt-get install command-not-found<br />sudo update-command-not-found<br />John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-63713442353932885992021-04-08T06:04:00.003-07:002021-04-08T06:04:24.602-07:00Using ffmpeg to batch convert images from webp to png<p>for i in *.webp; do ffmpeg -i "$i" "${i%.*}.png"; done<br /><br /></p>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-68559139711138526512020-02-15T07:25:00.000-08:002020-02-15T07:50:14.735-08:00Linux Diff Tools for Python and how to use them with GitThe differencer in <b>git gui</b> / <b>gitk</b> is usually good enough for me, but occasionally<br />
a commit diff can be really confusing, in which case<br />
<br />
<b>git difftool </b><br />
<br />
will start up a graphical differ.<br />
<br />
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:<br />
<br />
<b>git difftool HEAD~1</b><br />
<br />
(Here's a nice explanation of what the <b>~</b> and <b>^</b> mean <a href="http://www.paulboxley.com/blog/2011/06/git-caret-and-tilde">http://www.paulboxley.com/blog/2011/06/git-caret-and-tilde</a>)<br />
<br />
With python <b>xxdiff</b> can get confused by indentation changes. If this happens go to <i><b>Options</b></i> and tell it to <b><i>ignore whitespace</i></b>.<br />
<br />
That
makes the comparison work better, (although at that point it won't
highlight the whitespace changes, but you can still see them).<br />
<br />
<br />
-----------------------<br />
<br />
Other diff tools<br />
<br />
For me the graphical differ is always <b>xxdiff</b>, which I love, because it's fast and does the business.<br />
<br />
<br />
That appears to be set in my <b>git config</b>, which I can look at with: <br />
<b>git config -l</b><br />
<br />
the relevant line is:<br />
<br />
<b>merge.tool=xxdiff</b><br />
<br />
Sometimes, a commit can be particularly confusing, at which point I feel the need to try out different diff tools.<br />
<br />
This is a <i><b>pointless but fun merry-go round</b></i>, I always end up going back to <b>xxdiff</b>.<br />
<br />
However, this is how to do it.<br />
<br />
Install them all:<br />
<br />
<b>sudo apt install colordiff wdiff kompare meld kdiff3 xxdiff diffuse tkdiff</b><br />
<br />
Try them out:<br />
<br />
<br />
<b>git difftool --extcmd=kdiff3 HEAD~1 </b> #shows whitespace by default, isn't confused by it<br />
<b>git difftool --extcmd=xxdiff HEAD~1 </b><br />
<b>git difftool --extcmd=diffuse HEAD~1</b> #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<b><br /></b><br />
<b>git difftool --extcmd=meld HEAD~1</b> #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!!)<br />
<br />
<br />
<b>git difftool --extcmd=colordiff HEAD~1</b> # same as git diff HEAD~1<br />
<br />
<b>git difftool --extcmd=tkdiff HEAD~1</b> #noisy display, hard to read<br />
<br />
<b>git difftool --extcmd=diff HEAD~1</b> # like git diff HEAD^, but no colours<br />
<b>git difftool --extcmd=wdiff HEAD~1</b> # no colours, can't work out what it's doingJohn Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-65588445065986286402020-01-23T07:14:00.000-08:002020-01-23T07:18:45.478-08:00Is a Package Installed?Is cryptsetup installed?<br />
<br />
Most generally useful is:<br />
<br />
<b>apt search cryptsetup</b><br />
<br />
Or to concentrate on cryptsetup exactly: <br />
<br />
<b>apt list cryptsetup</b><br />
<br />
To get all the details of the package<br />
<br />
<b>apt show cryptsetup</b><br />
<br />
There are various other ways in which we can interrogate both dpkg and apt<br />
<br />
<br />
<b>dpkg --status cryptsetup</b><br />
<br />
<b>apt-cache policy cryptsetup</b><br />
<br />
<b>apt-cache search cryptsetup</b>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-82776188512822607502020-01-23T03:40:00.000-08:002020-01-23T07:20:14.127-08:00Which Package Provides a File?Which package will give me a java compiler?<br />
<br />
<b>apt search java</b><br />
<br />
<br />
gives endless output<br />
<br />
<b>apt-file search "javac"</b><br />
<br />
falls over in various ways:<br />
<br />
<hr />
<br />
Fail Better:<br />
<br />
<b>sudo apt update ; sudo apt install apt-file; sudo apt update</b><br />
<br />
<b>apt-file search "javac "</b>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-67293653435651076622020-01-19T10:56:00.004-08:002020-01-19T10:56:59.217-08:00To Manually Install get_iplayer on Debian (version 9.9)Instructions found here:<br />
<br />
<a href="https://github.com/get-iplayer/get_iplayer">https://github.com/get-iplayer/get_iplayer</a><br />
<br />
<br />
<br />
<br />
But all I needed to do was: <br />
<br />
<b>sudo apt-get install libwww-perl liblwp-protocol-https-perl libmojolicious-perl libxml-libxml-perl libcgi-pm-perl atomicparsley ffmpeg</b><br />
<b></b><br />
<b>wget https://raw.githubusercontent.com/get-iplayer/get_iplayer/master/get_iplayer</b><br />
<b></b><br />
<b>sudo install -m 755 ./get_iplayer /usr/local/bin</b><br />
<b></b><br />
<br />
<br />
<br />
<br />
<br />
Test with:<br />
<br />
<b>get_iplayer --release-check</b><br />
<b></b><br />
<b>get_iplayer ".*"</b><br />
<br />
To actually fetch something(s)<br />
<br />
<b>get_iplayer --get ".*Example.*"</b>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-27001458117670536712019-12-01T08:35:00.000-08:002019-12-01T08:35:09.710-08:00To Convert a Load of Document Files into Plain Text (In Order to Diff Them)<b>for i in * ; </b><br />
<b>do </b><br />
<b> echo "$i" ;</b><br />
<b> libreoffice --headless --convert-to txt:Text "$i" ; </b><br />
<b>done</b><br />
<br />John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-38185982837419534782019-07-06T14:47:00.002-07:002019-07-06T14:47:15.990-07:00To Play a Random Sound File in a Tree<b>mplayer "$(find . -name "*.3gp" | shuf -n1)"</b><br />John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-18559203897307524942019-07-06T14:45:00.000-07:002019-07-06T14:45:30.877-07:00To 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, <br />
<br />
<b>Compose - a and Compose a - will both produce an ā</b><br />
<b><br /></b>
but it's more convenient to make the right Alt key (AltGr) be the compose key<br />
<br />
to try it in a terminal<br />
<b>setxkbmap -option "compose:ralt"</b><br />
<br />
to make it the system default:<br />
<b>sudo dpkg-reconfigure keyboard-configuration</b><br />
<br />
you can also get it to work just in your desktop environment with e.g. in xfce, Applications/Settings/Keyboard/Layout<br />
<br />John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-48076924617058029472019-07-06T14:43:00.000-07:002019-07-06T14:43:03.935-07:00To play all the sound files in a tree<b>find . -name "*.3gp" -exec mplayer {} \;</b>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-70404518342742816852019-05-25T13:34:00.004-07:002019-05-25T13:34:41.631-07:00To Turn .midi Files Into .wav Files<b>for i in *.midi; do timidity -Ow -o "${i%.midi}.wav" "$i" ; done</b>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-81632671472609225632019-03-28T09:41:00.002-07:002019-03-28T09:41:10.577-07:00To Play a Random Video<b>mplayer -fs "$(ls | shuf -n1)"</b>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-72526544703084943362019-03-19T14:53:00.001-07:002019-03-19T14:53:38.722-07:00To move the five most recent files to a subdirectory<b>ls -rt</b> will show you the files most recent first. <br />
<br />
To move the most recent five to a subdirectory:<br />
<br />
<b>mkdir -p recent && find -maxdepth 1 -type f -printf '%T@ %P\n' | sort -rn | cut -d' ' -f2- | head -n 5 | xargs -I{} mv {} recent </b>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-38630743778622315762019-03-04T08:30:00.001-08:002019-03-04T08:31:01.705-08:00To Find the Most Recent Version of a FileOccasionally it so happens that you want to find the most recent version of thing.<br />
<br />
Suppose that you're trying to find your most recent timesheet. <br />
<br />
Then:<br />
<br />
<b>find ~ -type f -name "*timesheet*" -printf "%T@ %t %p\n" | sort -n </b><br />
<br />
does the business.<br />
<br />
Output looks something like:<br />
<br />
1519655146.5096155360 Mon Feb 26 14:25:46.5096155360 2018 /home/john/data/.~/timesheet.py.~86~<br />
1519925511.1565392570 Thu Mar 1 17:31:51.1565392570 2018 /home/john/data/.~/timesheet.py.~87~<br />
1520000595.5182763930 Fri Mar 2 14:23:15.5182763930 2018 /home/john/data/timesheet.py<br />
<br />
Where the first column is a sortable version of the last modification time "%T@", and the second "%t" is the human readable form.<br />
<br />
The last thing printed will be the most recent file in your home directory tree with timesheet in the name.John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-70111400085147287552019-01-07T09:54:00.001-08:002019-01-07T09:55:09.312-08:00Linux Laptop Battery Level<b>sudo apt-get install acpi </b><br />
<b>acpi -V</b><br />
<br />
or:<br />
<br />
<b>upower -i `upower -e | grep 'BAT'`</b>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-73987185014762424092018-05-09T13:50:00.002-07:002018-05-09T13:50:18.139-07:00Lilypond in Debian Stretchlilypond wasn't included in stretch, but has been backported<br />
<br />add<br /><br />
<b>deb http://ftp.debian.org/debian stretch-backports main</b><br />
<b></b><br />to <b>/etc/apt/sources.list</b>, and then<br />
<br /><b>sudo apt update<br />sudo apt-get -t stretch-backports install lilypond</b><br />
<br />
<b><br /></b>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-83579638597467676752018-04-20T14:16:00.003-07:002018-04-20T14:17:38.877-07:00To install a new version of Racket on an old version of DebianRunning Debian 8 which has Racket 2.1.<br />
<br />
Trying to work through<br />
<br />
<a href="http://io.livecode.ch/learn/gregr/icfp2017-artifact-auas7pp">http://io.livecode.ch/learn/gregr/icfp2017-artifact-auas7pp</a><br />
<br />
for which there is a Racket Package <br />
<br />
2.1 is not good enough, need Racket 2.6<br />
<br />
Check out: <br />
<br />
<a href="https://backports.debian.org/Instructions/">https://backports.debian.org/Instructions/</a><br />
<br />
<b>$ su</b><br />
<br />
<b># echo "deb http://ftp.debian.org/debian jessie-backports main" >> /etc/apt/sources.list</b><br />
<br />
<b># apt update</b><br />
<br />
<b># apt-get -t jessie-backports install racket</b><br />
<br />
Now have Racket 2.7, which is good enough.John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-54545071715055003522017-08-04T03:59:00.000-07:002017-08-04T03:59:14.487-07:00grep just highlight<a href="https://stackoverflow.com/questions/7393906/highlight-text-similar-to-grep-but-dont-filter-out-text#7394821">https://stackoverflow.com/questions/7393906/highlight-text-similar-to-grep-but-dont-filter-out-text#7394821 </a><br />
<br />
Trick is to use ^ to every line with a start-of-line. Since that's unprintable it won't get highlighted.<br />
<br />
So to list all the files with arista in the name, but highlight the objects:<br />
<br />
<b>find . -name "*arista*" | grep -E '^|\.o|.so'</b>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-51548892276796688222017-05-19T00:15:00.000-07:002017-05-19T00:15:07.173-07:00Find .c or .h or .py filesYou can use a regular expression with find: <br />
<br />
<b>find . -regex '.*cisco.*\.\(c\|h\|py\)'</b><br />
<br />
finds all cisco-related .c .h or .py files.John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0tag:blogger.com,1999:blog-3572916768506333947.post-13536785339252930062017-04-24T03:33:00.003-07:002017-04-24T03:33:27.550-07:00Make Firefox show the https:// bit of an Address<span style="font-family: inherit;">go to:</span><br />
<br />
<b><span style="font-family: inherit;">about:config </span></b><br />
<br />
<span style="font-family: inherit;">make </span><br />
<br />
<b><span style="font-family: inherit;">browser.urlbar.trimURLs</span></b><br />
<br />
<b><span style="font-family: inherit;">false </span></b><em><br /></em>John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.com0