My own notes and scrabbles relating to Linux, with mostly a Ubuntu take on it.

Git shorthands

# Do a git pull in all child folders. 
$ ls | xargs -P10 -I{} git -C {} pull -r

# Revert any changes in all child folders.
$ ls | xargs -P10 -I{} git -C {} reset --hard

# Change to a particular branch in all child folders. 
$ ls | xargs -P10 -I{} git -C {} checkout develop

# Change pull -r for any other git command to execute that on all child folders instead.

Quick and easy Snap restore

I depend on several snaps to be able to do my day to day work as efficient as possible. This is my way of making sure I get all needed snaps installed and back to work in a quick and easy way.

#!/bin/bash

toInstall=("bitwarden" "sublime-merge --classic" "rider --classic" \
	"code --classic" "datagrip --classic" \
	"postman" "slack --classic" "teams" "skype --classic" "ffmpeg" \
	"vlc" "obs-studio" "telegram-desktop" "spotify" "hugo")

for app in "${toInstall[@]}"; do
	snap install $app
done

Make Samba Mac Friendly

To get Macs to use Samba more efficient and better overall, there are some specific settings one needs to enable.

Add the following to your smb.conf file:

[Global]
min protocol = SMB2
vfs objects = fruit streams_xattr  
fruit:metadata = stream
fruit:model = MacSamba
fruit:posix_rename = yes 
fruit:veto_appledouble = no
fruit:wipe_intentionally_left_blank_rfork = yes 
fruit:delete_empty_adfiles = yes 

[TimeMachineBackup]
vfs objects = fruit streams_xattr
fruit:time machine = yes
#  fruit:time machine max size = SIZE

And that’s it, enjoy your Samba server even more from macOS.

SSH helpers

Copy your local SSH pub key onto a target servers authorized keys file. Obviously this will not work if you have turned off pwd auth. But this is a nice helper for bootstrapping a new server with allowed clients for example.

 
$ cat ~/.ssh/id_rsa.pub | ssh USER@HOST "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

NOTE: The above command will not create the dir and file with the correct permissions, so it is preferable if you have the folder and file already created on your target to avoid this issue.

Rsync commands

 
# Sync from ~/Pictures to /data/green/snews/Pictures as the target
# We will use full compression here and we will make sure to only do deltas
# We will finally delete files from target based on what has been removed in source
$ rsync -rtvuc --delete-after ~/Pictures /data/green/snews/Pictures

Power management

Install TLP. The default config works very well on my ASUS Laptop.

 
$ apt install tlp