Tag: Computer science

  • Linux Tutorial Series – 72 – The find command

    Here is the video version, if you prefer it:

    The find command is used to find files. (Ward, 2014)⁠ There are a lot of options to find, but I remember it simply as this:

    find dir -name file -print

    where dir is a directory from where to start the search and file is the file name I’m looking for. To elaborate more on the dir part – find will find files in the directory dir or a subdirectory of dir, but it will not go upwards of dir. For example, if my find starts like this:

    find /home/mislav …

    it will not look outside the mislav folder, just “further down”. That means it is impossible for me to get a result such as /home/jellyfish/… .

    -name is followed by the name of the file you are looking for. -print is used to instruct find to print the full file name on the standard output, followed by a newline. (“FIND(1),” n.d.)⁠

    Some examples of find:

    mislav@mislavovo-racunalo:~/Linux_folder$ find /home -name ab -print

    /home/mislav/.cache/pip/wheels/ab

    /home/mislav/.npm/_cacache/index-v5/ab

    /home/mislav/.npm/_cacache/index-v5/fc/ab

    /home/mislav/.npm/_cacache/index-v5/31/ab

    /home/mislav/.npm/_cacache/content-v2/sha512/b9/ab

    /home/mislav/.npm/_cacache/content-v2/sha512/ab

    /home/mislav/.npm/_cacache/content-v2/sha512/b1/ab

    mislav@mislavovo-racunalo:~/Linux_folder$ find /home -name ab.txt -print

    /home/mislav/Linux_folder/ab.txt

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

    /home/mislav/Linux_folder/aba.txt~

    /home/mislav/Linux_folder/ab.txt~

    /home/mislav/Linux_folder/aba.txt

    /home/mislav/Linux_folder/ab.txt

    /home/mislav/Linux_folder/ab2.txt

    I always used find to find a particular file (such as some files I needed which relate to software development), so I never needed to use other find functionalities (and there are many). I found a good guide for functionalities of find I didn’t cover here: (“A find Tutorial and Primer,” n.d.)⁠, although again, other than memorizing this short line at the beginning of this post and using it, I never used anything else besides that.

    “What’s the difference between locate and find?” you may ask. Well, the astute reader (and I hate when someone writes this as I always feel bad) will have noticed that locate operates on a database. So, if some file entry wasn’t added to the database locate operates on, locate won’t find it, but find will. So find is more powerful than locate in the sense that it doesn’t rely on a database which can be incomplete at a given moment. I have used find much more often than locate.

    Hope you learned something useful!

    References

    A find Tutorial and Primer. (n.d.). Retrieved February 6, 2020, from https://danielmiessler.com/study/find/

    FIND(1). (n.d.). Retrieved February 6, 2020, from http://man7.org/linux/man-pages/man1/find.1.html

    Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Page 20

  • Linux Tutorial Series – 71 – The locate command

    Here is the video version, if you prefer it:

    Today we are going to talk about locating files. This is very useful and I use it relatively frequently myself.

    The locate command is used to locate files. (Shotts, 2019)⁠ It is used as such:

    locate string

    where string is a part of the pathname you want to locate. To remind ourselves, a pathname is a location on your disk, such as /home/mislav/Linux_folder, so you are asking your computer “give me all the pathnames that contain string within themselves” (string being an array of characters).

    Here is an example:

    mislav@mislavovo-racunalo:~/Linux_folder$ locate Linux_folder

    /home/mislav/Linux_folder

    /home/mislav/Linux_folder/1-4.txt~

    /home/mislav/Linux_folder/1264.txt

    /home/mislav/Linux_folder/2345.txt

    /home/mislav/Linux_folder/a.txt

    /home/mislav/Linux_folder/a.txt~

    /home/mislav/Linux_folder/ab.txt

    /home/mislav/Linux_folder/ab.txt~

    /home/mislav/Linux_folder/ab2.txt

    /home/mislav/Linux_folder/aba.txt

    /home/mislav/Linux_folder/aba.txt~

    /home/mislav/Linux_folder/cb.txt

    /home/mislav/Linux_folder/cb.txt~

    /home/mislav/Linux_folder/file.txt

    Here, all paths that contain Linux_folder within them are located.

    Note: You may not have locate installed as a command (I know I haven’t). You can install the locate command by following an answer provided here: (“How to install the locate command?,” n.d.)⁠

    locate uses a database to find files. What that means is that pathnames are stored in a database and then that database is searched for pathnames matching string.

    There also exists a command called find, which you can also use to find files, but we will talk about find in another article.

    Thank you for reading!

    References 

    How to install the locate command? (n.d.). Retrieved February 6, 2020, from https://askubuntu.com/questions/215503/how-to-install-the-locate-command

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

  • Linux Tutorial Series – 70 – The diff command

    Here is the video version, if you prefer it:

    The diff command is used to see the difference between two files. (Shotts, 2019)⁠ I don’t think you will be using this command much if you are not a software developer, but if you are a software developer, you could use it to look at the difference of two program source files, or to compare two files which were outputted by different programs.

    Here is an example of using the diff command:

    mislav@mislavovo-racunalo:~/Linux_folder$ cat aba.txt

    Abba Money

    Money Money

    It's the Money

    In the Rich Man's World

    mislav@mislavovo-racunalo:~/Linux_folder$ cat ab.txt

    AB

    Ab

    aB

    ab

    mislav@mislavovo-racunalo:~/Linux_folder$ diff aba.txt ab.txt

    1,5c1,4

    < Abba Money

    < Money Money

    < It's the Money

    < In the Rich Man's World

    <

    ---

    > AB

    > Ab

    > aB

    > ab

    The output seems a bit confusing. What is this 1,5c1,4? In my opinion, you don’t have to know what that means. What you need to know is that when you encounter a <, that means that the line that follows is missing from the second file (in this case ab.txt) and when you encounter a >, that means that that line is missing from the first file (in this case aba.txt). (“Understanding of diff output,” n.d.)⁠

    Let’s take another example:

    mislav@mislavovo-racunalo:~/Linux_folder$ cat ab.txt

    AB

    Ab

    aB

    ab

    mislav@mislavovo-racunalo:~/Linux_folder$ cat ab2.txt

    AB

    aB

    aB

    ab

    mislav@mislavovo-racunalo:~/Linux_folder$ diff ab.txt ab2.txt

    2c2

    < Ab

    ---

    > aB

    Again, as I stated, when you encounter a < that means that the line that follows is missing from the second file (in this case ab.txt) and when you encounter a > that means that that line is missing from the first file (in this case ab2.txt). They only differ in the second line, and the second file is missing Ab, while the first file is missing aB.

    If you really want to know what 2c2 means, I refer you to the first answer in (“Understanding of diff output,” n.d.)⁠. I agree with the second answer in the reference, which is that you don’t need to know what this means. You will most likely be using diff rarely and when you do, you will be able to see the conflicting lines and that’s all you need to know. That is, in my experience, enough for practical purposes.

    There are 2 options for diff that are useful: the -c option (also known as the context format) and the -u option (aka the unified format). Both alter the output of diff. Here is an example of diff -c:

    mislav@mislavovo-racunalo:~/Linux_folder$ cat 1264.txt

    1

    2

    6

    4

    mislav@mislavovo-racunalo:~/Linux_folder$ cat 2345.txt

    2

    3

    4

    5

    mislav@mislavovo-racunalo:~/Linux_folder$ diff -c 1264.txt 2345.txt

    *** 1264.txt 2020-02-05 23:09:02.454637685 +0100

    --- 2345.txt 2020-02-05 23:06:15.415147970 +0100

    ***************

    *** 1,4 ****

    - 1

    2

    ! 6

    4

    --- 1,4 ----

    2

    ! 3

    4

    + 5

    Here is the meaning of the output: First of all, the *** denote the first file, while --- denote the second file. That means that *** 1,4 **** means lines 1 through 4 of the first file, while --- 1,4 ---- means lines 1 through 4 of the second file. Now for the actual file contents: a in front of a line means that a line appears in the first file, but not the second file. A + means that a line appears in the second file, but not in the first file. An ! means that a line (or lines) changed between the first and the second file. (Shotts, 2019)⁠

    Here is an example with the -u option:

    mislav@mislavovo-racunalo:~/Linux_folder$ cat 1264.txt

    1

    2

    6

    4

    mislav@mislavovo-racunalo:~/Linux_folder$ cat 2345.txt

    2

    3

    4

    5

    mislav@mislavovo-racunalo:~/Linux_folder$ diff -u 1264.txt 2345.txt

    --- 1264.txt 2020-02-05 23:09:02.454637685 +0100

    +++ 2345.txt 2020-02-05 23:06:15.415147970 +0100

    @@ -1,4 +1,4 @@

    -1

    2

    -6

    +3

    4

    +5

    A indicates that a line was removed from the first file and a + indicates that a line was added to the first file. This means that if we were to remove the lines with the minuses and add the lines with the pluses, we would get the contents of the second file.

    That’s pretty much it. I think I have covered all you need. You won’t be using diff as much if you’re not a software developer anyway, and if you are a software developer, this is all you need to know in my opinion.

    In case you are really curious: the numbers 1,5c1,4 in the first example are instructions for the patch command. Since I never used the patch command, I won’t cover it. If you ever need to use it, you know it exists and Google is your friend.

    Hope you learned something new!

    References

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

    Understanding of diff output. (n.d.). Retrieved February 4, 2020, from https://unix.stackexchange.com/questions/81998/understanding-of-diff-output

  • Interesting Conversations with Mislav Jurić #4 – Interview with Steve Omohundro

    In this podcast episode, I have a conversation with Steve Omohundro. Steve is one of the first people to point out the potential dangers of advanced AI systems and in this podcast we discuss topics related to AI, mainly personal AI and AGI (Artificial General Intelligence). Hope you enjoy!

    Find it here:

    Things mentioned in this podcast episode:

    Timestamps:

    • 00:00:00 – 00:01:40 Introduction
    • 00:01:40 – 00:06:26 Steve’s experience with startups
    • 00:06:26 – 00:10:49 Personal AI
    • 00:10:49 – 00:12:28 Steve’s research company
    • 00:12:28 – 00:20:37 Combining symbolism and connectionism in AI
    • 00:20:37 – 00:25:22 Can GPT-3’s successors eventually build an accurate world model?
    • 00:25:22 – 00:30:27 Contributing to AI or AI safety research as an individual?
    • 00:30:27 – 00:34:28 Entrepreneurship opportunities for individuals in AI
    • 00:34:28 – 00:45:28 Personal AI capabilities
    • 00:45:28 – 00:49:14 The outcome of AGI
    • 00:49:14 – 00:56:26 The reasoning behind The Basic AI Drives
    • 00:56:26 – 01:00:01 Can we mathematically formalize emotions?
    • 01:00:01 – 01:03:42 Can we slow down AI progress?
    • 01:03:42 – 01:06:35 Next steps for AGI and personal AI
    • 01:06:35 – 01:10:39 Ideal educational background for AI researchers?
    • 01:10:39 – 01:13:05 How to approach learning math?
    • 01:13:05 – 01:14:21 Parting thoughts
  • Linux Tutorial Series – 69 – The file command

    Here is the video version, if you prefer it:

    The file command is used to guess the filetype based on files contents. (Ward, 2014)⁠

    Here is an example of its usage:

    mislav@mislavovo-racunalo:~/Documents$ file ls.txt

    ls.txt: UTF-8 Unicode text

    Hope you learned something new!

    References

    Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Page 20

  • Linux Tutorial Series – 68 – The tee command

    Here is the video version, if you prefer it:

    The tee command is used to redirect standard output to both standard output and one or more files. (Shotts, 2019)⁠ Here is an example of its usage:

    mislav@mislavovo-racunalo:~/Documents$ ls | tee ls.txt | grep test

    test.txt

    mislav@mislavovo-racunalo:~/Documents$ cat ls.txt

    001_002.pdf

    Accounti

    AGI safety podcasti

    ...

    I never used it, but it is very useful to check the output intermediary steps in long pipes.

    Hope you learned something useful!

    References

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

  • Linux Tutorial Series – 67 – apropos, whatis and info – commands I never used

    Here is the video version, if you prefer it:

    Hello there,

    I wanted to introduce you to 3 commands I never used, but may come in handy in some cases (although so far I have never encountered them).

    The first is apropos. It is used to find commands appropriate for something. I use Google for this task.

    The second is whatis. It is used for short, one-line command descriptions. I use --help or (much less frequently) man. Much more frequently, I use Google to find out what the command does.

    The last command on the list is info. I use man over info and Google over man. To add something here – I have seen some instances where people recommend checking out info pages (accessed through the info command), but that is recommended in an answer on StackOverflow which gives the answer and then suggests looking at the info pages.

    There you have it – the commands and the alternatives I use. One of them is Google, but hey, if you are on a desert island and you simply must figure out what command is appropriate for something, use apropos.

    Thank you for reading! Hope you learned something useful.

  • Linux Tutorial Series – 66 – The alias command

    Here is the video version, if you prefer it:

    The alias command is used to construct your own commands which are made out of existing commands. (Shotts, 2019)⁠ Here is an example of how it is used:

    mislav@mislavovo-racunalo:~$ alias ll='ls -l'

    mislav@mislavovo-racunalo:~$ ll

    total 76

    drwxr-xr-x 27 mislav mislav 4096 Sep 19 14:00 anaconda3

    drwxr-xr-x 26 mislav mislav 4096 Dec 30 00:40 'Calibre Library'

    drwxr-xr-x 2 mislav mislav 4096 Aug 25 12:21 Desktop

    drwxr-xr-x 26 mislav mislav 4096 Jan 16 09:38 Documents

    Its syntax is as follows:

    alias name='string'

    Be wary of the spaces – there are no spaces between name, = and ‘ ‘!

    As you can see, you can create your own commands with alias. More specifically, you are creating an alias for an existing (or a sequence of existing) commands – hence the name.

    Some notes: make sure not to alias an existing command name (check if the command name is used already with the type command). Also, the alias you create will vanish when you exit your Terminal session. That is a topic for another post.

    Hope you learned something useful!

    References

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

  • Linux Tutorial Series – 65 – Executing multiple commands on the same line

    Here is the video version, if you prefer it:

    You can execute multiple commands on the same line. To do that, you need to add a semicolon, like so: (Shotts, 2019)⁠

    command1; command2; command3

    An example:

    cd /; ls; cd

    This lists the contents of the root directory and then switches your working directory back to your home directory.

    Hope you learned something new!

    References

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

  • Linux Tutorial Series – 64 – The which command

    Here is the video version, if you prefer it:

    The which command shows you the location of a given executable. (Shotts, 2019)⁠ For example:

    mislav@mislavovo-racunalo:~/Linux_folder$ which cp

    /usr/bin/cp

    It only works for executables, not for other command types.

    Hope you learned something useful!

    References

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