{"id":176,"date":"2020-01-30T22:08:14","date_gmt":"2020-01-30T21:08:14","guid":{"rendered":"https:\/\/codedoneright.eu\/?page_id=176"},"modified":"2021-01-01T12:31:36","modified_gmt":"2021-01-01T11:31:36","slug":"useful-tricks","status":"publish","type":"page","link":"https:\/\/codedoneright.eu\/?page_id=176","title":{"rendered":"Useful Tricks"},"content":{"rendered":"\n<div style=\"height:56px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Here you will find a collection of useful tricks you can use to make your work a bit easier. It does not matter if you work with <a href=\"http:\/\/raspberrypi.org\">Raspbian<\/a>, <a href=\"http:\/\/debian.org\">Debian <\/a>or <a href=\"http:\/\/ubuntu.com\">Ubuntu<\/a><\/p>\n\n\n\n<div style=\"height:56px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Find out your local IP address<\/h3>\n\n\n\n<p>The easiest way to find out your local IP address is to type the following command<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ifconfig<\/code><\/pre>\n\n\n\n<p>Which will show you output similar to the below<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"606\" height=\"131\" src=\"https:\/\/codedoneright.eu\/wp-content\/uploads\/ip_address_eth0.png\" alt=\"IP address\" class=\"wp-image-517\" srcset=\"https:\/\/codedoneright.eu\/wp-content\/uploads\/ip_address_eth0.png 606w, https:\/\/codedoneright.eu\/wp-content\/uploads\/ip_address_eth0-300x65.png 300w\" sizes=\"(max-width: 606px) 100vw, 606px\" \/><figcaption>Local IP address on eth0 \u2013 cable connection<\/figcaption><\/figure><\/div>\n\n\n\n<p>Screenshot above shows the <em>local IP<\/em> address of <em>eth0<\/em>, which means that my Raspberry is connected via an <em>ethernet cable<\/em> to my router and the local IP address is <em>192.168.0.129<\/em><\/p>\n\n\n\n<p>If you have more than one connection method, like Pi 4B has, both ethernet port and Wi-Fi, then all methods that are active will be listed, even if they are not used at the moment. You will simply see a connection that is not active, but ready.<\/p>\n\n\n\n<ul><li>eth0 \u2013 cable connection<\/li><li>wlan \u2013 Wi-Fi connection<\/li><li>lo \u2013 local connection, ignore for now<\/li><\/ul>\n\n\n\n<div style=\"height:56px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Better search engine for package repository<\/h3>\n\n\n\n<p>Default <em>apt search<\/em> functionality is not that great. With <em>xapian <\/em>indexing you can extend the search functionality. <\/p>\n\n\n\n<p>Install it with the following command<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install apt-xapian-index<\/code><\/pre>\n\n\n\n<p>Rebuild your package repository and update <em>xapian<\/em> index with<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo update-apt-xapian-index<\/code><\/pre>\n\n\n\n<p>Right after the installation <em>xapian<\/em> will update its index so you might see the progress of the process with a prompt that it is already running.<\/p>\n\n\n\n<p>Now you can use <em>axi-cache<\/em> command to browse your repository with the following<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>axi-cache search $SEARCH_TERM<\/code><\/pre>\n\n\n\n<p>If you want to learn how to refine your search run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>axi-cache --help<\/code><\/pre>\n\n\n\n<div style=\"height:56px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Check installed packages<\/h3>\n\n\n\n<p>If you want to see what packages you have installed on your system, run the following command <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt list --installed<\/code><\/pre>\n\n\n\n<p>If you want to search the list for a particular package you have to <em>pipe <\/em>the result to a different command \u2013 <em>grep<\/em>. <\/p>\n\n\n\n<p>In order to check if you have <em>$PACKAGE<\/em> installed, just run the following command<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt list --installed | grep $PACKAGE<\/code><\/pre>\n\n\n\n<div style=\"height:56px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Create a list of installed packages and install them on a different machine<\/h4>\n\n\n\n<p>Commands below will help you create a file that contains a list of all packages installed on your system. Why would you need that? <\/p>\n\n\n\n<ul><li>You can mirror your system build on another machine, if you would like to make a backup with fresh config files<\/li><li>You can help someone build an exact replica of your system<\/li><li>You are upgrading or changing the distribution that you are using right now, let&#8217;s say you move from Debian to Ubuntu \u2013 you just have to make a list and install packages!<\/li><\/ul>\n\n\n\n<p>It can be done surprisingly easy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dpkg -l | awk '\/^ii\/ { print $2 }' > ~\/package-list.txt<\/code><\/pre>\n\n\n\n<p>This will create a file called <em>package-list.txt<\/em> in your home folder that will have names of all packages that you installed on your system. Copy that file to a system on which you wish to install said packages and run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo xargs apt-get install -y &lt; ~\/package-list<\/code><\/pre>\n\n\n\n<p>The above will install everything from the file <em>package-list.txt<\/em> on the system. If you want to add more packages then simply supply more names in the file, just make sure all names are in a separate line<\/p>\n\n\n\n<div style=\"height:56px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Using  a pipe<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>It basically passes the output of a command on its left to a command on its right. Look at the following code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>command1 | command2<\/code><\/pre>\n\n\n\n<p>This takes the standard output (a result) of <em>command1<\/em> and passes it as an attribute to <em>command2<\/em>. It might not seem like much, but consider a example of browsing for installed packages above, I included it first for a reason. <\/p>\n\n\n\n<p>You could list all packages that you have installed on your machine and manually look through it for a specific one <strong>or<\/strong> pass the output to <em>grep<\/em> command so that it shows only what you are looking for, or nothing as this is also information. Remember that lack of information IS the information as well \u2013 you have to judge for yourself. <\/p>\n\n\n\n<p>Now consider a file with a list. Let&#8217;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 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat foo.txt | grep xyz | sort<\/code><\/pre>\n\n\n\n<p>to search the file <em>foo.txt<\/em> for the string <em>xyz <\/em>and have the output neatly sorted alphabetically? Exactly. Pipes are great, learn to use them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">See who logged in recently<\/h3>\n\n\n\n<p>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. One more use of logs is to see who managed to log in, and when. The following log file contains login attempts, both failed and successful ones<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/var\/log\/auth.log<\/code><\/pre>\n\n\n\n<p>Unfortunately output is usually quite long, as it records all authentication related events, even use of <em>sudo<\/em> by any user. To filter out successful logins run the following<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo cat \/var\/log\/auth.log | grep \"Accepted password\"<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here you will find a collection of useful tricks you can use to make your work a bit easier. It does not matter if you work with Raspbian, Debian or Ubuntu Find out your local IP address The easiest way&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1026,"menu_order":5,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Useful Tricks for working in Linux &#8212; Code Done Right!<\/title>\n<meta name=\"description\" content=\"Here is a collection of useful tricks I wish I knew when I started my journey with Raspberry and Linux in general, read on!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codedoneright.eu\/?page_id=176\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Useful Tricks for working in Linux &#8212; Code Done Right!\" \/>\n<meta name=\"twitter:description\" content=\"Here is a collection of useful tricks I wish I knew when I started my journey with Raspberry and Linux in general, read on!\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/codedoneright.eu\/wp-content\/uploads\/ip_address_eth0.png\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/codedoneright.eu\/?page_id=176\",\"url\":\"https:\/\/codedoneright.eu\/?page_id=176\",\"name\":\"Useful Tricks for working in Linux &#8212; Code Done Right!\",\"isPartOf\":{\"@id\":\"https:\/\/codedoneright.eu\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/codedoneright.eu\/?page_id=176#primaryimage\"},\"image\":{\"@id\":\"https:\/\/codedoneright.eu\/?page_id=176#primaryimage\"},\"thumbnailUrl\":\"https:\/\/codedoneright.eu\/wp-content\/uploads\/ip_address_eth0.png\",\"datePublished\":\"2020-01-30T21:08:14+00:00\",\"dateModified\":\"2021-01-01T11:31:36+00:00\",\"description\":\"Here is a collection of useful tricks I wish I knew when I started my journey with Raspberry and Linux in general, read on!\",\"breadcrumb\":{\"@id\":\"https:\/\/codedoneright.eu\/?page_id=176#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/codedoneright.eu\/?page_id=176\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codedoneright.eu\/?page_id=176#primaryimage\",\"url\":\"https:\/\/codedoneright.eu\/wp-content\/uploads\/ip_address_eth0.png\",\"contentUrl\":\"https:\/\/codedoneright.eu\/wp-content\/uploads\/ip_address_eth0.png\",\"width\":606,\"height\":131,\"caption\":\"IP address\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/codedoneright.eu\/?page_id=176#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/codedoneright.eu\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux\",\"item\":\"https:\/\/codedoneright.eu\/?page_id=1026\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Useful Tricks\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/codedoneright.eu\/#website\",\"url\":\"https:\/\/codedoneright.eu\/\",\"name\":\"Code Done Right!\",\"description\":\"Raspberry Pi server guides\",\"publisher\":{\"@id\":\"https:\/\/codedoneright.eu\/#\/schema\/person\/50378701e349dbd5d40888bc5b532568\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/codedoneright.eu\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/codedoneright.eu\/#\/schema\/person\/50378701e349dbd5d40888bc5b532568\",\"name\":\"CodeDoneRight\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codedoneright.eu\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/codedoneright.eu\/wp-content\/uploads\/www_icon.png\",\"contentUrl\":\"https:\/\/codedoneright.eu\/wp-content\/uploads\/www_icon.png\",\"width\":120,\"height\":120,\"caption\":\"CodeDoneRight\"},\"logo\":{\"@id\":\"https:\/\/codedoneright.eu\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/codedoneright.eu\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Useful Tricks for working in Linux &#8212; Code Done Right!","description":"Here is a collection of useful tricks I wish I knew when I started my journey with Raspberry and Linux in general, read on!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codedoneright.eu\/?page_id=176","twitter_card":"summary_large_image","twitter_title":"Useful Tricks for working in Linux &#8212; Code Done Right!","twitter_description":"Here is a collection of useful tricks I wish I knew when I started my journey with Raspberry and Linux in general, read on!","twitter_image":"https:\/\/codedoneright.eu\/wp-content\/uploads\/ip_address_eth0.png","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/codedoneright.eu\/?page_id=176","url":"https:\/\/codedoneright.eu\/?page_id=176","name":"Useful Tricks for working in Linux &#8212; Code Done Right!","isPartOf":{"@id":"https:\/\/codedoneright.eu\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codedoneright.eu\/?page_id=176#primaryimage"},"image":{"@id":"https:\/\/codedoneright.eu\/?page_id=176#primaryimage"},"thumbnailUrl":"https:\/\/codedoneright.eu\/wp-content\/uploads\/ip_address_eth0.png","datePublished":"2020-01-30T21:08:14+00:00","dateModified":"2021-01-01T11:31:36+00:00","description":"Here is a collection of useful tricks I wish I knew when I started my journey with Raspberry and Linux in general, read on!","breadcrumb":{"@id":"https:\/\/codedoneright.eu\/?page_id=176#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codedoneright.eu\/?page_id=176"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codedoneright.eu\/?page_id=176#primaryimage","url":"https:\/\/codedoneright.eu\/wp-content\/uploads\/ip_address_eth0.png","contentUrl":"https:\/\/codedoneright.eu\/wp-content\/uploads\/ip_address_eth0.png","width":606,"height":131,"caption":"IP address"},{"@type":"BreadcrumbList","@id":"https:\/\/codedoneright.eu\/?page_id=176#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codedoneright.eu\/"},{"@type":"ListItem","position":2,"name":"Linux","item":"https:\/\/codedoneright.eu\/?page_id=1026"},{"@type":"ListItem","position":3,"name":"Useful Tricks"}]},{"@type":"WebSite","@id":"https:\/\/codedoneright.eu\/#website","url":"https:\/\/codedoneright.eu\/","name":"Code Done Right!","description":"Raspberry Pi server guides","publisher":{"@id":"https:\/\/codedoneright.eu\/#\/schema\/person\/50378701e349dbd5d40888bc5b532568"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codedoneright.eu\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/codedoneright.eu\/#\/schema\/person\/50378701e349dbd5d40888bc5b532568","name":"CodeDoneRight","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codedoneright.eu\/#\/schema\/person\/image\/","url":"https:\/\/codedoneright.eu\/wp-content\/uploads\/www_icon.png","contentUrl":"https:\/\/codedoneright.eu\/wp-content\/uploads\/www_icon.png","width":120,"height":120,"caption":"CodeDoneRight"},"logo":{"@id":"https:\/\/codedoneright.eu\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/codedoneright.eu"]}]}},"_links":{"self":[{"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/pages\/176"}],"collection":[{"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codedoneright.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=176"}],"version-history":[{"count":23,"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/pages\/176\/revisions"}],"predecessor-version":[{"id":1381,"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/pages\/176\/revisions\/1381"}],"up":[{"embeddable":true,"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/pages\/1026"}],"wp:attachment":[{"href":"https:\/\/codedoneright.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}