Tag: tutorials

  • Linux Tutorial Series – 82 – The command path

    Here is the video version, if you prefer it:

    Let’s talk about a special kind of environment variable – the PATH variable, also known as the command path. (Ward, 2014)⁠ This variable stores all the places your operating system will look for executables. (“How to set your $PATH variable in Linux,” n.d.)⁠ To recall, executables are a type of a command (executable is another name for an “ordinary” program (just like Firefox)). What this means is that every time you modify or append something to your PATH variable, you are, in essence, telling the operating system: “Look for the executable in this directory as well”. If you have multiple directories containing the same executable, the operating system will take the first one it finds.

    Here is how the PATH variable looks like:

    mislav@mislavovo-racunalo:~/Linux_folder$ echo $PATH

    /home/mislav/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/mislav/Python-3.7.4/bin:/usr/lib/jvm/jdk1.8.0_231/bin:/usr/lib/jvm/jdk1.8.0_231/db/bin:/usr/lib/jvm/jdk1.8.0_231/jre/bin:/home/mislav/Downloads/hadoop-2.10.0/bin:/home/mislav/Downloads/hadoop-2.10.0/sbin

    I put $ in front of PATH to get the contents of the PATH variable. Here we see that all the folders where to look for executables are separated with a colon. So the structure of the PATH variable looks like this: path1:path2:path3

    This is convenient for the operating system because it tells the operating system where to look for executables. Otherwise, it would have to search through the entire computer looking for your executable. Yikes! Better help the good ol’ operating system by telling it where to look for. 

    Hope you learned something useful!

    References

    How to set your $PATH variable in Linux. (n.d.). Retrieved February 27, 2020, from https://opensource.com/article/17/6/set-path-linux

    Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 22-23

  • Linux Tutorial Series – 81 – Environment variables

    Here is the video version, if you prefer it:

    Today we will talk about a special kind of operating system variables. As we already know, the operating system (and other computer programs) use variables, which are places in computer memory that store values relevant to a computer program. A special kind of operating system variables are environment variables. Let’s explain what “environment variables” mean.

    Environment variables are the variables that the operating system passes to your shell programs. (Ward, 2014)⁠ What that means is that when you run your shell program, it has access to the environment variables. A shell program then uses those environment variables to read its configuration and options from them.

    Here are some examples of environment variables I got by running printenv, which is used to print all (or a part of) your environment. (“PRINTENV(1),” n.d.)⁠

    mislav@mislavovo-racunalo:~/Linux_folder$ printenv

    SHELL=/bin/bash

    SESSION_MANAGER=local/mislavovo-racunalo:@/tmp/.ICE-unix/6698,unix/mislavovo-racunalo:/tmp/.ICE-unix/6698

    ...

    Here we can see SHELL and SESSION_MANAGER as names of my environment variables, while the strings right of the equal sign are the values of the variables.

    Takeaway: Environment variables are passed by the operating system to your shell programs and they store configuration and options that shell programs take into account when they are executed.

    Hope you learned something useful!

    References

    PRINTENV(1). (n.d.). Retrieved February 7, 2020, from http://man7.org/linux/man-pages/man1/printenv.1.html

    Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 21-22

  • Linux Tutorial Series – 80 – Variables – what’s that?

    Here is the video version, if you prefer it:

    Let’s talk about variables. What are those? Variables, generally speaking, are a part of your computer memory which hold different values at different times, depending on the execution of a computer program. We are talking about some “regular” program here (like Firefox). So I can have a variable called number_of_open_tabs and it can be equal to 5 and if I close one tab, then number_of_open_tabs equals 4. The takeaway is that variables hold some values which are relevant for a computer program. Every variable has a name (i.e. number_of_open_tabs) and a value (i.e. 4).

    OK, OK. But what does that have to do with the operating system? Well, the operating system has its own variables. Those variables are relevant for the operation of the operating system. 

    This was important to know conceptually.

    Hope you learned something new!

  • Linux Tutorial Series – 79 – Dot files

    Here is the video version, if you prefer it:

    I think I mentioned this before when I covered the ls command, but it bears repeating:

    Dot files are the files whose name begin with a dot. They are called hidden files. They can be displayed in a directory listing using ls, but only by providing the -a option. I never had to meddle with dot files in my Linux dealings so far. I did have to look at some dot files in my programming projects, but that is a different story.

    Thank you for reading!

  • Linux Tutorial Series – 78 – Reverse incremental search

    Here is the video version, if you prefer it:

    Let’s say you want to search for a particular command in your command line history. You could write history | grep pattern, but there is a better way. Reverse incremental search to the rescue!

    Here is how to use reverse incremental search: (Shotts, 2019)⁠

    When in a Terminal window, press ^ + R (CTRL + R) to initiate it. Start typing in the command you are looking for in history. As you type in more characters of the command, the search will refine itself. If you want to execute the command currently displayed, press ENTER. If you want to copy the command to your current terminal session, press ^ + J (CTRL + J).

    It should look something like this:

    (reverse-i-search)`sudo': history | grep sudo

    This is something I rarely use (I use the Up/Down arrows), but something that I have in the back of my head should I need it. I have also seen this being used by other Linux users in their day-to-day, so I thought that this was important to cover.

    Hope you learned something useful!

    References

    Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Pages 110-112

  • Linux Tutorial Series – 77 – The history command

    Here is the video version, if you prefer it:

    Let’s talk about history. No, not about a high school history class or about your browsing history (that could spark interesting conversations for sure). I’m talking about the history command.

    The history command is used to display your command execution history. (Shotts, 2019)⁠ Example usage:

    mislav@mislavovo-racunalo:~/Linux_folder$ history | grep sudo

    1075 sudo apt install nodejs npm

    1081 sudo npm install npm@latest -g

    ...

    Here, I look for all of the sudo prefixed commands that I have executed. It is important to note that history doesn’t go on till the beginning of your bash usage – it is limited, although you can change how much history entries you keep. Keep that in mind.

    Your history is stored in a file called .bash_history in your home directory (the first dot in the filename indicates it is a hidden file).

    I didn’t use history as much, but I was aware of its existence. I have found myself looking for the commands I ran by using the Up/Down arrows on the keyboard. history seems to be a better choice for when the command was used in the not-so-recent past.

    Hope you learned something useful!

    References

    Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Page 110

  • Linux Tutorial Series – 76 – Checkpoint

    Here is the video version, if you prefer it:

    Carrying on, we will talk about history and about variables. Understanding what variables are and how to manipulate them is essential. Understanding what important variables entail is also essential. Do make sure to pay attention.

  • Linux Tutorial Series – 75 – Review

    Here is the video version, if you prefer it:

    We talked about command types, which there are 4 – executables, shell built-ins, shell functions and aliases, as well as the commands used to determine the type of a particular command. We also talked about finding files – both locate and find – and (hopefully) memorized the syntax find dir -name file -print.

    We also covered some other stuff, but the above ones are the most important.

  • Linux Tutorial Series – 74 – Things I never used related to text manipulation – cut, sed, awk, …

    Here is the video version, if you prefer it:

    There are some commands I never used in my day-to-day Linux experience – such as cut, sed, awk, sort and uniq – among other things. I did use them once, when I was taking a class which had some Linux command line laboratory exercises, but that was it. Since I haven’t used these commands at all, I shouldn’t talk about them. If you ever have the need to learn what these commands do, I think that a Google search with the command and the keyword “tutorial” will do the trick.

    As I am writing this, I feel bad for leaving out a bunch of commands, but the point of this Linux post series is to trim the fat – to give you the things you need for everyday use, not cover everything possible.

    I may me mistaken, but I think that it is a valid strategy to learn to use these tools as the need arises. I found myself manipulating text in programming languages like Python and C++ and not as much sed and awk. Those are my 2 cents.

    Hope you learned something useful!

  • Linux Tutorial Series – 73 – The xargs command

    Here is the video version, if you prefer it:

    Let’s talk about the xargs command. The xargs command is used to accept input from the standard input and then converting it into an argument list for a specified command. (Shotts, 2019)⁠

    Let’s look at an example:

    mislav@mislavovo-racunalo:~/Linux_folder$ find /home -name 'ab*' -print | grep Linux_folder | xargs ls -l

    -rw-r--r-- 1 mislav mislav 12 Feb 5 22:48 /home/mislav/Linux_folder/ab2.txt

    -rw-r--r-- 1 mislav mislav 63 Jan 13 05:17 /home/mislav/Linux_folder/aba.txt

    -rw-r--r-- 1 mislav mislav 0 Jan 11 23:00 /home/mislav/Linux_folder/aba.txt~

    -rw-r--r-- 1 mislav mislav 12 Jan 13 05:17 /home/mislav/Linux_folder/ab.txt

    -rw-r--r-- 1 mislav mislav 0 Jan 11 23:00 /home/mislav/Linux_folder/ab.txt~

    Here I use find and grep to find files starting with ab in my Linux_folder. Then I use xargs to use those results and pass it to ls -l so that I get the long listing of each of the resulting files.

    I have almost never had the need to use xargs. I only used it once or twice as a part of the “use Google to find a solution to your problem”. In that way, it is immensely useful to know what xargs does.

    Hope you learned something useful!

    References

    Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Pages 252-253