Some sed Tips
Put an * between the number 5 and 6
$ echo '12345678901234567890'| sed -e 's/^.\{5\}/&*/'12345*678901234567890
Put a comma between each number
$ echo "1234567890" |sed -e 's/./&,/g' -e 's/,$//'1,2,3,4,5,6,7,8,9,0
Put comma after every 2, if not even then last number exist by itself
$ echo "1234567890" |sed -e 's/../&,/g' -e 's/,$//'12,34,56,78,90
Red Hat Subscription Service
Once you have installed RHEL 9, register your RHEL subscription by running the following command on the terminal. The username and password are the login details to your Red Hat account.
$ sudo subscription-manager register --username=username --password=password
To confirm that the system is registered to Red Hat Subscription Management (RHSM), run the command:
$ sudo subscription-manager list --installed
Then refresh and subscribe:
Speed Up DNF Package Manager
You can increase the download speed for installing packages using DNF by updating the maximum number of simultaneous package downloads.
Start by editing the /etc/dnf/dnf.conf file:
$ sudo nano /etc/dnf/dnf.conf
Add the following line to enable DNF parallel downloads:
max_parallel_downloads=10
Another option is to select the fastest mirror from the Fedora public mirrors by adding the following line:
fastestmirror=True
Creating a Python requirements.txt File
This can be done quickly by typing:
$ pip freeze >requirements.txt
at the command line.
To install packages using a requirements file just use pip:
$ pip install -r requirements.txt
To check if the packages in your requirements.txt file are up-to-date use:
$ pip list --outdated
and to update those packages:
$ pip install -U <packagename>
Python: Initializing a New Project using venv
Start out by creating a new directory or cloning a repository (which creates a directory) and cd into it:
$ git clone https://gitlab.com/username/proj-name$ cd proj-name/
Initialize the virtual environment:
$ python3 -m venv venv$ source venv/bin/activate
Install whatever dependencies you need:
$ pip install package1 package2
Then develop and/or run your program:
Printing Numbers using Thousand Separators
You can use a pipe to awk to output numbers with thousands separators (commas). For Example, here’s how you can total the 5th column of the ls -l command and print it with thousands separators:
$ ls -l | awk '{total = total + $5}END{print total}' | LC_ALL=en_US.UTF-8 awk '{printf("%'"'"'d\n", $0) }'21,387
This can be adapted to other commands as necessary.
Ubuntu: Disable cloud-init on Startup
In systems that use systemd and have a current (17.0+) version of cloud-init, upstream documentation describes the process for disabling cloud-init with either of the following:
* touch /etc/cloud/cloud-init.disabled
or,
* add cloud-init=disabled to the kernel command line.
Red Hat Subscripion Manager - Registering
Registering your RHEL instance with Red Hat is straightforward assuming that you already have an account:
# subscription-manager register --username <your-rh-user> --password <password>
List the available repos or just go with a default:
# subscription-manager list --available# subscription-manager attach --auto
Then you can do your update:
# yum update
RHEL QCOW Image Password
Did you know that although you can install RHEL from an ISO, you can also download a QCOW2 image from Red Hat. However, when you try to start it up under virt-manager you’ll see that it boots to a root prompt and you don’t know what the password is. This can be fixed by running the following from the host’s terminal:
# virt-customize -a <qcow2-image-file-name> --root-password password:<password>
Find System Hogs and Child Processes
There are a lot of tools out there that can help you to do this that are both GUI or command line-based but sometimes you’re on a production server that may have limited tools and sometimes the simplest tools are best in cases like this.
List the processes that are not owned by you that are using a lot of CPU:
$ ps aux --sort=-%cpu | grep -m 8 -vwhoami