Code Done Right!

Useful Tricks

Here you will find a collection of useful tricks you can use to make your installation experience a bit easier. It does not matter if you work with Raspbian, Debian or Ubuntu

Find out your local IP address

The easiest way to find out your local IP address is to type the following command

ifconfig

Which will show you output similar to the below

IP address
Local IP address on eth0 – cable connection

Screenshot above shows the local IP address of eth0, which means that my Raspberry is connected via an ethernet cable to my router and the local IP address is 192.168.0.129

If you have more than one connection method, like Pi 4B has – both ethernet port and Wi-Fi. All methods that are active will be listed, even if not connected. You will simply see a connection that is not active, but ready.

  • eth0 – cable connection
  • wlan – Wi-Fi connection
  • lo – ignore for now

Better search engine for package repository

Default apt search functionality is not that great. With xapian indexing we can extend the search functionality. Install it with the following command

sudo apt install apt-xapian-index

Now we can use axi-cache command to browse our repository, basic use is

axi-cache search $search_term

If you want to learn how to refine your search run

axi-cache --help

Check installed packages

If you want to see what packages you have installed on your Raspbian run the following command

apt list --installed

If you want to search the list for a particular package you have to pipe the result to a different command – grep. In order to check if we have apache2 package installed run the following command

apt list --installed | grep apache2

You can substitute apache2 with any string to search for a different package

Using a pipe

Pipeing is done by using the character |, this is not an uppercase i nor it is a lowercase l. It is a separate symbol on your keyboard. A vertical line. Look for it around the enter key.

It basically passes the standard output of a command on its left to a command on its right. Look at the following code

command1 | command2

This takes the standard output (a result) of command1 and passes it as an attribute to command2. It might seem like it is not much, but consider a situation from the above, I included it first for a reason. You could list all packages that you have installed on your machine and manually look through it for that one you are looking for or pass the output to grep command so that it shows only what was searched for, or nothing as this is also information. Whether you made a typo or the lack of information IS the information – you have to judge for yourself.

Now consider a file with a list. Let’s say 200-something lines and this time you only know that it starts with some letter combination. Do you really want to look through the whole file or do you want to

cat file_name | grep xyz | sort

to search the file file_name for the string xyz and have the output neatly sorted alphabetically? Exactly. Pipes are great, learn to use them.

See who logged in recently

Logs provide a lot of useful information. They should be your go-to place for troubleshooting as they will tell you what errors are present and what to look for online. One more use of logs is to see who managed to log in, and when. The following log file contains both failed and successful login attempts

/var/log/auth.log

Unfortunately it usually is quite long as it records of bots that try to knock on your server using logins and passwords from the most commonly used lists. To filter out only successful logins run the following

sudo cat /var/log/auth.log | grep "Accepted password"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.