___ _____ _ _ _ _
|_ _|_ _| ___| |__ ___ __ _| |_ ___| |__ ___ ___| |_
| | | | / __| '_ \ / _ \/ _` | __| / __| '_ \ / _ \/ _ \ __|
| | | | | (__| | | | __/ (_| | |_ \__ \ | | | __/ __/ |_
|___| |_| \___|_| |_|\___|\__,_|\__| |___/_| |_|\___|\___|\__|
# shell
# 0. command or attribution?
# 1. solve redirections
# 2. expand {}
# 3. replace variables
# 4. replace meta characters: *, ?
# 5. replace aliases, verify if a file exists, and its permissions
# 6. send command to kernel
# debian
# to check debian version
lsb_release -a
# to clean /var/cache
sudo apt clean
# ways to clean /var/log/journal
sudo journalctl --rotate
sudo journalctl --vacuum-size=100M # limit logs to 100 Mb
sudo journalctl --vacuum-time=5d # delete logs older than 5 days
sudo journalctl --vacuum-file=2 # restrict number of log files
# Note: The “–vacuum-files” option will not delete the files that are currently active or in use.
# need to restart service after commands above
sudo service systemd-journald restart
# Reference
# https://itslinuxfoss.com/fix-big-var-log-journal/
# https://linuxhandbook.com/clear-systemd-journal-logs/
# generating ssh key
ssh-keygen -t rsa -b 4096 -C <e-mail> -f <keyfile>
chmod 600 <private keyfile>
emacs: $HOME/.emacs
bash:
/etc/bashrc contains system wide aliases and functions;
/etc/profile contains system wide environment stuff and startup programs;
$HOME/.bashrc contains user aliases and functions;
$HOME/.bash_profile contains user environment stuff and startup programs;
$HOME/.inputrc contains key bindings and other bits.
/etc/aliases
rm -i;cp -i;mv -i;ls -ld
It's a good idea to let new users have a few configuration files ready
when they first log in. Put the following files in /etc/skel:
.bashrc .bash_profile .bash_logout .inputrc .less .xinitrc
.fvwmrc .fvwm2rc95 .Xmodmap .Xdefaults .jedrc .abbrevs.sl. joerc
.emacs
The user can overwrite values set in /etc/profile by creating a file:
~/.bash_profile, ~/.bash_login or ~/.profile.
Note that just the first one of these is executed thus differing
of the logic of csh initialization.
~/.bash_login is not executed specially for login shells
and if .bash_profile exists, it is not executed at all!
debug: put in the 1st line: #!/bin/bash -x
other commands (common options):
tar -zcvf [destiny] [source]
tar -zxvf [destiny] [source]
rsync: verify remote files
nmap -sS [host] (run as root)
wget -r l6 -t1 [URL] (-L is just relative links)
to see system data:
uname -a
dmesg
ulimit -a
df -k
hostname
domainname
cat /etc/sysconfig/network
ifconfig
netstat -nr
netstat -a
cat /etc/inetd.conf
cat /proc/meminfo
cat /proc/filesystem
cat /proc/devices
cat /etc/passwd
to cleanup dos files:
vi : :%s/^V^M//g
shell: sed `s/^V^M//g` foo>foo.new
other commands (common options):
tar -zcvf [destiny] [source]
tar -zxvf [destiny] [source]
rsync: verify remote files
nmap -sS [host] (run as root)
nmap -sT [host] -P0
wget -r l6 -t1 [URL] (-L is just relative links)
# isolate process
ps -def | grep Xvnc | grep -v grep | awk -F" " '{print $2}'
# crontab
# to see
crontab -l
# to edit
export EDITOR=vi;crontab -e
# crontab format:
# 0 0 * * * calendar
# ^ ^ ^ ^ ^ ^
# | | | | | |
# 1 2 3 4 5 6
# (1) minutes (0 a 59)
# (2) hour (0 a 23)
# (3) day (1 a 31)
# (4) month (1 a 12)
# (5) day of the week (0 a 6, where 0 is Sunday)
# (6) command (it's good to redirect output to /dev/null)
# * means all possible values
# - means a range
# example:
# 0,10,20,30,40,50 * * * rmtrash
# rmtrash will be executed each 10 minutes
# to check encoding:
file -i >file<
# to list available encoding to convert
iconv -l
# to convert encoding
iconv -f >old encode< -t >new encode< >input.file< -o >output.file<
# Git - cheat sheet
# to use ssl connection, create a ssh key and upload the public key to git repository
git clone git@<site>:<username>/<project>.git # clone using SSL
git add -A
git commit -m <message>
git log # to see all commits
git push origin main
# or
git push origin master
# commit messages
The commit type can include the following:
feat – a new feature is introduced with the changes
fix – a bug fix has occurred
chore – changes that do not relate to a fix or feature and don't modify src or test files (for example updating dependencies)
refactor – refactored code that neither fixes a bug nor adds a feature
docs – updates to documentation such as a the README or other markdown files
style – changes that do not affect the meaning of the code, likely related to code formatting such as white-space, missing semi-colons, and so on.
test – including new or correcting previous tests
perf – performance improvements
ci – continuous integration related
build – changes that affect the build system or external dependencies
revert – reverts a previous commit
Reference: https://www.freecodecamp.org/news/how-to-write-better-git-commit-messages/
# Debian static IP configuration
Reference: https://linuxhint.com/debian-static-ip-configuration/
/etc/network/interfaces:
# The primary network interface
# allow-hotplug enp0s3
auto enp0s3
iface enp0s3 inet static
address 192.168.0.152
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 208.67.222.222 208.67.220.220 8.8.8.8 4.4.4.4
---
then reboot the computer
# Add user to sudoers
usermod -aG sudo <user>
groups <user> # to verify
# Samba
apt install samba
apt install cifs-utils # to mount external smb shares
# /etc/samba/smb.conf - basic sharing
[global]
allow insecure wide links = yes
log file = /var/log/samba/%m
log level = 1
name resolve order = lmhosts wins host bcast
workgroup = WORKGROUP
[<user>]
# This share requires authentication to access
path = /home/<user>
read only = no
follow symlinks = yes
wide links = yes
# create a smb user to access the shares
smbpasswd -a <user>
# sha generation (in this example, using sha512sum)
echo <statement>|sha512sum
# Python
# virtual environment
# create
python -m venv <myEnvironment>
# activate
source <myEnvironment>/bin/activate
# deactivate
deactivate
# install npm
apt install npm
# npm commands
npm install # Install a package
npm uninstall # Remove a package
npm unstar # Remove an item from your favorite packages
# install yarn - https://www.sitepoint.com/yarn-vs-npm/
npm install -g yarn
# install a new version of Node
npm install -g n
n lts
npm update [-g <pkg>]
# docker commands
docker image ls
docker run [-p <host_port>:<container_port>] [-v <host_folder>:<container_folder>] <container>
docker cp <folder>/<file> <container_id>/<folder>/<file>
docker ps
docker exec -it <container> /bin/bash # or other command
docker stop <container>
docker build -t <image-tag>
docker login --username <username>
docker push <image-tag>
# docker-compose
docker-compose up
Free Online HTML Escape Tool