shellsheet - feliyur/exercises Wiki

Shellsheet

Ubuntu (Debian?) specific

Add user to group sudo usermod -a -G groupName userName
Location of config/permissions on Ubuntu /etc/sudoers, /etc/groups
Show storage devices and UUID lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,UUID
Execute monitoring command every n seconds watch -n <sec> <command> <command args>
Compute directory size, show filesystem info. du, df
Get / change hostname hostname to get, sudo hostnamectl set-hostname to set (or sudo edit /etc/hostname)
Get ip address ifconfig -a old style. New: ip address.
Who is logged on who -H, who -u, w, users, ps au the latter shows processes for each user.
Processes info ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
Copy symlink cp -R --preserve=links

Backup raspberry pi:

ssh pi "sudo dd if=/dev/mmcblk0 bs=1M | gzip -" | dd of=~/Desktop/pibackup.gz

Safe fstab line: UUID=<device UUID> <mountpoint> none auto,nofail,noatime,nolock,intr,bind 0 0 Mountpoint must exist. Can check UUID with lsmlk

Convert PDF into (true) black-and-white (good for sending as fax):

gs -sDEVICE=bmpgray -dNOPAUSE -dBATCH -r300x300 -sOutputFile=./Payement-confirmation.pdf ./Payement-confirmation.pdf

gs -o ./Payement-confirmation-bw.pdf -sDEVICE=pdfwrite -c "/osetrgbcolor {/setrgbcolor} bind def /setrgbcolor {pop [0 0 0] osetrgbcolor} def" -f ./Payement-confirmation-b\&w.pdf

SSH Config

Generate ssh key ssh-keygen -t ed25519 -C "[email protected]" Or ssh-keygen -t rsa -b 4096 -C "[email protected]"
Add local ssh key to remote authorized_keys ssh-copy-id <[email protected]>. On Windows: type <key .pub file> | ssh <[email protected]> "cat >> .ssh/authorized_keys"

~/.ssh/config file format:

Host <my_alias>
HostName <ip>
User <remote username>
To connect through proxy, do
ProxyCommand ssh [email protected] nc %h %p
or
ProxyJump pi

To execute a remote command on connect (e.g., `cd` to some directory)
RequestTTY yes
RemoteCommand cd /home/katya/yuri; exec /bin/bash

Application shortcuts

.desktop files located at /usr/share/applications. Can link also to remote folders through sftp.

To create a desktop shortuct, need to create a .desktop file at ~/Desktop.

Remote File Transfer

rsync --partial --progress myfile [email protected]:/path/to/destination

Transfer file. --partial flag allows to resume an interrupted transfer.

scp

TODO: Description

Managing Processes

Ctrl + z Puts current process in the background
jobs Lists current session jobs.
fg <id> Brings process <id> (from jobs output) to foreground.
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head Processes info

Useful Programs

fail2ban Service to block repeated accesses to computer/server.
imagemagick Set of cli tools for manipulation of images.
diffuse Graphical comparison allowing manual alignment
pdftk Set of cli tools for dealing with pdfs
xclip Allows to redirect programs output to clipboard
jq command-line json manipulation
curl, wget download files. Syntax: wget url -O filename, curl url -o filename. Curl writes to stdout by default.
tmux, screen Terminal multiplexers. Allow to run programs persistently without being connected. tmux cheatsheet, screen cheatsheet

Archive Files

unzip file.zip -d destination_folder
unzip -t test.zip test if an archive is valid
unzip -l file.zip list contents
unzip file.zip -x a_particular_file exclude file
zip -r file.zip list of files and directories Compresses recursively.
tar -xvf Extracts (verbose)
tar -czvf file.tar.gz file-or-dir Compresses (-c) using gzip to file (-f).
7z x file Extracts. Need to sudo apt-get install p7zip-full to get 7z.

PDF Files

pdftk myfile.pdf cat 1-3 5 7-end output outfile.pdf Output portions of pdf

Special keys with AltGr Int'l keyboard

Problem: AltGr special keys not function Ubuntu 18.04. Solution: Keyboard shortcuts ==> Restore keyboard shortcuts (Super+Escape default).

prefix = right alt

Key Shortcut
é prefix+', e
è prefix+`, e
á, à idem.
ç, Ç prefix+, (hold prefix) c / shift+c
ï " + i
ĉ ^+c

Also see here

Libraries installations

sudo apt install libopencv-dev 
sudo apt install libpcl-dev

Midnight Commander

sudo apt-get install mc
mc -x start with mouse
Ctrl+o Back to shell
Tab Switch pane
%d/%f, %D/%F Refers to left dir/file and right dir/file respectively
Alt+I cd the other pane to the same directory as the current pane.
Alt+A Copy the cwd of the current pane to the command line.
Ctrl+R Refresh file list in pane.

More information about macros etc. here