Linux

All about Linux kernel and operating systems that are based on it.

 tags  RSS

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
23.12.2021 18:36:36

ffmpeg /dev/urandom test video 4 (mkv, low resolution)

from https://www.youtube.com/watch?v=jFqGCiQyH9Q

19.12.2021 09:14:13

Generate 1280x720 image with 16x9 grid containing random colors in each cell

$ dd if=/dev/urandom bs=1 count=432 of=in.bin

$ convert -depth 8 -size 16x9 rgb:in.bin -scale 1280x out.png


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.

5.12.2021 09:04:52


reposted by juozaspo memes naich schaaf
25.10.2021 11:43:17 reposted from juozaspo

28.6.2021 22:06:33 reposted from juozaspo

10.6.2021 23:43:15 reposted from juozaspo

Non native theme of the widgets on Mozilla Firefox looks ugly while using Linux. It can be disabled on about:config page.

7.6.2021 10:25:48 reposted from juozaspo

Me trying to compile some programs on Gentoo

from https://www.youtube.com/watch?v=XWMDjDXTuds

29.3.2021 20:11:49 reposted from juozaspo

20.9.2020 09:43:56 reposted from gpkvt

19.9.2020 09:33:13 reposted from gpkvt

23.8.2020 04:36:48 reposted from gpkvt

20.8.2020 17:47:44 reposted from gpkvt

17.8.2020 20:37:46 reposted from juozaspo

17.8.2020 20:37:36 reposted from juozaspo

Gentoo installation in virtualbox is never w/o bugs...
Triggered by running

# emerge --ask --verbose --update --deep --newuse @world
inside chroot on livecd

 

You have reached the end...

THE END

login