Enabling Snaps in Linux Mint 20+

Linux MInt has taken the decision to disable the ability to install snapd and subsequently containerised apps (or snaps) from the Ubuntu Snap Store.

Linux Mint users are met with an error when attempting to install snapd or snap store applications

You can disable the block on installing snapd as follows.

sudo rm /etc/apt/preferences.d/nosnap.pref
sudo apt update
sudo apt install snapd

This will allow you to install those specific containerised versions of apps that you want, e.g. Whatsdesk (a containerised Whatsapp client for your Linux desktop).

sudo snap install whatsdesk
Facebooktwitterredditpinterestlinkedinmail

Expand the existing Swapfile on Linux

Note that this only applies if you’re using a swapfile as opposed to a swap partition. This will apply if you’re using full disk encryption since the swap file is then also encrypted. Most modern linux distro’s will behave in this way by default.

Ignore the first dd command since it contains a typo (shown)

If you’re using KDE Plasma as your desktop environment, for entertainment purposes, open Memory.

The Memory Information dialog opens to look like this.

Now expand the window by dragging a corner and you’ll see some neat graphs of memory usage…

Memory and Swap Usage graphs in KDE Plasma Desktop Environments “Memory” app

Now with your Konsole to one side of the graphs, observe the changes going on on the system as you execute each command. Really quite cool. KDE Plasma is great. By far my favourite desktop environment. I recommend it but live in it for a week and figure it all out since it’s quite comprehensive. You’ll likely not go back!

Facebooktwitterredditpinterestlinkedinmail

Basic Linux Commands

Here are some Linux commands that everyone should be familiar with. In fact, you could argue that these are the first commands to memorise and build out your repertoire from there.

#BASIC LINUX COMMANDS

#Clear the terminal window
  clear
#Show kernel version
  uname -a
#Show all tunable kernel parameters in the /proc/sys directory
  sudo /sbin/sysctl -a
#Set a kernel parameter on the fly without persistence
  sudo /sbin/sysctl -w kernel.sysrq="1"
#Set a kernel parameter with persistence
  /etc/sysctl.conf
#Kernel parameters startup script
  /etc/rc.d/rc.sysinit
#Show network interfaces
  ifconfig
  ip addr show
#Configure network interface with persistence
  /etc/sysconfig/network
  /etc/sysconfig/network-scripts/ifcfg-eth0
#Show all filesystems and space
  df -ah
#Show service status
  service udev status
  systemctl status udev
#How much disk space is used by a given directory
  du ~/Downloads
#What TCP and UDP ports is the listem listening on?
  netstat -tulpn
  sudo netstat -tulpn #gives more info on process name
#Show information about a given process
  ps aux | grep containerd
#Show free memory stats
  free
#List block storage devices known to the system
  lsblk
#Show mounted storage devices
  mount
#Show filesystems that should be mounted at boot
  cat /etc/fstab
#Mount everything in /etc/fstab
  mount -a
#Mount a block storage device
  mount /dev/sdb1 /mnt
#LVM Commands
  pvdisplay pvcreate  pvremove  pvchange
  vgdisplay vgcreate  vgextend  vgremove  vgchange
  lvdisplay lvcreate  lvextend  lvremove  lvchange
  mkfs.ext4
#Copy files
  cp
  rsync
  dd
#Show command history
  history
#Look up a command
  man -k <search-string>
  man grep
Facebooktwitterredditpinterestlinkedinmail

Savage leaky programs

It’s come to my attention recently that despite a fresh install of Linux Mint, certain programs seem to leak like a basket and hang around after they’re closed too.

I’d noticed my machine freezing intermittently and adding the memory monitor panel item revealed that the system memory was filling up.

The blue mem bar fills up over time when Brave is left open. Disappointing for such an otherwise excellent Web Browser.

xreader and brave seemed to be the main culprits but since rebuilding my desktop machine, I’ve not been using many other programs apart from ledger live to track the value of my crypto currency portfolio while the fed prints money ad infinitum during the coronavirus pandemic. I digress.

Killing processes gets old really quick, so I wrote a quick’n’dirty little shell script to do it for me. Rather than killing individual processes, it savages all processes by the same name.

I shall call it savage.sh and share it with the world, right here. Not on github.

Killing all running processes for ledger and brave using savage.sh
#!/bin/bash
# savage.sh finds all process ID's for the specified program running under your own user account and kills them
# in order to free up system resources.  Some programs have severe memory leaks and consume vast amount of RAM and 
# swap if left running over time.
#
# Usage: savage.sh 
#
# Written by M. D. Bradley during Coronavirus pandemic, March 2020

#Variables
user=`whoami`
memfree=`free | grep Mem | awk {'print $4'}`
#Code
echo "Program to kill e.g. xreader?: "
read program
pidcount=`ps -fu $user | grep $program | awk {'print$program'} | wc -l`
ps -fu $user | grep $program | awk {'print$2'} | while read eachpid; do 
	kill $eachpid >/dev/null 2>&1
done
memfree2=`free | grep Mem | awk {'print $4'}`
freedmem=$(( memfree2 - memfree ))
if [ $pidcount -eq 1 ] 
then
	echo "Found $pidcount process running for $program"
	echo "Killed it.  Freed up $freedmem bytes."
fi
if [ $pidcount -gt 1 ] 
then
	echo "Found $pidcount processes running for $program"
	echo "Savaged them. Freed up $freedmem bytes."
fi
Facebooktwitterredditpinterestlinkedinmail

git Cheat Sheet

My super concise git notes

Developed by Linus Torvalds, git is a…

  1. Distributed Version Control System (VCS) for any type of file
  2. Co-ordinates work between multiple developers
  3. Tracks who made what changes and when
  4. Revert back at any time
  5. Supports local and remote repositories (hosted on github, bitbucket)

It keeps track of code history and takes snapshots of your files
You decide when to take a snapshot by making a commit
You can visit any snapshot at any time
You can stage files before committing

INSTALLING git
sudo apt-get install git (debian)
sudo yum install git (red hat)
https://git.scm.com (installers for mac and windows)
gitbash is a linux-like command cli for windows

CONFIGURING git
git config –global user.name ‘matt bradley’
git config –global user.email ‘matt@cyberfella.co.uk’
touch .gitignore
echo “log.txt” >> .gitignore
Add file to be ignored by git, e.g. log file generated by script
echo “/log” >> .gitignore Add directory to be ignored, e.g. log directory

BASIC COMMANDS (local repository)
git init Initialize a local git repository (creates a hidden .git subdirectory in the directory)
git add Adds file(s) to Index and Staging area ready for commit.
git add . Adds all files in directory to Staging area
git status check status of working tree, show files in Staging area and any untracked files you still need to add
git commit commit changes in index – takes files in staging are and puts them in local repository
git commit -m ‘my comment’ Skips git editing stage adding comment from command.
git rm –cached removes from staging area (untracked/unstaged).

BASIC COMMANDS (remote repo)
git push push files to remote repository
git pull pull latest version from remote repo
git clone clone repo into a local directory

git clone https://github.com/cyberfella/cyberfella.git clones my cyberfella repository

git –version shows version of git installed

BRANCHES
git branch loginarea creates a branch from master called “loginarea”
git checkout loginarea switches to the “loginarea” branch
git checkout master switches back to the master branch version
git merge ‘loginarea’ merges changes made to ‘loginarea’ files in loginarea branch to master branch

REMOTE REPOSITORY
https://github.com/new
Create a public or private repository
Shows the commands required to create a new repository on the command line or push an existing repository from the command line

README.md
A readme.md (markdown format) file displays nicely in github.

#MyApp

This is my app

Basically it should look like this in github

MyApp

This is my app

USEFUL COMPLIMENTARY INFORMATION

atom is a very nice, simple text editor for programmers that supports integration with git. https://flight-manual.atom.io/getting-started/sections/installing-atom/

Facebooktwitterredditpinterestlinkedinmail

Make bootable USB from .iso in Linux

The following command will write a downloaded .iso file of your favourite distro to a USB stick.  You can then boot off it and install to hardware.

sudo dd bs=4M if=./manjaro-xfce-18.0-stable-x86_64.iso of=/dev/sdb status=progress

Note that in my example, there was no partition on the usb stick to start with.  I’d removed it using gparted (not necessary though).Facebooktwitterredditpinterestlinkedinmail

Conky

One of my first ever posts was about conky and wbar on crunchbang linux.

Crunchbang has since been replaced with a community led fork, Bunsenlabs, and it’s well worth checking out.  I’m so impressed with it that it’s my laptop OS of choice, giving me very little grief installing onto my disappointingly-not-particularly-linux-friendly Dell XPS 15, unlike other popular distros.  Suffice to say, Bunsenlabs has saved my XPS15 from the financial damage limitation exercise known as ebay.

In any case, I thought I’d include a link to my own .conkyrc file.  It’s simple and neat, nothing too fancy.

The download file is called conkyrc.  Once downloaded, just rename it to .conkyrc i.e. put the dot in front (hidden file and the conky default), and copy it to your home directory, remembering to back up any existing .conkyrc file already in your home directory first.

If you want to edit yours to make it your own, the man page for conky is very good, but I find this better.Facebooktwitterredditpinterestlinkedinmail

Linux disk space consumption analysis.

Desktop distro’s have wonderful graphical disk space analysis programs such as Baobab (KDirStat), QDirStat, xdiskusage, duc, JDiskReport and with your desktop distro being connected to the internet, even if you dont already have them installed, installing them from your repositories is easy.   You can quickly drill down using these treemapper programs and find the culprit for filling your disk up.

In the datacentre, things are never so easy.  You have no internet access, and no local repository configured, and even if you did, you have no change control to install it on a live system, and even if you did, no GUI to view it. All you have is a production problem, a stressed out ops manager and a flashing cursor winking at you -oh and native tools.

Sure, you can use the find command to go looking for files over a certain size,

find ./ -type f -size +1000000M -exec ls -al {} \;

removing a zero and re-running as required until it starts finding something, but you’ll fight with the find command syntax for 15 minutes trying to get it to work, only to be unconvinced of the results.  As good as find is, it’s not exactly easy trying to put together a command that does something that should be simple.

Here is a much simpler solution.  Just use du.  In particular…

du -h –max-depth=1

This will summarize the size of the top level sub-directories underneath your present working directory.  You then cd in to the biggest one, run it again and repeat until you basically end up digging down and arriving at the largest file on disk – in my case a 32GB mysql database in /var/lib/mysql/zabbix.

So there you go.  Have a play with it and you’ll see what I mean.  It’s my favourite way of finding out what’s eating all my disk space.

Using QDIRSTAT on headless servers

We live in strange times, where despite the best efforts of the likes of Edward Snowden to open our eyes to the fact that we’re being monitored at any and every opportunity by the intelligence community, we’re still hell bent on moving our enterprise computing into huge corporate cloud data centres that the CIA and NSA have back doors into. If you think “That’s OK, I have nothing to hide.” then great. How ’bout you hand me your phone and let me go and have a good look around it? Oh, that’s not OK? Well make your mind up, will you? You think you’re gonna be as successful as Google and Amazon if you use their cloud services? Whose cloud service do you think they use? That’s right, their own. So your Cloud is their On Prem. I know, I’m such a cynic.

For those who are tasked with monitoring disk space consumption on their cloud servers, containers, headless stuff, you can use a neat little qdirstat cache file writer to generate a cache file that you can then open in qdirstat on your workstation for analysis.

I’ve summarised its use below, assuming you’ll understand what each command is doing.

ssh myserver
sudo cd /usr/local/bin
sudo wget https://github.com/shundhammer/qdirstat/raw/master/scripts/qdirstat-cache-writer
sudo chmod +x qdirstat-cache-writer
sudo qdirstat-cache-writer / ~/myserver-root.cache.gz
exit
scp "root@myserver:~/*.cache.gz" ~/
sudo chmod 777 ~/*.cache.gz
sudo apt-get install qdirstat
qdirstat --cache ~/myserver-root.cache.gz

I’d like to issue a special thanks to Mike Schlegel in the comments section below for dragging me kicking and screaming into the 21st Century. I guess there’s still some of us out there who are clever enough to be working with Linux but stupid enough that we didn’t buy Bitcoin at 10$ back in 2012 when I started this blog.

Facebooktwitterredditpinterestlinkedinmail

Simplify linux find command using shell functions

Do you need to find a file and then perform some action on it and get caught up in curly brackets, back slashes and syntax errors when you could swear “this command worked in the past?”.  It’s one of the joys of Linux I guess, but quickly becomes tedious when you’re working against a problem and are under stress.

Here is a reference find command that works.  I hope it helps.  It’ll no doubt help me at some point (the entire purpose of my blog is to actually remind myself how to do half of this stuff from time to time).

sudo find ./ -name *.mkv -exec ls {} \;

Something I like to do is create shell functions in the .bashrc file in your home directory to simplify commonly used commands that are long to type and quite syntax sensitive.

#SHELL FUNCTIONS FOR .bashrc
f() { find . -name “*$1*”; }

This is a nice useful one that can be used to find any files that have the specified string anywhere in the filename.  Just type f All  to find any files with the word All occurring anywhere in the filename.

You could create other versions such as this one, that will find and remove files with a specified string in the filename – but I’d really not recommend it.

fr() { find ./ -name “*$1*” -exec rm {} \; }

Be sure to run man fr first to check that your shell function name isn’t the name of an existing binary on the system!Facebooktwitterredditpinterestlinkedinmail

Dropbox alternative for Linux users

With the recent announcement that Dropbox is dropping its support for linux filesystems (other than ext4) in November, you’ll no doubt be searching for an alternative cloud storage provider that supports linux file system synchronisation.

Look no further than MEGA.

50GB for free, local filesystem synchronisation, download and retain your own private key,  a great, easy to use web browser client.

File system sync client: https://mega.nz/syncFacebooktwitterredditpinterestlinkedinmail