Cron

List cron

crontab -l

List cron pour root

sudo crontab -l

Curl

Set HTTP METHOD

curl -X POST

Add header

curl  -H "header-name: header-value"

Deletion

Shred to securely delete

shred -n 25 -z -u *

SystemD

Logs

journalctl -f -u hubot

Clean Output

echo "otot" >/dev/null

Sudo

sudo su

sudo -i -u root
ln  -s  source  destination

List directories with for loop

for i in $(ls -d */); do echo ${i%%/}; done

Find by name

find directory -name namepattern

Find and delete

useful when rm …​ does not work

find . -name "logs*.txt" -delete
find . -type d -name ".aws-sam" -exec rm -r {} \;
find . -type d -name "cdk.out" -exec rm -r {} \;
find . -type d -name "node_modules" -exec rm -r {} \;
find . -type d -name ".angular" -exec rm -r {} \;
find . -type d -name "target" -exec rm -r {} \;

Find by date

find /mnt/ -mindepth 3 -mtime +26


find /mnt/ -mindepth 3 -mmin +720 | ls -ltha


find . -mtime +50 | ls -ltha

#more than 5 days, list
find . -mtime +5 -ls

# more than 5 days, list and delete
find . -mtime +5 -ls -delete

# filter name
find . -mtime +2 -name "*.ts" -ls

find . -mtime +5 -name "*.ts" -ls -delete

Change file content

sed -i 's/old/new/g' myfile

List folder size

du -hs /path/to/directory

Par dossier

du -h /path/to/directory

Pour un dossier donné, liste des tailles de sous fichier

sudo du -hH --max-depth=1 . | sort -h

Lister tous les fichiers par taille

find . -type f  -exec du -h {} + | sort -r -h

SCP

Encryption

openssl [encryption type] -in [file to encrypt]
openssl aes-256-cbc -in in.txt -out out.txt
openssl aes-256-cbc -d -in encrypted.txt -out normal.txt

Show hidden files

chflags nohidden /path/to/the/file/to/change

Archive

tar cvfz archive.tar.gz spencel1 fichierarchive2...

Public/Private Keys

ls ~/.ssh/*.pub
cat ~/.ssh/id_rsa.pub

Sudo

Declare new sudo

/etc/sudoers

SSH

Création clé SSH avec email

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Droits sur les répertoires

  • your home directory ~, your ~/.ssh directory and the ~/.ssh/authorized_keys file on the remote machine must be writable only by you: rwx------ and rwxr-xr-x are fine, but rwxrwx--- is no good¹, even if you are the only user in your group (if you prefer numeric modes: 700 or 755, not 775).

  • If ~/.ssh or authorized_keys is a symbolic link, the canonical path (with symbolic links expanded) is checked.

  • Your ~/.ssh/authorized_keys file (on the remote machine) must be readable (at least 400), but you’ll need it to be also writable (600) if you will add any more keys to it.

  • Your private key file (on the local machine) must be readable and writable only by you: rw-------, i.e. 600.

Copy SSH KEY

ssh-copy-id -i myfile user@123.45.56.78

Load known_host

KNOWN_HOST

ssh-keyscan -t rsa myhost

Service

Script Jenkins /etc/default/jenkins service status-all

Redhat

Redhat chkconfig tool

chkconfig provides a simple command-line tool for maintaining the /etc/rc[0-6].d directory hierarchy by relieving system administrators of the task of directly manipulating the numerous symbolic links in those directories. chkconfig has five distinct functions: adding new services for management, removing services from management, listing the current startup information for services, changing the startup information for services, and checking the startup state of a particular service.

Add service called foo

This option adds a new service for management by chkconfig:
# chkconfig --add foo

Delete service called foo

The service is removed from chkconfig management, and any symbolic links in /etc/rc[0-6].d which pertain to it are removed:
# chkconfig --del foo

List status for foo service

This option lists all of the services which chkconfig knows about, and whether they are stopped or started in each runlevel.
# chkconfig --list foo

Memory by process

ps -o pid,user,%mem,command ax | sort -b -k3 -r

sudo pmap 917

Turn on or off services:

# chkconfig foo on
# chkconfig foo off
# chkconfig --level 2 foo on

Note that –level 35 specifies run levels 3 and 5, so following will turn on httpd service for 3 and 5 only:
# chkconfig --level 35 httpd on

This command might be needed to avoid the password ssh key

restorecon -R -v ~/.ssh
Add -R option
chmod -R +r myfolder

Tar

Compress tar czvf toto.tar.gz

Option Mnemonics: tar xzvf = Xtract Ze Vucking Files [said in thick German accent]

EXtract tar xzvf toto.tar.gz folder

Brew

brew update && brew upgrade && brew cleanup && brew doctor