Персеиды, Калязин и радиотелескоп

Каждый год рядом с Землей пролетает большое облако метеоритов, которое называется Персеиды.

У меня становится традицией выбираться за город и наблюдать это космическое явление :-)
В этот раз в поисках чистого неба и красивого вида мы с другом решили забраться довольно далеко – под Калязин.

Итак, начнем!

Continue reading “Персеиды, Калязин и радиотелескоп”

Useful Linux commands

Find directory size:

https://askubuntu.com/a/1226
du -hs /path/to/directory
cd to dir which size you want to know
du -chd 1 | sort -h (1 – subdirs shown in output, size output value not affected when changing)

Show HDD space usage:

df -h
Interesting utulity showing extended info about disk usage:
https://dev.yorhel.nl/ncdu

Show HDD’s installed in the system:

fdisk -l

Su as another user:

su USERNAME

Sleep in scripts

Example:
sleep .5 # Waits 0.5 second.
sleep 5 # Waits 5 seconds.
sleep 5s # Waits 5 seconds.
sleep 5m # Waits 5 minutes.
sleep 5h # Waits 5 hours.
sleep 5d # Waits 5 days.
One can also employ decimals when specifying a time unit; e.g. sleep 1.5s
https://stackoverflow.com/questions/21620406/how-do-i-pause-my-shell-script-for-a-second-before-continuing

Find specific word in file:

grep -a “WORD-WE-NEED” /var/log/some.log

Watch for changes in file (usually we need to watch small status log):

watch -n 1 cat /var/log/some-status.log

Stress-test CPU:

https://ph0en1x.net/102-linux-cpu-stress-test-load-cores-tools.html
yes > /dev/null

Clear, remove, erase bash history::

cat /dev/null > ~/.bash_history && history -c
https://askubuntu.com/a/192001

Move all data from larger Linux Ubuntu partition to a smaller disk::

Prepare smaller VMDK
Stop original VM and copy VMDK in case of something going wrong to a safe place
Connect both old large and new small to a fresh created Ubuntu VM
Decrease old partition to fit new disk
Delete swap partition from original disk
Copy decreased partition with data to a new disk using dd: dd if=/dev/sdb of=/dev/sdc status=progress
Create swap partition on the new small disk and set it’s type as swap
Connect new small VMDK to original VM
Create swap file:
mkswap /dev/sda2
fallocate -l 512M /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
swapon --show
free -h

Discover current swap partition’s UUID by typing blkid
Setting new swap partition’s UUID in /etc/fstab.
Test how VM is running
If everyting is OK delete old original VMDK and it’s copy

Change swapfile size:
swapoff -a
rm -rf /swapfile
fallocate -l 512M /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
swapon --show
free -h

Check fstab for correct swap file record:
cat /etc/fstab
Add swap file if no relevant found in fstab:
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Very useful swap file configuration:
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04

Scan subnet with result displaying MAC and IP addresses:

https://linuxhint.com/use-nmap-scan-subnet/
nmap -sP 192.168.0.1/24

Free disk space removing, deleting, flushing apt cache:

https://www.cyberciti.biz/faq/can-i-delete-var-cache-apt-archives-for-ubuntu-debian-linux/
Cache is located in /var/cache/apt/archives
apt-get clean
apt-get autoremove
rm -rf /var/lib/apt/lists/*
apt-get update -y
ls -l /var/cache/apt/archives

Check disk space usage by folders and files:

https://askubuntu.com/questions/36111/whats-a-command-line-way-to-find-large-files-directories-to-remove-and-free-up

apt-get install ncdu
or
apt-get install gt5

Echo shell commands as they are executed:

https://stackoverflow.com/a/2853843
#!/bin/bash
set -x #echo on

ls $PWD

Sed

-i – Изменить и сохранить указанный документ

Заменить foo на too в первой найденной строке.
$ sed -i ‘s/foo/too/’

Заменить foo на too во всем файле.
$ sed -i ‘s/foo/too/g’

Удалить 14ю строку.
$ sed -i ’14d’ /file

Удалить строку содержащую Network или network.
$ sed -i ‘/[Nn]etwork/d’ /file

Добавить в конец файла “[mounts]” затем перенос на новую строка и “user root”.
$ sed -i ‘$ a \\n[mounts]\nuser root’ /etc/munin/config

После 14ой строки добавить “echo “graph_category logger””.
$ sed ’14a\ echo \”graph_category logger\”‘ /etc/munin/plugins/command

Вставить в начало файла ‘# vim: ft=ruby’ и перенос строки.
$ sed ‘1i # vim: ft=ruby\n’

Заменить повторяющиеся пустые строки на одну пустую строку
$ sed -e ‘:a;/^$/N;/\n$/{D;ba}’ file.txt

Конвертация переносов строк DOS (CR/LF) в Unix (LF)
$ sed ‘s/.$//’ dosfile.txt > unixfile.txt

Заменить строку string1 строкой string2
$ sed ‘s/string1/string2/g’

Изменить строку anystring1 на anystring2
$ sed ‘s/\(.*\)1/\12/g’

Убрать комментарии и пустые строки
$ sed ‘/ *#/d; /^ *$/d’
sed -i “/^$/d” file.txt #-i для изменения внутри документа

Соединить строки (линии) с предшествующим \
$ sed ‘:a; /\\$/N; s/\\\n//; ta’

Удалить предшествующие пробелы с строк
$ sed ‘s/[ \t]*$//’

Заескейпить активные метасимволы оболочки двумя ковычками
$ sed ‘s/\([\\`\\”$\\\\]\)/\\\1/g’

Выровнять числа по правой границе
$ seq 10 | sed “s/^/ /; s/ *\(.\{7,\}\)/\1/”

Напечатать 1000-ную строку
$ sed -n ‘1000p;1000q’

Напечатать строки с 10 по 20-ую
$ sed -n ‘10,20p;20q’

Получить title из HTML страницы
$ sed -n ‘s/.*

 

Частично взято отсюда, спасибо автору!

Nano

Make Nano show line numbers:
sed -i ‘/# set constantshow/c\set constantshow’ /etc/nanorc

Go to the end of file:
Ctrl + w + v

Start selecting text:
Ctrl + 6

Failed to deploy OVF package: The task was canceled by a user.

Если OVA:
– распаковать OVA файл с виртуальной машиной используя Winrar или 7zip;
– изменить расширение .mf файла (например на mf-)
– отыскать CD-ROM: vmware.cdrom.iso в .ovf файле
– изменить iso на atapi
– экспортировать распакованное содержимое, выбрав отредактированный .ovf файл

https://communities.vmware.com/thread/431021

https://tm-experimental.blogspot.com/2013/11/failed-to-deploy-ovf-package-task-was.html