====== generic cli command cheatsheet ======
===== OS version =====
==== find debian dist version ====
$ cat /etc/debian_version
11.5
==== find ubuntu dist version ====
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy
==== find alpine dist version ====
$ sudo cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.16.2
PRETTY_NAME="Alpine Linux v3.16"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
===== sudo =====
==== sticky sudo ====
ubuntu@kamaradski:~$ sudo -i
root@kamaradski:~#
==== add user to sudo ====
# change to superuser
someuser@server$ su
password:
# add some user to sudo
root@server$ /sbin/usermod -aG sudo someuser
# confirm user is added
root@server$ getent group sudo
sudo:x:27:someuser
# test that it works
root@server$ su - someuser
someuser@server$ sudo whoami
[sudo] password for someuser:
root
===== user and group management =====
==== add user (interactive) ====
$ adduser kamaradski
Adding user `kamaradski' ...
Adding new group `kamaradski' (1000) ...
Adding new user `kamaradski' (1000) with group `kamaradski' ...
Creating home directory `/home/kamaradski' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for kamaradski
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
===== RAM stats =====
==== type and speed of RAM ====
$ dmidecode --type 17
# dmidecode 3.3
Getting SMBIOS data from sysfs.
SMBIOS 3.0.0 present.
Handle 0x0037, DMI type 17, 40 bytes
Memory Device
Array Handle: 0x0036
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 4 GB
Form Factor: DIMM
Set: None
Locator: DIMM_A1
Bank Locator: BANK 0
Type: DDR4
Type Detail: Synchronous
Speed: 2400 MT/s
Manufacturer: 859B
Serial Number: 24C500AF9
Asset Tag: 9876543210
Part Number: CT4G4DFS824A.M8FE
Rank: 1
Configured Memory Speed: 2133 MT/s
Minimum Voltage: 1.2 V
Maximum Voltage: 1.2 V
Configured Voltage: 1.2 V
Handle 0x0038, DMI type 17, 40 bytes
Memory Device
Array Handle: 0x0036
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 4 GB
Form Factor: DIMM
Set: None
Locator: DIMM_B1
Bank Locator: BANK 2
Type: DDR4
Type Detail: Synchronous
Speed: 2400 MT/s
Manufacturer: 859B
Serial Number: 24C59B2F
Asset Tag: 9876543210
Part Number: CT4G4DFS824A.M8FE
Rank: 1
Configured Memory Speed: 2133 MT/s
Minimum Voltage: 1.2 V
Maximum Voltage: 1.2 V
Configured Voltage: 1.2 V
==== freeBSD => sorted list of processes by total size (res, swap, libraries etc etc) ====
$ top -S -w -o size
==== freeBSD => sorted list with top res (physical memory) ====
$ top -S -w -o res
==== freeBSD => sorted list by swap ====
$ top -S -w -o swap
===== cpu stats =====
==== find architeture ====
$ uname -m
# x86_64 => 64-bit version of the x86 (normal Intel or AMD)
# aarch64 => shows with ubuntu in VM on Arm
# arm64 => apple M1/M2
==== find all cpu details ====
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 39 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Vendor ID: GenuineIntel
Model name: Intel(R) Celeron(R) 2955U @ 1.40GHz
CPU family: 6
Model: 69
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 1
Stepping: 1
CPU max MHz: 1400.0000
CPU min MHz: 800.0000
BogoMIPS: 2793.57
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss
ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc
cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg cx16 xtpr pdcm pcid sse4_1 sse4_2
movbe popcnt tsc_deadline_timer xsave rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb sti
bp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust erms invpcid xsaveopt dtherm arat pln pts
md_clear flush_l1d
Virtualization features:
Virtualization: VT-x
Caches (sum of all):
L1d: 64 KiB (2 instances)
L1i: 64 KiB (2 instances)
L2: 512 KiB (2 instances)
L3: 2 MiB (1 instance)
NUMA:
NUMA node(s): 1
NUMA node0 CPU(s): 0,1
Vulnerabilities:
Itlb multihit: KVM: Mitigation: VMX disabled
L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT disabled
Mds: Mitigation; Clear CPU buffers; SMT disabled
Meltdown: Mitigation; PTI
Mmio stale data: Unknown: No mitigations
Retbleed: Not affected
Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Spectre v2: Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP disabled, RSB filling, PBRSB-eIBRS Not affected
Srbds: Mitigation; Microcode
Tsx async abort: Not affected
===== time sync =====
related config file: /etc/systemd/timesyncd.conf
==== current time ====
$ date
Sat Nov 12 14:57:27 CET 2022
==== check state ====
$ timedatectl
Local time: Mon 2022-10-31 17:39:26 CET
Universal time: Mon 2022-10-31 16:39:26 UTC
RTC time: Mon 2022-10-31 16:39:26
Time zone: Europe/Berlin (CET, +0100)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
==== detailed status ====
$ systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-11-15 20:27:34 CET; 58min ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 2680819 (systemd-timesyn)
Status: "Initial synchronization to time server 51.75.67.47:123 (pool.ntp.org)."
Tasks: 2 (limit: 1068)
Memory: 1.2M
CPU: 51ms
CGroup: /system.slice/systemd-timesyncd.service
└─2680819 /lib/systemd/systemd-timesyncd
Nov 15 20:27:34 hostname systemd[1]: Starting Network Time Synchronization...
Nov 15 20:27:34 hostname systemd-timesyncd[2680819]: Invalid PollIntervalMinSec=. Using default value.
Nov 15 20:27:34 hostname systemd-timesyncd[2680819]: PollIntervalMaxSec= is smaller than PollIntervalMinSec=. Using default value.
Nov 15 20:27:34 hostname systemd[1]: Started Network Time Synchronization.
Nov 15 20:27:45 hostname systemd-timesyncd[2680819]: Timed out waiting for reply from 172.67.191.29:123 (ntp.somewhere.com).
Nov 15 20:27:55 hostname systemd-timesyncd[2680819]: Timed out waiting for reply from 104.21.60.32:123 (ntp.somewhere.com).
Nov 15 20:28:05 hostname systemd-timesyncd[2680819]: Timed out waiting for reply from [2606:4700:3037::6815:3c20]:123 (ntp.somewhere.com).
==== set timezone ====
$ sudo timedatectl set-timezone America/New_York
==== turn ntp on (22.04 and above) ====
$ sudo timedatectl set-ntp on
===== wc (word count) =====
==== count of string lenght ====
$ echo "some-very-long-string" | wc -c
22
===== lsof (list open files) =====
==== list anything that is listing on a specific port ====
$ sudo lsof -i :53
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
systemd-r 629 systemd-resolve 13u IPv4 16505 0t0 UDP localhost:domain
systemd-r 629 systemd-resolve 14u IPv4 16506 0t0 TCP localhost:domain (LISTEN)
===== curl =====
==== download a file (and follow any redirects) ====
$ curl -LO https://path.to/some/file.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 11.0M 100 11.0M 0 0 6226k 0 0:00:01 0:00:01 --:--:-- 10.9M
===== symlink =====
==== create symlink ====
$ ln /path/some/source.file /path/target/link.name
use -f to force a new symlink (overwrite)
use -s for a soft-link
===== zip/tar/etc =====
==== un-tar file, keep same structure ====
$ tar -xvf some_file.tar.gz
./somefolderinsidethezip/
./somefolderinsidethezip/file1
./somefolderinsidethezip/file2.txt
===== scp =====
==== from remote to local ====
$ scp user@remotehost:/source/folder/file.ext /local/target/folder/
file.ext 15% 5706MB 56.8MB/s 09:21 ETA
==== from local to remote host ====
$ scp /local/file.ext user@remotehost:/remote/target/folder/
file.ext 8% 3191MB 18.1MB/s 31:36 ETA
==== notes ====
- By default, when the target on the remote system is a directory and you don't provide a filename, scp expects that the source file name should be used. However, you must ensure that the directory path does not include a trailing slash if you don't specify the filename explicitly.
- Make sure to always use proper paths for the files you are copying. For example for a file in the local folder from where you are issuing the command use "./local.file" instead of just "local.file". This will prevent issues with SCP misinterpreting your intentions.
===== other =====
==== track the output of a command by executing it every x-time ====
$ watch -n 1 docker ps
#display the output of "docker ps" and update it every 1 second (-n 1) including a screen refresh/clear. default to 2sec without -n parameter.