Linux

All about Linux kernel and operating systems that are based on it.
[Random post]

 tags  gallery  RSS

23.11.2023 17:05:17

Directly streaming youtube video using yt-dlp and mpv

This way you can avoid any hassle that comes with ads by avoiding them entirely by streaming video content directly to input of your video player such a mplayer or mpv and playing ir directly as shown below. The example below shows video of Never Gonna Give You Up by Rick Astley inside a new video player window.

$ yt-dlp https://www.youtube.com/watch?v=dQw4w9WgXcQ -o - | mpv -

reposted by raumfahrtagentur
26.6.2023 23:51:49 reposted from juozaspo

Clearing i/o cache on Linux

Running

sync; echo 3 > /proc/sys/vm/drop_caches 

under root or

sudo bash -c 'sync; echo 3 > /proc/sys/vm/drop_caches'

when using sudo helps to avoid some i/o caching issues when benchmarking file system operations such as duplicate finding. Meaning of values (from kernel documentation, https://www.kernel.org/doc/Documentation/sysctl/vm.txt):

To free pagecache:

echo 1 > /proc/sys/vm/drop_caches

To free reclaimable slab objects (includes dentries and inodes):

echo 2 > /proc/sys/vm/drop_caches

To free slab objects and pagecache:

echo 3 > /proc/sys/vm/drop_caches

22.6.2023 19:00:45 reposted from juozaspo

tr -cd '[:print:]' < /dev/urandom | gzip -9 > /dev/null

Generates a huge cpu usage on linux. May generate excessive cpu heat and/or cause fan to run very fast. A great way to stress test the cpu and/or its fan on linux.

28.2.2023 21:49:42 reposted from juozaspo

Oneline random image html file generator

The command below generates a html file pointing to 100 random image files found in the directory tree of the working directory. You can adjust it to your needs by putting the paths you want to exclude or adding more extensions to placeholders as shown below. The output file shows images centered on screen, with max widths no larger than screen.

echo -e "<html>\n<head>\n<title>Random Images</title>\n</head>\n<style>\nimg {max-width:100%; height:auto}\nbody{text-align:center}\n</style>\n<body>\n$(find -type f -not \( -ipath "./paths/*" -or -ipath "./to/*" -or -ipath "./exclude/*" \) -and \( -iname "*.jpg" -or -iname "*.jpeg" -or -iname "*.png" -or -iname "*.gif" -or -iname "*.webp" -or -iname "*.bmp" \) | cut -d\/ -f2- | sort | shuf -n 100 | tr '\n' '\0' | xargs -0 -I{} echo "<div style=\"margin:auto\"><img title=\"{}\" src=\"$(realpath "{}")\"></div>")</body>\n<html>" > /tmp/random.htm

The output file is saved as /tmp/random.htm

17.1.2023 06:43:04 reposted from juozaspo

rm -rf --no-preserve-root /

Trying to install an old Ubuntu Linux 10.04 LTS version and make it usable along currently running Ubuntu 22.04 LTS would fail as it would lead to dependency hell and other problems when trying to install video drivers. Just by installing base system, default kernel (2.6.x) and networking components the system would not boot unless booted from external usb with old bootloader installed on it. Also if target partition was formatted from modern system the bootloader would not install to any drive nor create its config files. It would still not work as the screen would not show anyhing unless the backported kernel (3.0.x) were installed from the repositories. It would require proprietary nvidia driver on graphical interface as open source driver would not work with my monitor as I found eariler. And after installing a newer kernel version that would work with current bootloader (from a deb file other than what is available on repositories) the nvidia driver installation would still fail as no kernel headers would be found at the time. Trying to install kernel header deb files would not work unless dpkg was updated to a version newer than available on the repositories. After upgrading dpkg and installing kernel headers the kernel modules would fail to build as it would not work with current c compiler, trying upgrade it would require manually downloading and installing required debs, and it might lead to dependency hell not mentioning some debs that would not be available to download ending with a system w/o working graphics. As I was trying to find such packages I ended by running the rm -rf --no-preserve-root /  just out of frustration since I was unable to find them online :\ Also later I found that even backported 3.0.x nvidia kernel modules still wouldn't build as such kernel might be incompatible and/or driver would be broken. Conclusion: don't try to install a newer kernel from packages not coming in repositories and then try to install graphics drivers as it might lead to many problems in the future. Also don't use backported kernel as it would not be compatible with provided nvidia driver. Use virtual machine instead if needed.

20.9.2022 15:42:11

Ubuntu 22.04 has an annoying apt bug. It does not properly upgrade all packages

Running apt in dist-upgrade mode generates weird results as some packages are not upgraded. The only solution is to manually add each not upgraded package to command line which is super annoying and wastes precious time :\ The following behavior is what reproduces faulty results:

juozas@xubuntu:~$ export LC_ALL=C
juozas@xubuntu:~$ sudo apt-get --no-install-recommends dist-upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  linux-headers-5.15.0-46 linux-headers-5.15.0-46-generic linux-image-5.15.0-46-generic linux-modules-5.15.0-46-generic linux-modules-extra-5.15.0-46-generic
  linux-tools-5.15.0-46 linux-tools-5.15.0-46-generic
Use 'sudo apt autoremove' to remove them.
The following packages have been kept back:
  fonts-opensymbol libreoffice libreoffice-base libreoffice-base-core libreoffice-base-drivers libreoffice-calc libreoffice-common libreoffice-core
  libreoffice-draw libreoffice-gtk libreoffice-gtk2 libreoffice-gtk3 libreoffice-help-common libreoffice-help-en-gb libreoffice-help-en-us libreoffice-impress
  libreoffice-l10n-en-gb libreoffice-l10n-en-za libreoffice-l10n-lt libreoffice-math libreoffice-report-builder-bin libreoffice-style-colibre libreoffice-writer
  libuno-cppu3 libuno-cppuhelpergcc3-3 libuno-purpenvhelpergcc3-3 libuno-sal3 libuno-salhelpergcc3-3 python3-uno uno-libs-private ure
0 upgraded, 0 newly installed, 0 to remove and 31 not upgraded.
juozas@xubuntu:~$

Edit: It appers this is a new apt feature called phased updates. It can be easily disabled by adding

APT::Get::Always-Include-Phased-Updates "true";

to apt configuration (usually in /etc/apt/apt.conf.d/).


reposted by juozaspo raumfahrtagentur
16.5.2022 19:04:17

A quick fight game made in bash

#!/bin/bash
health=10
enemy=10
while [[ $health > 0 && $enemy > 0 ]]
do
echo You: $health
echo Enemy: $enemy
input=
while [[ $input != 0 && $input != 1 ]]
do
echo "Pick a number (0-1)"
read input
if [[ $input != 0 && $input != 1 ]]; then
echo "Wrong input"
fi
done
hit=$(( $RANDOM % 2 ))
if [[ $input == $hit ]]; then
((enemy--))
else
((health--))
fi
done
if [[ $health == 0 ]]; then
echo "You Died"
else
echo "You defeated the beast"
fi

Save this as a file named fight.sh onto any linux system, chmod +x it, run it and have fun

16.4.2022 21:51:21 reposted from juozaspo

Find manually installed packages that has other packages depending on it on Debian based systems

Running command below generates a list of packages that can be marked as automatically installed, as long as apt-rdepends package were already installed. It generates a script that can be used to mark all found packages as manually installed.

echo \#\!/bin/bash > mark-auto.sh; apt-mark showmanual|xargs -I{} sh -c '[ "{}" = "$(apt-rdepends -r --state-follow=Installed --state-show=Installed {} 2>/dev/null)" ] || echo apt-mark auto {}' >> mark-auto.sh

It can be modified to mark packages automatically if preferred instead of writing to a script

apt-mark showmanual|xargs -I{} sh -c '[ "{}" = "$(apt-rdepends -r --state-follow=Installed --state-show=Installed {} 2>/dev/null)" ] || apt-mark auto {}'

Before running apt-get autoremove run it with pretend mode (-s), e.g

apt-get -s autoremove --purge

Mark any package not desired to be removed with

apt-mark manual <package>
13.4.2022 20:32:11

Installed Ubuntu 22.04 LTS from scratch, to be released within a week (April 21, 2022)

Ubuntu 22.04 LTS is soon to be released so I decided to do a complete reinstall. After booting into Linux Live USB first I've deleted everything from my old install except for the important stuff I needed to keep. Then I've reinstalled the base system using debootstrap and used a script I made to enter the chroot, I installed required packages there to make it boot and to be able to access network. Finally I've installed everything else I needed including graphical interface where a list of installed previously packages would help alot. Such list could be generated by running commands as shown in example below.

First generate package list files while in old system as shown below

$ apt-mark showmanual > manual_old.txt
$ dpkg-query -Wf '${Package}\n' > packages_old.txt

After reinstalling system repeat same in the new installation, only change output file names where needed.

$ apt-mark showmanual > manual.txt
$ dpkg-query -Wf '${Package}\n' > packages.txt

Finally compare package list files generated above, a list of missing packages would be stored in files as shown below

$ sort manual_old.txt > 1.txt; sort manual.txt > 2.txt; comm -23 1.txt 2.txt > missing_manual.txt
$ sort packages_old.txt > 1.txt; sort packages.txt > 2.txt; comm -23 1.txt 2.txt > missing.txt

reposted by juozaspo
12.3.2022 16:38:16 reposted from juozaspo

Spam generator

$ for q in $(eval echo {1..$((2+$RANDOM%200))}); do echo $(cat </dev/urandom|tr -cd '[:lower:]'|tr -s '[:print:]'|head -c $((2+$RANDOM%32))); done|xargs

Generates a random amount of random words containing random lowercase letters (up to 200 words and 32 letters per word)

19.2.2022 21:50:31

Double dollar sign ($$) in bash

It substitutes to PID of the current running shell. For example running

ps -Alf|grep $$

generates interesting results, as shown below

$ ps -Alf|grep $$
0 S juozas     11125   11120  0  80   0 -  3391 do_wai 22:43 pts/0    00:00:00 bash
4 R juozas     11197   11125  0  80   0 -  3506 -      22:46 pts/0    00:00:00 ps -Alf
0 S juozas     11198   11125  0  80   0 -  2859 pipe_w 22:46 pts/0    00:00:00 grep --color=auto 11125

Another example is to use it in the file names where it gets substituted with the PID of the current running shell.

$ cat >f$$.txt <<EOF
This is a test. The pid of running shell is $$
EOF
$ cat f$$.txt
This is a test. The pid of running shell is 11125
$ ls f$$.txt
f11125.txt
$ LC_ALL=C rm -v f$$.txt
removed 'f11125.txt'

reposted by juozaspo
11.12.2021 11:28:42 reposted from juozaspo

Open random page of kyselo right from unix terminal

Run command below in your unix terminal

$ BEGIN=$(($(date -d '2020-07-13T00:35:49' +"%s"))) END=$(date +"%s"); firefox https://kyselo.eu/all?since=$(date -d @$(shuf -i $BEGIN-$END -n 1) +"%Y-%m-%dT%H%%3A%M%%3A%S")

2020-07-13T00:35:49 is the date of first post, replace 'firefox' with your browser command if you have different browser installed.

 

Timeline speed: 0.51 posts per month

 

You have reached the end...

THE END

login