How to List Installed Packages in Fedora, RHEL, CentOS
Listing installed packages with YUM:
$ sudo yum list installed
To display details about a package:
$ yum info nginx
You can cat all installed packages to a file, copy the file to another machine and duplicate the system:
$ sudo yum list installed > installed-packages.txt$ sudo yum -y install $(cat installed-packages.txt)
List installed packages with RPM:
Git: Deleting Multiple Commits
Let’s say that you want to delete the last 3 commits that you’ve already pushed to the remote repository. In this example, you want 566dab6 to be the new HEAD revision.
$ git log --pretty=oneline --abbrev-commit57bc36b (HEAD -> master, origin/master, origin/HEAD) 3nd set of bad entries on 6th commitdfb4bd3 2nd set of bad entries on 5th commit0fd1e16 First set of bad entries on 4th commit566dab6 Yet more good entries on third commitd50370a More good entries on second commitb5fbc6d Good entries on first commit2cad4c7 Initial commit
Deleting Blank Lines Using Grep
If you have a file (or a stream) that has blank lines you want to remove, you can use this command:
$ grep -v "^ *$" file-with-blanks.txt > output-file.txt
where file-with-blanks.txt is the input file and has blank lines and output-file.txt will
be the output file without the blank lines.
You have to keep the space between the ^ and the *$ otherwise blank lines which include
spaces will not be removed.
Convert webm to mp4
You can use ffmpeg to convert webm to mp4 on the command line very easily:
$ ffmpeg -i file.webm -c copy file.mp4
This will stream copy (re-mux) and avoid re-encoding.
Parsing Bitwarden CLI
If you use the excellent Bitwarden app for you password storage you may not be aware that they also have a command line version on Linux. It outputs data using the JSON format. You can install the jq JSON parser and pipe the output of the CLI’s query to it in order to extract the username and password for a specific site in your search:
$ bw list items --search accounts.google.com | jq '.[] | .login.uris[].uri,.login.username,.login.password'"https://accounts.google.com""john.doe@gmail.com""** password1 **""https://accounts.google.com""jdoe@gmail.com""** password2 **"
Export VirtualBox VDI using CLI
Sometimes you may want to move a virtual machine in VirtualBox from one server to another. Once way of doing that is to export it from the command line.
- Locate the virtual machine that you want to export (I’ll use the name UbuntuServer for the one to be exported and name the new one UbuntuServerNew), and then
- Run the export command as follows:
$ vboxmanage export UbuntuServer -o UbuntuServerNew.ova
Rename Files Downloaded Using youtube-dl
If you have used youtube-dl to download content from YouTube then you know that the file names can get to be rather long. In addition to the video’s title there is a dash followed by what appears to be a random sequence of characters just before the file extension. If you find this to be annoying then here is a code snippet that you can use to remove it.
This will remove the last field separated by a ‘-’ and replace it with the file extension of your choice, .mp4 is used in this example:
Sending Email from the Command Line with mutt
If you prefer using mutt as your command line email tool, then here are a couple of examples of using mutt to send emails which can be automated quite easily to use in scripts.
Sending a file attachment (-a) and an empty message body:
$ mutt -s "System Logs" -a /var/log/somelog.log -- username@example.com < /dev/null
Sending a message body using redirection:
$ mutt -s "Email Subject" username@example.com < email.html
Sending a file attachment along with a message body:
Sending Email from the Command Line with cURL
Let’s assume that you had a RFC 5822 formatted file named mail.txt as follows:
From: Some Sender <some.sender@gmail.com>
To: Some Recipient <some.recipient@example.com>
Subject: Saying Hello
Date: Tue, 6 Jun 2023 04:15:06 -0100
Message-ID: <1234@local.machine.example>
This is a message just to say hello.
So, "Hello".
You can forward this to a email recipient using Google’s SMTP with the following curl command provided you have a Google app password:
$ curl --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
--mail-from 'some.sender@gmail.com' \
--mail-rcpt 'some.recipient@example.com' \
--upload-file mail.txt \
--user 'some.sender@gmail.com:your-gmail-app-password'
Output should be something like this:
Transfering Files Using netcat
You can use netcat to transfer a file from one machine to another machine.
On the receiving machine enter the following command:
$ netcat -l 12345 > file.txt or
$ netcat -l -p 12345 > file.pdf
Then, on the sending machine use this command:
$ netcat $MY_IP_ADDRESS 12345 < file.txt