BLACK CAT PROGRAMMER

Ubuntu disable ctrl+alt+e

iBus binds ctrl + alt + e to enter emoji, but it is quite annoying actually. I did not enter emoji on Ubuntu. More importantly, it collides with the vscode shortcut.

So, how to disable it.

Method 1

In terminal type ibus-setup, go to the emoji tab, and delete the keybindings.

But for some reason, it may not work in VSCode.


https://github.com/Microsoft/vscode/issues/48480

Method 2

  1. Open terminal
  2. enter
    gsettings set org.freedesktop.ibus.panel.emoji hotkey []
  3. Done
Posted in notesTagged ,

bash script notes

Get input arguments

test.sh -n=Tom –phone=1234

#!/bin/bash

for i in "$@"
do
case $i in
    -n=*|--name=*)
    NAME="${i#*=}"
    ;;
    -p=*|--phone=*)
    PHONE="${i#*=}"
    ;;
esac
done

echo NAME = $NAME
echo POST = $PHONE

Get positional arguments

Save below script to test.sh and run it as

#!/bin/bash

echo $0 $1 $2

>> test.sh a bb cc

result:
test.sh a bb

Get process id of last executed command

python3 HelloForever.py &

pid=$!
echo $pid

Assign variables

GREETING_WORD="Hello world!"
echo $GREETING_WORD

>> Hello world!

Loop

for (( i=0; i<5; i++)) do
	echo $i
done

echo date

TODAY=`date +%Y%m%d`
echo $TODAY

Changing all files in working directory to lowercase

for i in *; do mv $i `echo $i | tr [:upper:] [:lower:]`; done

Adding prefix to all files in working directory

for a in *.png; do mv "$a" "$1$a"; done

Posted in notesTagged ,

vim notes

vim 真是太好用了

The basic

In view mode:

CommandUsage
:w
:q
:wq
:wq!
Save
quit
Save and quit
confirm save and quit
:number
eg: :129
Go to line number
Go to line 129
20|
25h
25l
Go to column 20
Move cursor 25 characters ahead
move cursor 25 character after
/keyword
?keyword
n
N
Search keyword from beginning of file
Search keyword from the end of file
Go to next find result
Go to previous find result
$
9
:1
G
Go to beginning of current line
Go to the end of current line
Go to line 1
Go to the end of file
ctrl + d
ctrl + u
Move half of the view downwards
Move half of the view upwards
i
a
r
Insert: start editing at the current cursor position
Append: start editing after the current cursor position
Replace: replace the character at the current cursor position
u
Ctrl + r
Undo
Redo
h
j
k
l
Move the cursor to left
Move the cursor to down
Move the cursor to up
Move the cursor to right
e
E

w
W
Go to the end of a word separated by special character
Go to the end of a word separated by space

Go to the start of a word separated by special character
Go to the start of a word separated by space

Display and not display line number:

:set number
:set nonumber

marco

// record a marco and named it "a"
// in view mode, enter "q" then the name of the marco, a-z

ie: qa

// then vim will enter recording mode. You may see "recording @a" in bottom left corner

// To play the marco once
// in view mode enter "@" followed by the name of the marco, in my case, a

ie: @a

// To play the marco several times
// in view mode, enter the number of times followed by "@" and the name of the marco

ie: 10@a

Posted in notesTagged ,

IP Table

iptables 就可以當作是 linux 裡的防火牆。

Each table has many chains which each chain has many rules

Common tables are nat and filter

filter is for controlling the incoming and outgoing packets

 CHAINS
  1. INPUT
  2. FORWARD
  3. OUTPUT

while

nat is for forwarding packets

 CHAINS
  1. PREROUTING
  2. INPUT
  3. OUTPUT
  4. POSTROUTING

Save the current iptables rules

iptables-save > file_path.rules

Restore iptables rules

iptables-restore < /etc/iptables.rules

Examples

1. List current iptable rules of NAT
iptables -t nat -L -v

2. List current iptables rules of INPUT line number
iptables -t nat -L -v --line-numbers

3.1. Adding a new rule accepting port 1194 traffic
3.1) Append mode
 iptables -t nat -A INPUT -i eth0 -p tcp -m tcp --dport 1194 -j ACCEPT
3.2) Insert mode
iptables -t nat -I INPUT [line number ]-i eth0 -p tcp -m tcp --dport 1194 -j ACCEPT
3.3) Insert mode v2
iptables -I INPUT 7 -p tcp --dport 8443 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT

4.Change the source IP from 10.8.0.0/24 to 192.168.13.11
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j SNAT --to-source 192.168.13.11

5. delete a rule
 1) first, show the current rules by
 iptables -t nat -L -v --line-numbers 
 
 2) delete the rule
 iptables -t nat -D POSTROUTING 1

REF: https://opensource.com/article/18/9/linux-iptables-firewalld

Posted in notesTagged ,

Linux command cheatsheet

Finding files

# finding a file
# 1. find hello.txt in /src
find /src -name hello.txt

# Find large files in linux
$ sudo du -a /dir/ | sort -n -r | head -n 20

Add a new user

adduser <username> --shell /bin/bash --home <home directory>

Add a user to an existing to group

usermod -aG <group name> <username>

# eg1: add user to sudo group
usermod -aG sudo <username>

Remove user from a group

gpasswd -d <user name> <group name>

# show the group of the user
groups <user name>

Creating symbolic link

ln -s <source folder> <new shortcut>

Show current memory usage

> free -h

              total        used        free      shared  buff/cache   available
Mem:           875M        141M        155M         80M        579M        592M
Swap:           99M          0B         99M

or

> free -m

              total        used        free      shared  buff/cache   available
Mem:            875         141         155          80         579         592
Swap:            99           0          99

Remove password requirement

sudo vim /etc/pam.d/common-password

remove obscure to disable complexity check

add minlen=3 to add min password length

Service control

# Start a service
sudo service nginx start

# check the status of a service
sudo service nginx statua

# stop a service
sudo service nginx stop

# list all service
service --status-all
service --status-all | more
service --status-all | grep ntpd
service --status-all | less

Posted in notesTagged