moji

moji

bash cheat sheet

add a cover image to an mp3

You can use mediainfo to investigate if the file has already a cover image.

˜ mediainfo mysong.mp3

The you can add a cover image to the file without reencoding it by ffmpeg. Use a 300×300 pixel image no larger than 500kB in JPEG format with moderate compression.

˜ ffmpeg -i sng.mp3 -i img.jpg -map_metadata 0 -map 0 -map 1 -acodec copy out.mp3

burn a cd from the command line

An easy to remember command line:

˜ wodim CD.iso

It will use some defaults and try to guess your drive, which is fine in most cases. That way you only need to set other options, like speed, if you really need to.

take a screenshot of the X-window session

Using image magic you can take a screenshot from the command line similarly to plan 9 (slightly, at least philosophically)

˜ magick import -window root screen.png

irssi

set you nickname

˜ /set nick yourNickNameHere

connect and disconnect from a server

˜ /connect sevreNameHere ˜ /diconnect

join and leave a channel

˜ /join channel name here ˜ /leave

marking as being away

˜ /away someTextHere

when back simply use the same command without comment to reset the status.

moving between open windows or chats

˜ ctrl+n

to comment on what you are doing in the chat

˜ /me theThingYouaAreDoing

to answer to a specific user type the username and tab complete it, the write the message

prepare for audio on Ubuntu

˜ sudo apt install ubuntustudio-audio linux-lowlatency

decompression

when unrar is not available use bsdtar which is art of libarchive-tools in alpine Linux

˜ doas apk add libarchive-tools ˜ bsdtar -xf file.rar

for zip files and also tgz files

˜ 7z x file.zip ˜ 7z x file.tgz

iff lmb image multimedia files

use the ilbmtoppm file converter fro the netpbm package. for Alpine

˜ doas apk add netpbm ˜ ilbmtoppm file.lbm > file.ppm

networking

check you IP

˜ ip address

scan network for connected ip/hostname

˜ nmap -sn 192.168.1.0/24

This will show you which hosts responded to ping requests on the network between 192.168.1.0 and 192.168.1.255. You will need to install nmap.

get file information

˜ stat flename

ncftp

˜ ncftp -u USER ftp.server.com

sort files

To find the 10 biggest folders in current directory:

˜ du -h | sort -hr | head -n 10

To find the 10 biggest files and folders in current directory:

˜ du -ah | sort -hr | head -n 10

speak

˜ echo "Hello, my name is Max Hedron."|espeak

Check memory speed and bank details

check ram size

˜ sudo lshw -c memory

update omz

˜ update zsh: omz update

one line HTTP server

if you would like to serve the website go to the root directory and launch

˜ python3 -m http.server

mac keyboard layout

Ubuntu Linux sets the keyboard parameters in the file /etc/default/keyboard. You can set the content manually in /etc/default/keyboard:

˜ XKBMODEL="macintosh" ˜ XKBLAYOUT="ch" ˜ XKBVARIANT="de_mac" ˜ XKBOPTIONS="lv3:alt_switch"

˜ BACKSPACE="guess"

periodical rsync

create the log file:

˜ touch sync-script.log

create the following sync-script.sh file

˜ #!/bin/sh ˜ rsync -acu --delete ~/sample/source/ ~/sample/target/ >> ˜ ~/sync-script.log

render it executable

˜ chmod +x sync-script.sh

add it to the crontab by open it in edit mode

˜ crontab -e

and adding

˜ */1 * * * * /bin/sh ~/sync-script.sh >> ~/sync-job.log 2>&1

crontab

List crontab

˜ crontab -l

Edit crontab

˜ crontab -e

monitor file content

To monitor a file content (text mostly) and print updates to the screen use

˜ tail -f file

current directory size and mounted drives site

˜ df -h -> for drives ˜ du -h -> for current dir

-h gives the site on Mb Gb etc

mounting cifs with correct right

˜ sudo mount -t cifs -o ˜ username=host_user,uid=local_user,gid=local_group //IP/host /dest

Don't forget to install key and cifs utils

˜ sudo apt install keyutils cifs-utils

some cisco vpn clients

Some Cisco clients provided by some institutions still need libbwebkit2gtk-4.0 which is no more available in Ubuntu 24.x (here they use v4.1+) to install it anyways you need to add the old source lists, update apt and install. It is recommended that you remove (or comment out the source after and update apt again. Note that form Ubuntu 24.x the distro sources have been moved from /etc/apt/sources.list, but this file will be still read when updating.

˜ echo 'deb http://gb.archive.ubuntu.com/ubuntu jammy main' >> /etc/apt/sources.list ˜ sudo apt update ˜ sudo apt install libwebkit2gtk-4.0-37

Cisco secure client should now run the connecting to vpn.fhnw.ch

˜ gtk-launch com.cisco.secureclient.gui

starting a HTTP server with python

cd into the directory containing the HTML files, preferably also with an index.html

˜ python3 -m http.server

launching programs at startup in zsh/bash

create a file .zlogin or .bash_login in your home directory and add you stuff there.

setup blender 3D

The following is an example on how to install blender form the tar file downloaded form the official website. Extract the tar to the location you want the create a simlink to a location which is in the PATH, for example

˜ sudo ln -s EXECUTABLE_DIR/blender ~/.local/bin

Then, copy app icon provided by blender to local folder, so your system can find it

˜ mkdir -p ~/.local/share/icons && cp blender.svg ~/.local/share/icons

If the local icons folder does not exist out-of-the-box. Just in case, use mkdir command with -p option to try creating it. Finally, copy (or move) the blender.desktop file (also provided by blender) into .local/share/applications directory:

˜ cp blender.desktop ~/.local/share/applications

And run update-desktop-database to apply, log out and in again. After that, your system can read this .desktop file, and show app icon in menu.

encrypting the home folder and swap on Ubuntu

From here

Install the tools

˜ sudo apt install ecryptfs-utils cryptsetup

Create a additional super user

˜ sudo adduser encryption_user ˜ sudo usermod -aG sudo encryption_user

logout and into the new user, do NOT reboot. check if you can access the home folder of the user (here winnie) you want to encrypt.

˜ sudo ls -l ~winnie

Start the encryption (passphrase is the password of winnie)

˜ sudo ecryptfs-migrate-home -u winnie

logout and in to winnie, doe NOT reboot. A window soul pop up. First however check if you can write to the new folder ~winnie (the encryption made a copy of the non encrypted folder ~winnie.. Write into a file and cat it.

˜ vim ~winnie/hello.txt ˜ cat hello.txt

Now in the pup up click on "Run this action" if there was no pup up then

˜ ecryptfs-unwrap-passphrase

Provide winnie's password. check the passphrase$

˜ sudo ecryptfs-unwrap-passphrase

copy and save it on a secure place. Now encrypt the swap. Check of you have one

˜ swapon -s ˜ free -h

now encrypt it

˜ sudo ecryptfs-setup-swap

Now clean up, i.e. remove user, remove not encrypted home

˜ sudo deluser –remove-home encryption_user ˜ sudo rm -Rf /home/winnie.

check if you encrypted all. For the home folder check if you have these files

˜ la ~ | grep .ecryptfs ˜ la ~ | grep .Private

For the swap check if the answer to the following command contains cryptswap

˜ sudo blkid | grep swap