Modern C++ Course: Hands-on Tutorial: Working with Linux (2021)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome to the first video of a series of tutorials where we are going to show you some basic tools that we want you to learn during this course this is not a full blown lecture but mostly i will be showing you some techniques and i will be trying to code along you a lot on this first tutorial we want to show you how to work with linux but it's going to be extremely basic so it's not it's not going to cover uh the full story of how to work with the new linux system but at least i'm i'm going to try to show you the bare minimum tools you should have in order to succeed with this course let's get started so again so why we're going to use quino linux so linux is a super popular choice for development nowadays in our particular case where we target computer visions applications and mobile robots it's really important to understand that most of embedded systems nowadays will be running some sort of variation of the linux operating system so therefore it's much easier to develop with the same platform that's going to be the target platform although there are still some small devices where you don't have any kind of operating system but this we call bare metal we are not going to go into any details on how to work with those and dev systems on this course but rather targeting linux or embed linux linux is a free unix lag operating system so linux is basically inspired in unix that is an operating system that was created along c on the 70s so many years ago the kernel of the operating system was implemented by linus turbos and therefore the name come from there and linus is still developing the linux kernel nowaday so this is some something really particular from this area of the technology that is being developed with people who are still alive and working along us so nowadays it's extremely popular and this means that it's basically everywhere so it's on chrome os it's on some sort of uh notebooks on any kind of mobile roads it's very likely that some sort of variation of linux is running android is based on linux so most of the cell phones out there are also running some sort of variation of linux and it's basically ubiquitous it's something that now it's everywhere so even if you have some measurement instrument like an oscilloscope it's very likely that it's going to be running a linux operating system inside the instrument so linux nowadays became really popular and this is also good because allow us to work with tools that everyone is also using so there are many distributions available the fact that the operating system is free and open source allow you to change it the way you like it and therefore infinite amount of distributions came into place in the last 15 years so my recommendation our recommendation is to just stick to ubuntu that is probably the most popular distribution out there and if you struggle if you have some sort of issues it's much more likely to find an answer on the internet that just trying to look it through some documentation from some really particular distribution even though when i don't use plain ubuntu my operating system is basically based on top of ubuntu 24 so whatever i do on my computer and whatever you see you are also you can also do it on your computer if you have yourself ubuntu 2004 so the take away message of working with linux i want you to take home is basically everything in linux it's a file no matter if it's like a real file like a text file or if we are speaking about the camera like the camera i'm using right now on my linux system or whatever kind of device you have connected to your computer everything in linux it's going to be a file so this is super important and therefore you should somehow understand how the linux directory structure was designed so this is something that came from unix on the 70s and has been the directory structure the the tree structure for all the unix or linux based system since these 50 years because it's rare simple so everything will start with root so i will do some highlighting now so everything starts here with the root directory that is always the slash directory and from there all the directories will be a child of these roots so the root is going to be the starting point of the files of your operating system and everything is inside this root that's why the name root and it's important to notice that inside this router inside this file system there are not any strange volume letters like c d e f of whatever of course if you have different disk you can mount it into different points on your system but that's rather another story so most of the cases you will be wanting to pay attention to your user home space that this basically is whatever comes inside slash home slash your username and that's where you have permissions typically to write files store data and do your work here so the other directories you will have for example on this local directory you have the libraries that you install it locally so if you install opencv later in this course the opencv library is going to be located here the bin director is going to have the binaries that you will be using they leave the lyrics and and so on and everything er so everything start with root and then from there you go down and then you for example if you want to reach this local directory then let me clean so the path you should follow is the following so you start from the root directory and then you go to the user directory and then you go to the local directory and that's how you reach the path so it's always going inside the folders and it's extremely easy once you get used to it so make sure you remember the takeaway message is everything in linux is a file no matter what we are talking about in linux is going to be a file then we move forward so this is like a summary of how to work with these files and folders so in linux uh everything that ends with the with the backlash it's going to be a folder so if i find my highlight so this is the backlash i'm talking about so if the path we are discussing ends with the backlash like this this means that we are talking out a folder or a directory depending how you want to call it and then everything else is going to be a file so if you pay attention here so at the end of the path there is no backslash meaning that basically this is going to be a regular file and then also we have something we call absolute path that is basically when you provide a full path from the root directory of your system towards the end of so the file you're looking for so in this case if we want to for example if you want to access this folder this we say this is an absolute path because it starts from the root directory so if you check it's starting from here from the root directory meaning that we are going to provide the full path to the file but let's say we are working in another directory and then we go from this directory towards another file therefore we can provide something that is called a relative path that is going to be this example down here so in this case because we are not providing the backlash at the beginning the shell is the terminal is going to be prepending the current working directory so you can reach the file as with the relative form and then the path is our case sensitive so make sure you remember this fact so the file name these two finances are completely different over here and then the extension is part of the name so the extension doesn't mean anything a particular or anything rather special but it's basically part of the file name so filename.cpp is only different from filename.png not because there are different files but basically because the name is going to be different so to open a terminal in most of ubuntu based distribu distribution and you just press ctrl alt which is go and loop to the terminal program and then therefore you can start working with the terminal right away i will show you a simplified version of the terminal now that i have in order to make it fit with slides most of the tasks you usually do from the gui that is basically the graphical interface you can do it from the terminal so let's say you want to rename a file you can do it with the gui with the file explorer or you can also do it with the terminal and it's rather much more convenient because let's say you for some reason you need to rename 50 000 files i guarantee you that if you find a way of how to do this with the terminal you can automate this process and not go and change 50 000 files by hand so how to navigate this tree structure from the terminal basically there are three main commands that is spring working directory change directory and list directory and we are going to show you right away okay so let's fire up a terminal so in this case this is a terminal that is basically bitmain file so it fits the the slice and we can see the slice while we go along so basically if i run the print working directory i'm going to see in this case that i'm at slash home ibiza that is basically my user folder and then i can for example ls to check what is inside here and then let's say i want to go to the dev folder and i just will do cd and then there and this tab is basically a relative path so i could be doing this to go there or i can basically go to my home directory again and i can do the full path the absolute path that is going to be home if it's so and then dev that is basically the same place so if you see my shell here is highlighting where it's dislocated and in both cases we reach the same place there is basically four special kind of characters the first one is the root uh directory the slash so if i go to just the root i'm going to be on the first point of my operating system on the file system and then if i for example i go to the tilde this still is basically an alias for my home directory so if i do print working directory now i'm basically on my home directory and then the last two is basically the current folder and the parent folder so if i go to dev if i do ls for example and i provide an argument that i stopped and it's going to be the same as ls because i'm basically listing this current directory and if i do ls dot dot basically going up it's going to be listing my home directory so this is basically super simple if you don't really understand the only way to get through it is open your terminal stop the video pause the video and start typing this command and play around so it's free it's safe and you don't really lose anything with trying so if you are already a bit lost with your terminals just go to the terminal and start using it let's go back to the slides then the structure of linux command is always the same and i want to tell you right now that the concept or the idea of command is rather something complicated because if you forget if you were sorry remember our first takeaway message everything in linux it's a file what is the meaning of this there is no such thing as a command it's basically a file that is going to be located somewhere in your system and when you use this file when you execute this file because it's going to be you are not going to provide the full path it's going to have the feeling of a command and that's why we call it a command so ls if we go back to ls here so let me clear the screen and let me go to my home directory this ls here is basically a command or we call it a terminal command but it's nothing but a file so if i know where is this file located so if you do use serving ls now you're providing the full path to the the command and if i execute this it's going to give me sorry user being ls is going to give me the same answer of the ls command and why is this because i'm i know where is the file located i'm just executing so a command is rather uh a file that is somewhere on the system therefore it's important to notice that here we have this path that is nothing but a variable on your local system that will tell you where you should be looking for commands so whenever you fire up a command on the terminal like ls or bring working directory the shell is going to go to this path variable and look through all the directories that are located listed there to find for this ls so oh sorry so if you go here if i basically show you what i do have on my path i basically have all these directories uh here on the left and basically when i fire the ls command first is going to be looking on this directory to find it and then into this one and then into this one and so on and at some point it's going to reach this user user local bin that is the one we were doing with the ls and then it's going to find the file and it's going to execute it from there so that's basically the idea of a command each command that is basically each program will always or most likely have options and parameters so for example you ls and then you say help this is going to give you the help of the command let me make the terminal bigger and then these are all the arguments you could use with ls and sometimes it's two verbose all the description of the command and therefore you can check for the manual and then the parameters basically is going to be the program specific parameters for the particular command you're trying to use like for example input files and and stuff like this if you got lost with any command there is the manual that is always the the like the user manual for each command or most of the commands out there or programs we have the dash h or help uh in order to to know what's going on so for example let me make the terminal bigger again and then if i do man ls basically this is going to show you all the the options for the ls command and you can navigate through it in order to see what what's the thing you're missing or the particular task you need so then let's continue because this is rather simple then this is just a trick a hint whenever you are working with the terminal and make sure you use the top so when you tap you basically you can auto complete what you're doing so if i do cd and then i do that and i tap i will i'm going to get some prompt from the terminal and let's say i want to go to that and i now i'm reaching the point i was looking for so make sure you top always so because it's much easier for you to navigate through the terminal so in order to create files and folders these are the four most common commands if you are looking this video i highly recommend you to pause the video right now and go to your terminal and start working around with these commands i'm going to skip through it because it's extremely simple and i know you could do it by yourself the the other stuff you could probably do after like working with creating some files and copying files from some place to another is to use some special characters on the terminal like placeholders so i'm going to show you the first one and then as a homework you you also have a an example slide coming next and you should also play around a bit with all these other files so let's say i'm going to go to my root directory and this this temp directory was here and here i'm going to create a directory that you just learned by yourself on the previous slide and that's going to be placeholders now i'm going to cd into this directory and if i list here of course it's completely empty so let's say i want to create 10 files or let's make it even easier let's create just three files one way of creating spice like empty files with nothing is using the touch command so i can do by one by two and five three and now when i ils i have these three fives so one option let's say that you for some reason want to delete these files and then you could do remove five one and then file two and so on but what happens when you have fifty thousand files then it's going to be a bit messy and therefore you could use the the um the star placeholder that's going to give you basically anything it's like a glob so if i do rm that stands for remove and i specify the the the globe operator when i do this it's going to remove all the files and actually my shell is from protein telling me you're just about to read three files i would say yes and then when uls it's basically gone so now i will invite you to stop the video again and then go to your terminal create the the files you see here so first create these files these nine files and how to create it you can use the touch command and specify the extension there's no need to be a real pdf there just a file and then use try to play around with this or with some variation of the commands i'm showing to you on these slides and therefore we go to the one of the most important parts of this lecture here so the standard input and output channel are basically the same on any unix based system so you will always have almost likely you will have a standard input channel that is basically assigned to the channel zero and then you have two output channels that one is going to be for the standard output and the one is going to be for a standard error traditionally these channels are going to be one uh for the center output and two for a standard error so you already saw some standard output and standard manipulation on the first lecture of this course so basically i have one example for you here so whenever you run any program that is going to be a file on the system because you're using linux this is what is going on under the hood so the program will be always reading from the standard input that on the desktop computer is going to be the keyword of your computer and then it's going to be outputting to the monitor that is assigned to the standard output and sorry the standard output and the standard error are assigned to the monitor on the stock computer so every time you run a program this is what's going on under the hood basically so um i have a one example program so we can work a bit with this example and i can show you some redirections of these channels on unix systems so if i go to my directory my home directory so let me show you where i'm located i have one example here so i have a pre-compiled binary here that is going to show some operations with the channel so after we finish the explanation the idea is that you stop the video again and then as i i told you on the first lecture the idea of this course is you get hands on the keyboard and then you work a lot otherwise it's very hard to learn so once you we finish with this explanation stop the video and the exercise is you should code the c plus plus program that exactly represents the behavior i'm going to show you so i'm not going to show you the source code but rather the how the brand behaves and then you need to do some sort of reverse engineering and make the source code by yourself so on the video you will have the example on how the program should behave so let me clear the screen sorry and let me execute this example so here on the standard output we have a message that says please input a number bigger than 100. let's say for some reason we didn't read the message and then we put five and we will have an error message saying on the standard error channel the number is not bigger than 100 and it's basically five then we try it again and then now again we're reading so we are inputting data from the standard input that on my laptop is assigned to the keyword and let's put 500 now and then on the standard output i have one confirmation confirmation message that is basically 500 so be aware that this string over here and this string over here is not normally something i put on my program to make it more obvious to you where is this going to the standard output or to the center error let's go to the next example so let's say that for some reason we want to show the the user only the errors but the standard output we want to put it into a file how we do it so there's a simple syntax on any unix based system that is basically this angular bracket syntax so basically one that is the standard output channel and that's why the one is there we say please put this and it's like you just put it here into one file this file would be whatever file you want so basically now if i do the example and i say redirect one that is a standard output to a file that's called i know standard output.txt now the message of the standard output please enter a number is not being shown because it's on the file actually so now i will show you the file how it looks when it ends and you will see the message but we remember the behavior and then let's put a five again and then now we see the error why we see the error because still so the error message is going to be printed to the standard error and if you see this is still going through the monitor over here that's why you get to see the error of course if you know ls here you will see this file you just created and then if you cut that is to see what is inside the file this file you will see the message you were expecting at the beginning so of course the same you could do with the standard error so you can just show the standard output and then rewrite the standard error how using a 2 because the channel for assigned for the center error is 2. so basically if we now do the same linux example but then 2 is going to be an like error txt so to this file now we see the standard output message on the monitor because we didn't redirect it and then when we put five the error message is not being shown because now it's on the file unless you see the error file if we see what's in here the standard error message is going to be prompted there and of course you could do some other stuff like okay i want to have one five four there or one five for the standard output channels and then if you run this so basically one is going to be for the standard output and then two is going to be redirected to the error file now you don't see anything because um everything is going to be redirected to the file so if i put five here all the messages are being lost because there both messages are on each independent file so again if you for some reason got lost you just stop the video open your terminal as i'm working around open the files if you don't want to check the files from the terminal open the files with the text editor i don't really care the only thing is you should really get your hands on to so you can develop this experience and learn while you uh type and this is the last example we're going to see because it's the syntax it's a bit more complicated but it's basically the same principle so what we are doing here is basically we are first redirecting the standard output channel so one to one file that is out txt but then we say you know what let's also redirect the standard error that is two to whatever is pointing to one and then in this case it's going to be splitted uh speeded to the out txt file meaning that we are going to put both on the same file so let me remove these files just to clean up my workspace i only have my example and then if i do this like out txt and then the standard error that is two is going to be redirected to whatever is on one it's print is asking me for the number i will put five again and then if we check this file we have both the standard output and there on the same file again now you should stop the the video or pause the video and then try to write a c plus problem that behaves exactly that's like this linux example these messages are optional so the standard output or error but what you should do is go through the slice that is going to be on the link down on the description and then make sure that all the examples i'm showing you here you get the same output check the files so you know that your program is probably working as i am asking you to make it work and then we move forward so these are uh a rather short list of the commands you should always have on your uh on your belt on your toolbelt so i'm not going to show you all the commands of course but it's basically a summary of what you should have in mind always in order to work fast with the terminal to allow you to do the tasks you will need to do for programming c plus plus and working with linux in general the other important thing is how to change commands so if you remember um on the lecture zero when we saw a header wall so when you see when the each program uh finish its execution it's going to return a code to the shell basically and then if this uh code is different than zero then it's going to be an error and if it's zero is going to be no error so let me show you basically uh one example over here so let me clean again here this workspace and then let's try to cut to uh see what is in like file.txt but if you check here on ls this file doesn't exist so now i'm going to get an error on the standard error a channel but actually if you check the return code from this program with this command you will see that it's 1 meaning that there was an error so if i want to change the commands with the with this operator that is the semicolon this is going to fail so this semicolon operator basically means run the command 1 run the command 2 run the command 3. sorry it's not going to fail it's going to run it no matter what so if i do for example cut file txt and then cut file two txt both commands are going to run and both are going to fail the other option is going to use the double ampersand that is basically going to say tell the terminal first run this command and only and only if it doesn't tell so if there's a return code that is exactly zero then move to the following command so if i run now this so in the previous example we were running both commands no matter what and therefore we got the two error messages and in this case because i'm telling you just move forward if you don't fail we should see the error message for this command and then this one should not be prompted and as expected so we did the first command it failed and then we avoid the execution of the rest of the commands then something that is extremely important is piping so basically when you pipe something on linux you basically use the vertical bar operator and then when you pipe you basically put whatever is on the standard output of the first command to the standard input of the of the command to so if we go back to this slide so when you're running a problem by itself so the keyword is going to be injecting data into the standard input over here but when you're piping commands you basically have another program here on your chain that is going to so let me try to draw it so we'll probably have a so this is going to be another program this is going to this is not going to be part of the story anymore so just wipe it out and then basically the standard output of the first program is going to be filling the standard input of the following program and that's basically the main idea behind pipes on linux so basically and then and so on so if you have a three third command so the standard output of this command is going to be uh being checked to a standard input of the third command so how you can use pipe to do really cool stuff for example here let's say you have multiple files so let's create files again and then let's say you're looking for five three so the when you see a less that is basically listing directory you're working right now it's printing this to the standard output because you see it on the monitor on the terminal and therefore maybe you can use script that is a command that when you provide something to the standard input of this command it's going to search through this so basically now with the pipe so the standard output of ls is going to be the uh set to the standard input of crap and here i got browse and query like for example file three and this is the file i'm looking and if you see i have the the the output is now being shown in the standard output channel is a terminal and i know that on this directory i have this 5 3 i was looking for there's a cool video on how to use linux and command line pipes and redirections so it's basically what we just saw so in case you want another perspective or someone has explained this to you because you think it turned to be more complicated i highly recommend you to watch this video i think it's uh 10 minutes video so it should be enough for you to get a grasp of what you need to work with linux then last but not least so if you want to run some command and then for some reason let's say you run into an incident loop there's many ways of killing it the ones i would probably recommend you because are the most easy ones are ctrl c so basically ctrl c stands for cancelling this command so if you're running on the shares just press ctrl c and then it will cancel or you can use h top or top there are applications to watch whatever is on your system and look through the commands and then try to keep it with the with the k operator button basically on your keyboard so this is a rather like a trick how to navigate with the commands on your linux computer so if you see if i go up i can see all the commands i just run of course if i also do history there is a command i can check all the commands i just run and then i can also wrap using the pipes for example cut and i can see all the commands that i did with cat on my story so again stop the video try to run all these examples here so you get used to how to work with the terminal installing software in linux is extremely easy so typically just install the problem you want and if not you should google or maybe if you have the source code available it's typically easy but it's traditionally much more easy to install it on linux if it's available on the main repositories of the your distribution that installing software on windows so let's say you want to run h-stop so htop is this application to to watch all the process on your computer like this one and then if you don't have it the only thing you need to do solo app install h-stop and then it's going to ask your password and then this is going to install the h-top binary on your system which is extremely easy and convenient so and to finish this video uh i would recommend a bash tutorial so in case you're really really new to linux and scripting this is probably a good starting point along with this video so yeah i highly recommend you to to at least watch it and again while you watch it stop the video run the comments on your terminal and get used to it that's basically it from my side i highly appreciate your attention and if you have any questions just ask me or rodriguez will be happy to answer thank
Info
Channel: Cyrill Stachniss
Views: 2,714
Rating: undefined out of 5
Keywords: robotics, photogrammetry
Id: seW8wn4-EfI
Channel Id: undefined
Length: 36min 37sec (2197 seconds)
Published: Sat Oct 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.