January 29, 2016

January 24, 2016

compare 2 folders


comm <(ls /folder_name/) <(ls folder_name)


comm -23 <(ls /Volumes/Transcend_Blue/Pictures/) <(ls /Volumes/Multimedia/Pictures/Sorting/) >> missing.txt

show only missing files from 1 folder and save to list


find empty directory and delete it


find . -type d -empty -exec rmdir {} +

find 0 byte files and remove

find * -size 0 -exec rm -f {} +

Add files to archieve without compressin and split zip volumes

7z a -bt -m0=copy -v2g file_name.7z *

m0=copy - store files only
v2g - split into 2gb volumes

January 23, 2016

unzip file via command line

Qnap TS-420

which 7z

go to directory

run 7z x file_name

zip file without compression via command line

zip -r -0 zip_filename.zip folder_1_to_zip folder_2_to_zip

SSH server on MacOS

Enable ssh login

From command-line
systemsetup -setremotelogin on


Restrict access to ssh only to admin

# Create the com.apple.access_ssh group
dseditgroup -o create -q com.apple.access_ssh

# Add the admin group to com.apple.access_ssh
dseditgroup -o edit -a admin -t group com.apple.access_ssh

ssh login without password via id_rsa

machine A - client
machine B - server

on A run
ssh-keygen -t rsa
if asked to provide password just press ENTER

Result:
ls ~/.ssh

you should see the id_rsa & id_rsa.pub files


login via ssh to B

ssh username@machine_ip
promt for password - type in your password

ls ~/.ssh

if directory does not exist - create it
mkdir ~/.ssh

if directory exists - log out

on A

let's copy the id_rsa.pub key to remote server B

cat .ssh/id_rsa.pub | ssh username@machine_b_ip  'cat >> .ssh/authorized_keys'
promt for password - type in your password


we are almost done. From now you can login to remote machine without password promt. But we need to take some security providing steps.

from A let's login to B

ssh username@machine_b_ip

No password promt. You have been loged in to remote server 2.
Please apply

chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Authentication refused: bad ownership or modes for directory

login to remote ssh machine you are not being able to connect via key authorisation

and apply

chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

restart remote ssh server

you are done

MacOS terminal keyboard text shortcuts

On Mac OS X - the following keyboard shortcuts work by default. Note that you have to make Option key act like Meta in Terminal preferences (under keyboard tab)

alt ⌥+F to jump Forward by a word
alt ⌥+B to jump Backward by a word

I have observed that default emacs key-bindings for simple text navigation seem to work on bash shells. You can use

Meta-d to delete a word starting from the current cursor position
ctrl+A to jump to start of the line
ctrl+E to jump to end of the line
ctrl+K to kill the line starting from the cursor position
ctrl+Y to paste text from the kill buffer
ctrl+R to reverse search for commands you typed in the past from your history
ctrl+S to forward search (works in zsh for me but not bash)
ctrl+F to move forward by a char
ctrl+B to move backward by a char

How to type letters with accent

Very useful article https://www.freecodecamp.org/news/how-to-type-letters-with-accents-on-mac/