TOC
Links to external resources
- https://cheatsheets.zip/cpp
- The Book of Secret Knowledge The repo includes variety of tools, shell commands related to CLI.
- https://quickref.me/
- https://devhints.io/
Linux General Commands
awk
awk is used to filter and manipulate output from other programs and functions. Slices the line from empty spaces and assign them to vars. Patterns are enclosed in curly braces {}
. Together, a pattern and an action form a rule. The entire awk program is enclosed in single quotes '
.
# $0: Represents the entire line of text.
# $1: Represents the first field.
# $2: Represents the second field.
# $7: Represents the seventh field.
# $45: Represents the 45th field.
# $NF: Stands for "number of fields," and represents the last field.
who | awk '{print $1, $4}'
# OFS (output field separator) variable to put a separator between the month, day, and year.
date | awk 'OFS="/" {print$2,$3,$6}'
# Separate the lines using ":"
cat /etc/passwd -n | awk -F: '{print $1}'
cat
# Display CPU information.
cat /proc/cpuinfo
# enter text into the file (overwrite)
cat > FILE_NAME
# enter text at the end of the file (append)
cat >> FILE_NAME
caffeinate
# Stay awake your Computer (on Mac OS)
caffeinate -dis
curl
https://www.youtube.com/watch?v=BuEYquQweGo
date
# Display current date
date
du
du
command lists directories (folders) and files
# use human-readable sizes
du -h -d1
# look down 3 levels and only show folders above a threshold size
du -h -d3 -t10G
# list directories and sort by size
du -h | sort -hr
# only show top 10 directories
du -h | sort -hr | head -n10
# list directories in current folder, threshold 10G, sort with human-readable sizes, top 10
du -h -d1 -t10G | sort -hr | head -n 10
# find files larger than a size, list with details
find . -size +200M -exec ls -lh {} \;
# find files and folders, list with details
find . -size +200M -exec du -hs {} \;
# find files and folders, list with details, sort, top 10
find . -size +200M -exec du -hs {} \; | sort -hr | head -n 10
echo
# remove all text context in a file
echo "" > file_name.txt
# List content of $PATH output line-by-line
echo $PATH | tr : '\n'
find
# Find files starting at current location and containing text in name
sudo find . -iname FILE_OR_FOLDER-NAME
# Find "webui-user" folder in the "/var/lib" location. Non-case sensitive
sudo find /var/lib -iname "webui-user" -type d
# find case insensitive
sudo find . -iname FILE_OR_FOLDER-NAME -d 3
# find files over a certain size
sudo find . -size +200M
# Find "webui-user" file in the "/var/lib" location.
sudo find /var/lib -iname "webui-user"
gcc
# Display C++ compiler
gcc --version
grep
tool used for searching and manipulating text patterns within files.
# List running process including teamviewer.. and rest of possible characters
sudo ps -e | grep 'teamviewer*'
# List files including "input" word
ls | grep "input"
# output -> .rw-r--r--@ 3.0M alptugan 29 Nov 00:39 input.pdf
head / tail
# View the first line of the file
head -n 1 FILE_NAME
# View the last line of the file
tail -n 1 FILE_NAME
lm-sensors
# List sensors
sudo sensors-detect
# Monitor sensor values
watch sensors|
ls
# List files with human readable file size on disk.
ls -lh
# Display CPU information.
lscpu
# Display list of HDD block devices.
lsblk
nvidia-smi
# Display NVIDIA GPU information.
nvidia-smi -q
# Display in a table. For continous update check watch
nvidia-smi --query-gpu=gpu_name,gpu_uuid --format=csv
pkill
# Kill a running app by calling its absolute path
sudo pkill -f -9 /home/filika/Desktop/irlz540.py
ps
# list running process with name
sudo ps -e | grep 'mysqld'
# list running scripts with prefix
ps -ef | grep "irlz*"
rm
# Delete the folder_name directory and file_name document
rm -rf folder_name/ file_name
rsync
# display copied file names
rsync -av source_folder/ target_location
# Display progress
rsync -ah --progress source_folder/ target_location
# Copy large files, stop and resume from the last state.
rsync -ah --progress –partial source_folder/ target_location
# remote copy
rsync -ahP source_folder user@192.168.1.247:/user/
scp
# Copy a file from Mac to Windows
scp Remote.It-Installer-x64.exe filika@192.168.1.100:C:\Users\ASUS\Desktop
sed
# The ****SED (Stream Editor)**** command in Unix/Linux is a powerful utility used to process and manipulate text in files. It can perform a variety of operations such as searching, find-and-replace, insertion, deletion, and more, without the need to open the file in an editor.
systemctl
# Grep anything that has prefix `teamwiever`
systemctl | grep "teamviewer*"
# Disable and remove service from autostart.
sudo systemctl disable teamviewerd.service
# Enable and add service from autostart.
sudo systemctl enable teamviewerd.service
tar
# Compress html folder at the /var/www/html location
# -C tells the script to go to /var/www directory and zip the html folder.
# The zipped folder will appear in the current directory path where the user works
tar -zcf backup.tar.gz -C /var/www html
# Execute command in an another command via $() syntax... to add date as suffix
tar -zcf /home/tony/backup/daily/backup-$(date +%Y%m%d).tar.gz -C /var/www/ html
# Extract compressed files
tar -xzvf backup.tar.gz
timedatectl
# List time zone names
timedatectl list-timezones
# Set time zone
sudo timedatectl set-timezone Europe/Istanbul
# Enable the service
sudo timedatectl set-ntp on
# Check the current date-time
timedatectl
uname
# 32-Bit: armv6l,armv7l,armv8,armhf
# 64-Bit: arm64, aarch64
# Get dist name
uname -m
# Processor architecture.
uname -p
# Get dist name and release name
uname -m && cat /etc/*release
ufw
# Set firewall and port accesibility
ufw allow 22
# Disable port 22
ufw deny 22
udisksctl
# Display HDD brand names within /dev
udisksctl status
watch
# Execute a program periodically, showing output fullscreen.
# Re-run a command every 60 seconds:
watch -n 60 command
# Repeatedly run a command and show the result:
watch command
# Monitor the contents of a directory, highlighting differences as they appear:
watch -d ls -l
# Repeatedly run a pipeline and show the result:
watch 'command_1 | command_2 | command_3'
# Monitor GPU usage realtime, update every second
watch -n 1 nvidia-smi
Docker Basics
# List docker images
docker ps
# Login docker image folder. Type `exit` to log-out
docker exec -it <container_id> /bin/bash
# Display docker-compose content
docker inspect dc87f8ea23aa
# Stop running docker
docker stop docker_name
# Restart docker containers
sudo systemctl restart docker
Documentation on basic usage Blog-post on DEV site.
Locations
/etc/docker/daemon.json
/var/lib/docker/containers → include casaos failed folders as well
/var/lib/casaos/www → webpage location
/var/lib/casaos/apps → docker-compose.yml
# Autostart application on desktop startup for Raspberry Pi
/etc/xdg/autostart/
sudo nano starter.desktop
.ssh/config file
ProxyCommand docker exec -i cloudflared cloudflared access ssh --hostname %h
Bash Cheat Sheet
Troubleshooting
Temporary failure resolving ‘archive.ubuntu.com’
Here are some steps to diagnose and resolve the issue:
- Check Network Connectivity:
- Run
ping 8.8.8.8
to check if your system can connect to the Google DNS server. If this fails, it could indicate a broader network issue.
- Run
- Check System Services:
- Run
sudo systemctl status systemd-resolved
to check the status of the systemd-resolved service. If it is stopped, start it usingsudo systemctl start systemd-resolved
.
- Run
- Check Current DNS Servers:
- Run
sudo resolvectl
to see your current upstream DNS servers.
- Run
By following these steps, you should be able to identify and resolve the issue causing the “Temporary failure resolving ‘archive.ubuntu.com’” error.
SSH Keys
I generated these keys on my local machine
.ssh/id_rsa → the private key
.ssh/id_rsa.pub → public key
https://www.youtube.com/watch?v=_FXyQso1H50 (guacamole)
Run docker container’s command
# Go to .ssh/ folder
# edit the config file as follows
Host ssh-filika.damp-server.org
# ProxyCommand /usr/local/etc/cloudflared access ssh --hostname %h
ProxyCommand docker exec -i cloudflared cloudflared access ssh --hostname %h
Uninstall package on Debian
sudo apt autoremove --purge Stremio
NVIDIA Encoding/Decoding codecs → link
/etc/docker/daemon.json
{
"hosts": [
"tcp://0.0.0.0:2375",
"unix:///var/run/docker.sock"
],
"default-runtime": "nvidia",
"runtimes": {
"nvidia": {
"path": "/usr/bin/nvidia-container-runtime",
"runtimeArgs": [
"--gpus",
"all"
]
}
}
}