Vim

cw (change word) changer le mot
dw (delete word) supprimer le mot
c4w changer 4mots
/ rechercher un mot sur la page
dd supprimer une ligne
6dd supprimer 6 lignes
o creer une nouvelle ligne
G aller en bas de page
yy puis c copier la ligne et l'inserer en dessous 
:s/foo/bar/g Change each 'foo' to 'bar' in the current line.
:%s/foo/bar/g Change each 'foo' to 'bar' in all the lines.
Linux

Disque amont

 $ df -h

Show number of processes

$ nproc number of process on the machine
$ free state of memory
$ free -h  state of memory Human read
$ lscpu ls proc human read
$ /proc/cpuinfo info on every proc
$ /proc/meminfo info on memory
$ less /proc/cpuinfo info on every proc
$ less /proc/meminfo info on memory

List all valid IP addresses in a local network

  1. dnf install nmap (if not installed)
  2. nmap -sn 192.168.1.0/24 or nmap -sP 192.168.1.*

Global bash for all users

  1. cd /etc/profile.d 
  2. touch CHOOSE_NAME_YOU_WANT.sh 
  3. put your aliasses in CHOOSE_NAME_YOU_WANT.sh
  4. run: source /etc/profile

send file to external server with scp

 scp fileToSend user_name@server_ip:~/targetFolder/|renameFile

get file from external server with scp

 scp user_name@server_ip:~/targetFolder/fileToGet
Reseaux

Afficher les machines dans un réseau

$ arp -a | -n | -v | -nv| -e

Tester les ip sur internet

  1. test-ipv6.com verifier l'état du ipv6
  2. api.ipify.org ipv6 et ipv4 
mysql

extend import file size in phpMyAdmin

  1. go to mamp/bin/php.x.x./conf/php.ini
  2. memory_limit = 256M 
  3. post_max_size = 500M 
  4. upload_max_filesize = 500M 

Error: Can't connect to local mySQL server through socket /tmp/mysql.sock

  1. run: ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
  2. reboot mySQL 

Error message in MySQL goes like this: “ERROR 1136 (21S01): Column count doesn’t match value count at row 1“.

This error typically occurs when you’re trying to insert data into a table, but the number of columns that you’re trying to insert don’t match the number of columns in the table.
SELECT table_schema, table_name, index_name, column_name
information_schema.statistics 

Select all foreign key of database

select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE = 'FOREIGN KEY'
macOs

Error: gyp: No Xcode or CLT version detected macOS Big Sur

sudo xcode-select -r
ordi

Reboot when power is re-applied after a power failure (mini-pc acepc)

  1. on reboot press F2 
  2. go to Boot
  3. go to State After G3
  4. set Power On
  5. Save & exit
centos/ almalinux

Network configuration for static IP

  1.  $ cd /etc/sysconfig/network-scripts/
  2. $ vim ifcfg-interface-Name
  3. config or add:
  4. BOOTPROTO=static
    IPV6INIT=no
    del: IPV6_AUTOCONF=yes, IPV6_DEFROUTE=yes if IPV6INIT=no
    IPADDR=198.168.1.100(ex: your static ip addr)
    NETMASK=255.255.255.0(according to your network)
    GATEWAY=192.169.1.1((according to your network)
    HOSTNAME=(name you want to give the machin)
    NM_CONTROLLED=no
  5. $ sudo systemctl restart NetworkManager.service

Change hostname

  1. $ sudo hostnamectl set-hostname 'NEW NAME' 
  2. $ hostnamectl (to verifie the new change )

clean cache

  1. dnf clean all 
  2. rm -rf /var/cache/yum/*

Error: semanage : commande introuvable

  1. $ sudo dnf provides /usr/sbin/semanage
  2. $ sudo dnf install policycoreutils-python-utils

Linux : Ajouter un nouveau utilisateur

  1. login as adm 
  2. adduser user_name<
  3. passwd  user_name
  4. visudo  or  vim /etc/sudoers
  5. user_name ALL=(ALL) ALL
  6. userdel  user_name

Install Mysql on centos8 && almalinux

  1. $ sudo dnf update
  2. $ sudo dnf install mysql mysql-server (almalinux 9)  and go to 5.
  3. $ sudo dnf module list mysql
  4. $ sudo dnf module enable mysql:8.0
  5. $ sudo dnf install @mysql
  6. $ sudo systemctl enable mysqld
  7. $ sudo systemctl start mysqld 
  8. $ sudo systemctl status mysqld 
  9. $ sudo mysql_secure_installation (securisation)
  10. $ mysqladmin -u root -p version (test mysql)
  11. $ mysql -u root -p (connexion)

Manage Mysql on centos8

  1. $ mysql -u root -p (connect as root)
  2. CREATE DATABASE IF NOT EXISTS database_name;
  3. SHOW DATABASES;
  4. CREATE USER IF NOT EXISTS 'database_user'@'localhost' IDENTIFIED BY 'user_password'; (add user with password )
  5. GRANT ALL PRIVILEGES ON database_name.* TO 'database_user'@'localhost';
  6. - DROP USER IF EXISTS 'database_user'@'localhost'; (delete user)
  7. - GRANT ALL PRIVILEGES ON *.* TO 'database_user'@'localhost';(grant for all database)
  8. - SELECT user, host FROM mysql.user; (list all user account)
  9. - DROP USER IF EXISTS 'database_user'@'localhost';(delete  user account)
  10. - SHOW GRANTS FOR 'database_user'@'localhost';(display user privilèges account)
  11. - ALTER USER 'database_user'@'localhost' IDENTIFIED BY 'new_password';(change user password)

Initial Server Setup (Setting Up a Basic Firewall)

  1. sudo dnf install firewalld -y 
  2. sudo systemctl start firewalld 
  3. sudo systemctl status firewalld 
  4. sudo firewall-cmd --permanent --list-all 
  5. sudo firewall-cmd --get-services 
  6. sudo firewall-cmd --permanent --add-service=http 
  7. sudo firewall-cmd --reload 

Install Httpd (apache) on centos8 & co

  1. sudo dnf install httpd
  2. sudo firewall-cmd --permanent --add-service=https
  3. sudo firewall-cmd --reload
  4. sudo systemctl start httpd
  5. sudo systemctl status httpd
  6. hostname -I ( to get IP ADDR if don't know)
  7. http://your_server_ip ( to test if evething is ok at this point)

Error : httpd: Could not reliably determine the server's fully qualified domain name, using...

Update /etc/hosts and do server’s ip address resolvable to the fully qualified domain name(fqdn) or hostname.
  1. $ vim /etc/hosts 
  2. change server’s ip address 
  3. $ systemctl restart httpd 

Setting Up Virtual Hosts

  1. sudo mkdir -p /home/stingers/NAME/;
  2. sudo mkdir -p /home/stingers/NAME/log; 
  3. sudo mkdir -p /home/stingers/NAME/api;
  4. sudo mkdir -p /home/stingers/NAME/html;
  5. sudo chown -R apache:apache /home/stingers/NAME/;
  6. sudo chmod -R 755 /home/stingers/
  7. sudo vim /home/stingers/NAME/html/index.html
  8. sudo mkdir /etc/httpd/sites-available /etc/httpd/sites-enabled
  9. sudo vim /etc/httpd/conf/httpd.conf
  10. press G > i ( insert mode) and add IncludeOptional sites-enabled/*.conf
  11. sudo vim /etc/httpd/sites-available/NAME.conf; (config VirtualHost);
  12. sudo ln -s /etc/httpd/sites-available/NAME.conf /etc/httpd/sites-enabled/NAME.conf;

Adjusting SELinux Permissions for Virtual Hosts

  1. sudo setsebool -P httpd_unified 1;
  2. sudo ls -dlZ /home/stingers/NAME/log/;
  3. sudo semanage fcontext -a -t httpd_log_t "/home/stingers/NAME/log(/.*)?";
  4. sudo restorecon -R -v /home/stingers/NAME/log;
  5. sudo ls -dlZ /home/stingers/NAME/log/;

Testing the Virtual Host

  1. sudo systemctl restart httpd;
  2. ls -lZ /home/stingers/NAME/log/

Forbidden – You don’t have permission to access / on this server” Error

  1. getenforce if output: Enforcing
  2. sudo vim /etc/selinux/config
  3. set: SELINUX=disabled 
  4. sudo reboot (to reboot the system)

How To Secure Apache with Let's Encrypt on CentOS 8

  1. sudo dnf install epel-release
  2. sudo dnf install certbot python3-certbot-apache mod_ssl
  3. sudo certbot --apache
  4. sudo certbot renew --dry-run;
  5. echo "0 0,12 * * * root python3 -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew -q" | sudo tee -a /etc/crontab > /dev/null;
AH00526: Syntax error on line 5 of /etc/httpd/conf.d/ssl.conf:
Cannot define multiple Listeners on the same IP:port
solution :   comment listen: 443 in /etc/httpd/conf.d/ssl.conf file
npm

util global modules

sudo npm i -g depcheck; run: depcheck (analyze the dependencies in a project to see: how is used or useless)
sudo npm i -g npm-check-updates ; run: ncu (checks npm modules updates)

install eslint in project

  1.  npm i eslint --save-dev;
  2. npm init @eslint/config; 
  3. npx eslint ./ (optional : check problems in current directory) 
  4. npx eslint ./ --fix (optional : fix problems in current directory) 
pm2

Process Management

  1. sudo npm install pm2@latest -g
  2. pm2 ecosystem
  3. pm2 save
  4. pm2 [list|ls|status]
  5. pm2 logs

ecosystem config

module.exports = {
apps : [{
   name: 'okai',
   script: 'dist/index.js',
   exec_mode : 'cluster',
   autorestart: true,
   watch: ['dist/**/*.js'],
   ignore_watch : ["node_modules/**/*"]
 }]
};