 Let's take a look at command line basics, displaying a calendar of the current month. At the command line, there is a simple command that you can use to display a calendar of the current month, CAL. Let's take a look at command line basics, displaying the current date and time. At the command line, there is a simple command that you can use to display the current date and time. The date command. Let's take a look at command line basics, PWD. PWD is one of the simple commands that you need to learn. PWD stands for print working directory. This command gives us the location where we're currently located in the directory structure. Let's take a look at the manual page. PWD prints the name of the current working directory. There are a couple of options which you usually won't need to use. When we run PWD currently we see that I'm in my home directory. We can explore other places in the file system and use PWD to identify where we are. Let's use the cd command to go somewhere else. Let's try a few more. You'll see that wherever I go I can use PWD to find out the location where I am. Let's take a look at command line basics using exit to end a terminal session. When you are done at the command line it is good practice to explicitly terminate your bash terminal session. This is done using the command exit. After you execute this command your bash session ends. If you were connected to a remote server via SSH as I was here executing the exit command also terminates your SSH session. Let's take a look at command line basics using up and down arrow keys to navigate the command history. Let's begin by running a few simple commands. We'll start by running a command to see the current date and time. Next we'll print a simple message and next let's display a calendar of the current month. When working at the command line it is likely that you may want to run a command again. Bash provides a simple mechanism for navigating the commands that you have used recently the up arrow and the down arrow. Pressing the up arrow will instruct bash to recall the previous command from the list of recently used commands. Let's try pressing the up arrow as you can see the most recently used command now appears. Let's try pressing the up arrow again the next most recently used command which in this case was echo now appears. Let's try pressing the up arrow again the next most recently used command which in this case was date now appears. Just as we can use the up arrow to navigate backwards in time through the command history we can also use the down arrow to navigate forwards in time through the command history. Let's try pressing the down arrow doing so takes us forward one command to the echo command. Let's try pressing the down arrow again doing so again takes us forward one command this time to the call command and finally let's press the down arrow one more time doing so takes us back to an empty command line this corresponds with where we were before we first pressed the up arrow. Let's take a look at command line basics using left and right arrow keys to navigate within the current command. Let's begin with a command that displays a simple message. After entering this command what can I do if I want to change what I just typed? One option would be to delete what I typed using the backspace key and then type something else. However there is a more efficient option by using the left and right arrow keys I can navigate backwards and forwards within the command as I type. Let's take a look at command line basics, makedir. Makedir is used to create directories. After using makedir to create a directory we can use the ls command to verify that that directory was successfully created. Let's try again this time let's ask makedir to be verbose. By calling makedir with the dash of v flag makedir prints a message for each created directory we can of course still use ls to verify that the directory was created. Makedir can also be used to create multiple directories at one time. If you attempt to create a directory and a directory with that name already exists makedir will produce an error message. In the previous examples we created directories directly within the current working directory. It is also possible to use makedir to create directories elsewhere. This command creates a sub directory called edu inside the src directory. This behavior can be extremely useful however the advice that if the parent directory does not exist makedir will produce an error message and will fail to create the sub directory. This command failed because the examples directory doesn't exist. There's a solution. Let's take a look at the manual for makedir to find it. The dash p flag instructs makedir to make parent directories as needed. The dash p flag can also be used so that makedir doesn't complain if the directory already exists. Recall that we already created a directory called bin. As we saw earlier if we try to create a directory that already exists makedir will normally fail but by calling makedir with the dash p flag makedir will silently succeed. In all of the examples so far we've asked makedir to create directories within the current working directory. We can alternatively call makedir using absolute paths. Makedir is an essential Linux command that you will use frequently. You should practice using it to create directories in your current working directory and elsewhere. While you may never use the dash z or dash m flags you should learn to use the dash p flag. Let's take a look at command line basics using ls to list the contents of the current working directory. ls is one of the most commonly used commands. Let's take a look. If I run ls with no arguments it will display the contents of the current working directory. We can now see that this directory contains five other directories. Baz, foo, homework, canlm, and zork. Let's navigate to another directory and use ls to view its contents. We can now see that the current working directory, kenlm, contains a number of files and directories. Now let's use cd to change to a different directory. Now if I run ls with no parameters it's going to print the contents of the current working directory which is slash user. In conclusion invoking ls with no parameters will display the contents of the current working directory. Let's take a look at command line basics using ls to view text files. When working at the command line it is likely that you will commonly want to view the contents of various files you were working with. There are a number of programs you can use to accomplish this goal. One of the most widely used programs for viewing text files is ls. Like many programs you will encounter the name ls is a play on words. ls was developed as a more fully featured replacement for an earlier text viewing application whose name is more. ls can be used to view the contents of text files. Notice that unlike on windows on linux file extensions such as .md, .txt, .zip, and .py are not meaningful. Even though readme.md has an extension it is still a plain text file and can be opened by ls. ls can be navigated page up and page down using various key shortcuts including space to page forward and b to move backwards. To exit ls press q. ls has lots of options. One helpful option is the display of line numbers. This option can be enabled with the dash n flag. Notice that if necessary ls will wrap lines if the line is too wide to be viewed on the current display. Line 10 in this file begins here but continues through here. This line is marked as line 10 throughout. Let's take a look at some other files. Here is George Washington's inaugural address and here is Johnson's and here is Obama's. The text files don't have to be in English. ls is capable of displaying text in other languages. For example here's a swadish list for russian. ls can also open more than one file at a time. When using ls to view multiple files the command colon n is used to navigate to the next file and the command colon p is used to navigate to the previous file. ls is one of the most commonly used programs you will encounter when using the command line. It is well worth your while to learn how to use it and to learn some of its more commonly used shortcuts. Let's take a look at command line basics using ls to list the contents of a non-current directory using a relative path. Let's take a look. If I run ls with no arguments it will display the contents of the current working directory. ls also accepts an argument. When I provide an argument to ls it will list the contents of that directory rather than the current directory. So here we see that there are a number of files and directories within the kenlm directory. If we want to see the contents of one of these subdirectories one approach would be to use cd to navigate to that sub directory and then use ls to view its contents. However, there is a faster way. Let's go back to the home directory and try the faster way. Rather than calling cd and then calling ls we can directly call ls providing the directory as an argument. In the above invocation of ls we provided a relative path. kenlm slash include as an argument to ls. After doing so ls listed the contents of the specified directory. We can also call ls using other relative paths including those that make use of dot and dot dot. Recall that dot dot refers to the parent of the current working directory. In this case the parent of the current working directory is kenlm. Let's try another. In this case dot dot refers to the parent of the current working directory kenlm and dot dot slash util refers to the util directory that is within the kenlm directory. Let's take a look at kenlm blind basics using ls to list the contents of a non-current directory using an absolute path. Let's take a look. If I run ls with no arguments it will display the contents of the current working directory. ls also accepts an argument. When I provide an argument to ls it will list the contents of that directory rather than the current directory. So here we see that there are a number of files and directories within the kenlm directory. If we want to see the contents of one of these subdirectories one approach would be to use cd to navigate to that sub directory and then use ls to view its contents. However, there is a faster way. Let's go back to the home directory and try the faster way. Rather than calling cd and then calling ls we can call ls directly providing the directory as an argument. In the above invocation of ls we provided an absolute path slash home slash lane s slash kenlm slash include as an argument to ls. Let's take a look at kenlm blind basics identifying and understanding symbolic links. Let's take a look. So far everything looks normal. User bin python is a file. More specifically we can use this file to invoke the python interpreter. Let's look more closely at this file. In the above invocation of ls we used the dash l flag to direct ls to use the long listing format. Notice that in this long listing there is an arrow. The arrow means that user bin python is not a regular file. Instead it is a symbolic link that points to another file. In this case user bin python points to the file python 2.7. We can confirm that user bin python is a symbolic link by invoking the program file. File can be used to determine the type of a file. This confirms that user bin python is a symbolic link. Let's take a look at user bin python 2.7. We see now that user bin python 2.7 is an actual executable file. So when we call python the system redirects our call so that python 2.7 is called instead. Now let's look at a slightly more complex example. We see that user bin emacs is a symbolic link to etsy alternatives emacs. Okay that's a little strange. Normally executable files are located in user bin not in etsy. Let's take a look at etsy alternatives emacs. We see now that we have another symbolic link. Etsy alternatives emacs is actually a symbolic link to user bin emacs 24x. So when we run user bin emacs the system redirects our call twice. First to etsy alternatives emacs and then finally to user bin emacs 24x. In conclusion symbolic links like shortcuts in windows and aliases in the mac os provide a mechanism for referring to another file. Symbolic links can be easily identified by using ls with the dash l flag and also by using the file command. Let's take a look at command line basics using ls to view hidden files. If I run ls with no arguments it will display the contents of the current working directory. We can see now that this directory contains five other directories bazz foo homework canlm and zork. However this directory actually contains a number of other hidden files. By default ls ignores any file whose name begins with dot. We can force ls to display these otherwise hidden files by using the dash a flag. As you can see when we invoke ls with the dash a flag in the home directory a number of hidden files can be seen. Let's take a look at command line basics using ls with additional options. If I run ls with no arguments it will display the contents of the current working directory. We can now see that this directory contains five other directories bazz foo homework canlm and zork. There are a number of additional options we can use to configure ls. One commonly used option is the dash l flag. The dash l flag causes ls to use a long listing format. Using the long listing format shows us additional information for each file. This information includes the file type, file permissions, the owner, and group associated with the file, the file size, the modification date, and the file name. The file sizes reported by ls dash l aren't particularly readable. By using the dash h flag ls will report file sizes in a more human readable format. Notice that when we specify multiple flags we can either list each flag separately or list the flags together. The above two commands are equivalent. There are a number of other useful flags in ls which can be found by reading through the ls man page. Let's take a look at command line basics using rm to delete files and directories. Let's take a look. The rm command can be used to delete files. Let's use rm to delete the file license in the current directory. After using rm the specified file has been deleted. Note that by default rm does not prompt you for confirmation. It simply deletes the file. If you use the dash i flag rm will prompt you for confirmation before it begins deleting files. Let's use rm to delete a file in the food directory. Because we specified the dash i flag rm prompted us for confirmation before it deleted the file. Let's see what happens if I say no. rm did not delete the file. Let's try again and this time we'll say yes to the confirmation. We can also use the dash v flag to force rm to explain what is being done. Let's try removing another file this time using the dash v flag. By invoking rm with the dash v flag rm printed a message confirming that the file was deleted. We can also invoke rm with an absolute path. Now let's try to use rm to delete the food directory. What just happened? We called rm providing foo as the argument for what to delete and rm failed to delete the directory. Let's look at the man page for rm to see if we can figure out what just happened. By default rm does not remove directories. To force rm to remove a directory and any contents it might have we can invoke rm with the dash r flag. In many cases especially when you are new to the command line it is advisable to use the dash i or dash capital i flag when invoking rm recursively. Here we'll use the dash capital i flag. We will also use the dash v flag so that rm will confirm what files it deletes. Let's take a look at command line basics using cd to navigate to a directory using a relative path. Let's take a look at where we are the current working directory. Now let's use ls to view the contents of the current working directory. We can use the bash built-in command cd to change directories. To use cd we provide the name of the directory into which we wish to navigate. Let's use pwd to verify that we've changed directories. Notice that in the above invocation of cd we only specified the name bas. We did not type slash home slash lane s slash bas. This style of referring to a directory by only part of its name shows the use of cd using a relative path. The absolute path in this case would be slash home slash lane s slash bas. The relative path that we used was simply bas. Because we were located in the directory slash home slash lane s at the time we invoked cd the part of the path corresponding to the current directory can be omitted through the use of a relative path. There are two special relative path components dot and dot dot. Dot refers to the current working directory. Dot dot refers to the parent of the current working directory. Let's recall where we are. The current working directory bas is located within the directory lane s. We could refer to the parent by its absolute path slash home slash lane s or we could refer to it as dot dot. Let's use cd and dot dot to navigate to the parent of the current working directory. Let's practice some more. What just happened? We told cd to navigate to dot. Dot is another name for the current working directory. Consequently we stayed in the same current working directory. In other words we didn't go anywhere. What just happened? We were in slash home slash lane s slash foo. We used dot dot twice from slash home slash lane s slash foo. Dot dot would refer to the parent directory slash home slash lane s but we used the relative path dot dot slash dot dot. If dot dot is the parent then dot dot slash dot dot is the parent of the parent. In this case the parent is slash home slash lane s and its parent is slash home. So invoking cd dot dot slash dot dot from home lane s foo takes us to home. Notice what we just did. We used a relative path lane s slash ken lm to navigate from slash home to slash home slash lane s slash ken lm. We could have called cd twice but this way was faster. Let's go back and see the slower way. We used cd here to navigate one directory at a time. Just as we can use ls to look into subdirectories we can also use cd to navigate directly into subdirectories. Let's take a look at command line concepts. Understanding complex relative paths using dot and dot dot. Now let's take a look at one example of a relative path that uses both dot and dot dot multiple times. Now let's go back and take a closer look at this complex relative path. We'll begin by visualizing the directory tree in which we're operating. The directory tree looks like this. For convenience in keeping track of subdirectories I have color coded the subdirectories we'll be discussing. The current working directory is slash home slash lane s slash ken lm slash util slash stream. Notice that I've color coded the names in this path to match the corresponding subdirectories in the directory tree. Now let's look at our complex relative path. Again notice that I've color coded the names in this relative path to match the corresponding subdirectories in the directory tree. Dot dot which you see here in red refers to the parent of the current working directory. In our case the parent is the util directory which is also drawn in red here in the tree. Double conversion is a subdirectory of util. Thus given that stream is the current working directory dot dot slash double conversion refers to the subdirectory colored in gold in the tree slash home slash lane s slash ken lm slash util slash double conversion. Dot is another name for the current directory. This means that dot dot slash double conversion slash dot means exactly the same thing as dot dot slash double conversion. The parent of double conversion is util thus dot dot slash double conversion slash dot slash dot dot refers to the red node in the tree whose absolute path is slash home slash lane ls lane s slash ken lm slash util. The parent of util is ken lm so dot dot slash double conversion slash dot slash dot dot slash dot dot refers to slash home slash lane s slash ken lm which we see colored orange in the tree lm which you see in blue is a subdirectory of ken lm so dot dot slash double conversion slash dot slash dot dot slash dot dot slash lm refers to slash home slash lane s slash ken lm slash lm and because dot which we see here in blue refers to the current directory dot dot slash double conversion slash dot slash dot dot slash dot dot slash lm slash dot refers also to lm. Rappers is a subdirectory of lm so dot dot slash double conversion slash dot slash dot dot slash dot dot slash lm slash dot slash wrappers refers to slash home slash lane s slash ken lm slash lm slash wrappers dot dot which we see here in blue refers to the parent of the current working directory so this path refers to lm and finally builder is a subdirectory of lm and so dot dot slash double conversion slash dot slash dot dot slash dot dot slash lm slash dot slash wrappers slash dot dot slash builder refers to home lane s ken lm lm builder let's take a look at command line concepts understanding complex relative paths using dot and dot dot now let's take a look at one example of a relative path that uses both dot and dot dot multiple times note that the following example is intentionally complex deliberately made convoluted to illustrate how dot and dot dot can be used within other paths maybe a while before you encounter an example that says complex in real life but it is good to understand what's going on now let's go back and unpack that messy path dot dot refers to the parent of the current working directory in our case the parent is the utl directory double conversion is a subdirectory of utl its absolute path is slash home slash lane s slash ken lm slash utl slash double conversion dot is another name for the current directory that means dot dot slash double conversion slash dot means exactly the same thing as dot dot slash double conversion the parent of double conversion is utl the parent of utl is ken lm so dot dot slash double conversion slash dot slash dot dot slash dot dot refers to home lane s ken lm lm is a subdirectory of ken lm so dot dot slash double conversion slash dot slash dot dot slash dot dot slash lm refers to home lane s ken lm lm and because dot refers to the current directory dot dot slash double conversion slash dot slash dot dot slash dot dot slash lm slash dot is the same as dot dot slash double conversion slash dot slash dot dot slash dot dot slash lm Also referring to HOME, LANE, S, KEN, LM, LM. Rappers is a subdirectory of LM, so dot dot slash double conversion slash dot slash dot dot dot slash dot dot slash LM slash dot slash wrappers refers to HOME, LANE, S, KEN, LM, LM, wrappers. Dot dot refers to the parent of the current working directory, so dot dot slash double conversion slash dot slash dot dot slash dot slash LM slash dot slash wrappers slash dot dot refers to HOME, LANE, S, KEN, LM, LM. And finally, builder is a subdirectory of LM, so dot dot slash double conversion slash dot slash dot dot slash dot dot slash LM slash dot slash wrappers slash dot dot slash builder refers to HOME, LANE, S, KEN, LM, LM, builder. Let's take a look at command line basics using CD to navigate to a directory using an absolute path. Let's take a look at where we are, the current working directory. Now, let's use LS to view the contents of the current working directory. We can use the bash built-in command CD to change directories. To use CD, we provide the name of the directory into which we wish to navigate. Let's use PWD to verify that we have changed directories. Notice that in the above invocation of CD, we specified the full path slash HOME slash LANE, S slash BAS. This style of referring to a directory by its full name shows the use of CD using an absolute path. Let's navigate somewhere else. In the above command, the absolute path that we used was slash user slash local. Notice that an absolute path always begins with a slash. The layout of the Linux directory structure is a tree. There is a single unique root of the file system tree. The notation slash represents the root of the file system. All directories have slash as their ultimate ancestor. Every absolute path begins with slash. Every absolute path specifies a sequence of contains relations beginning with the current file or directory and ending at the root of the file system. Let's look at another absolute path. We used CD to navigate to slash user slash share slash man slash user slash share slash man is an absolute path. Let's decompose this absolute path to understand it better. Man is a directory. We can use ls to view its contents. The parent directory of man is share. In other words, the share directory contains the man directory. Let's verify this by using ls to view the share directory. The share directory contains the man directory. The parent directory of share is user. In other words, the user directory contains the share directory. Let's verify this by using ls to view the user directory. The user directory contains the share directory. And finally, the parent of user is root. In other words, the root directory contains the user directory. Let's verify this by using ls to view the contents of the root directory. The root directory contains the user directory. Let's take a look at command line basics using CD without options to navigate to the home directory. Let's take a look at where we are, the current working directory. We are currently located in the home directory. Each user has a unique home directory. The path of the home directory can also be observed by printing the value stored in the home environment variable. Now let's navigate to a different directory. Let's use pwd to verify that we have changed directories. Now let's call cd again. This time we're going to call cd without providing a directory path. What just happened? Normally when we call cd, we provide a relative or absolute path to a directory, and cd then takes us to that specified directory. In this case, we didn't provide a directory. So where did we go? Let's use pwd and the documentation for cd to figure out what just happened. By running pwd, we can see that cd took us to the home directory. Each user's home directory is different. My home directory is slash home slash lane s. We invoked cd without any options. Doing so took us to the home directory. Let's take a look at the documentation for cd to find out why. Recall that cd is a bash built-in command. Documentation for bash built-in commands can be accessed using the help command. The documentation states that cd is used to change the shell working directory. Specifically, cd is used to change the current directory to dir. Normally dir is provided by the user. However, the square brackets in the usage means that providing this value is optional. In other words, users are allowed to call cd without providing a directory. When this happens, cd falls back to a default value for dir. The default dir is the value of the home shell variable. As we saw earlier, the home shell variable stores the value of the user's home directory. Thus, calling cd without any options takes us to the home directory. Let's take a look at command line basics using mv to move files. The mv command can be used to move files. mv takes two mandatory arguments. When moving a single file, the first argument is the path to the file you want to move. The second argument is the path where you want the file moved to. In the above invocation of mv, I moved the license file from the knlm directory. The result is a file in my current working directory called abc. Another way to invoke mv is by giving mv a destination directory. For example, let's say we wanted to move the file abc from the current directory into the directory baz. To do so, we call mv using abc as the source file and baz as the destination directory. As you can see, after the above invocation of mv, the baz directory now contains abc. Usually, it is not necessary to supply any options to mv. However, if you want confirmation of what mv is doing, invoking mv with the dash v flag will explain what is being done. By calling mv with the dash v flag, mv confirms that it moved the file baz slash abc to knlm slash license. mv can also be used to move multiple files to a common destination directory. Let's use touch to create several empty files. Now, let's use mv to move all four of these files into the foo directory. The dot dot dot notation here indicates that mv allows us to specify multiple source files. As you can see, all four files have been moved to the foo directory. Let's take a look at command line basics. Using cd to navigate using tilde. Let's take a look at where we are, the current working directory. We are currently located in the home directory. Each user has a unique home directory. The path of the home directory can also be observed by printing the value stored in the home environment variable. Let's look and see what other users have home directories on this system. Navigating to or referring to a user's home directory is so common, there is a special shorthand syntax for doing so. Tilde. The notation tilde username refers to the home directory for username. For example, let's try navigating to the home directory for the user Brice2. We can use pwd to verify that we have successfully navigated to the home directory for the user Brice2. Let's try again with another user. I can also use this notation to refer to my own home directory. My username on this system is laness, so I can refer to my own home directory using tilde laness. It turns out that referring to your own home directory is even more common than referring to someone else's home directory. Consequently, there's an even shorter shorthand notation for referring to your own home directory, tilde. When used as a directory, a bare tilde without an accompanying username refers to the user's own home directory. You can also use this notation to refer to files and directories within your home directory. Notice that in the above invocation of cd, tilde slash canlm refers to the canlm directory that is in my home directory. In conclusion, the notation tilde username can be used to refer to the home directory associated with the specified username. For example, the notation tilde can be used to refer to your own home directory. Let's take a look at command line basics. Using lan to create symbolic links. The lan command, when used with the dash s flag, can be used to create symbolic links. Symbolic links, like shortcuts and windows and aliases in the macOS, provide a mechanism for referring to another file. In its first form, lan takes two mandatory arguments. The first argument is the path to a file that already exists. The second argument is the path where you want the new symbolic link created. In the above invocation of lan, I created a new symbolic link called abc that points to the license file in the canlm directory. abc is not a copy of license. It is a symbolic link to license. We can verify this by using the file command to ascertain the type of abc. We can also verify this by calling ls with the dash l flag. The long file format shows that abc is a link and that it points to canlm slash license. Now, let's take a look at the second form of invoking lan. In the second form, we only provide the path to the file that already exists. When we invoke lan in this manner, providing only a single file as an argument, lan creates a symbolic link to that file with the same name. In the current working directory. The third form of invoking lan is more advanced and can involve some additional subtleties, so we'll cover that in a separate video. Let's take a look at command line concepts. Using lan to create symbolic links in another directory. The lan command, when used with the dash s flag, can be used to create symbolic links. Symbolic links like shortcuts and windows and aliases in the macOS provide a mechanism for referring to another file. We're going to look at the third form of invoking lan. The first argument is the path to a file that already exists. The second argument is a directory in which you want the new symbolic link created. Something's not right here. The symbolic link is broken. Let's remove the broken link and try again. In the above invocation of lan, we attempted to create a symbolic link in another directory. When we provided the first argument, it was a relative link. This use of a relative link in the third form of lan is the cause of our broken link. There are a couple of possible solutions. The first solution is simply to use an absolute path instead of a relative path. Now, let's remove the symbolic link and figure out how to make a symbolic link in another directory using a relative path. Let's try to figure out why this link is broken. Within the BAS directory, license is a symbolic link pointing to canlm slash license. Canlm slash license is a relative path. Within the BAS directory, what does the relative path canlm slash license mean? Well, it would mean that there should be a directory, a subdirectory called canlm within the current directory, BAS. And within that subdirectory, there should be a file called license. There's the problem. Is there a canlm directory inside BAS? No, there's not. We just ran ls from within BAS and there is no canlm subdirectory. The broken link is looking for something that doesn't exist. That's why it's broken. We can confirm this by using read link to determine the absolute path that the symbolic link is attempting to point to. This confirms that the symbolic link is looking for a file that doesn't exist. So what would happen if the missing file were to be created? Let's find out. To do so, let's create a directory called canlm within the BAS directory. Now, let's use the touch command to create an empty file called license within our newly created canlm directory. Finally, let's see if our symbolic link is still broken. The symbolic link license in the BAS directory is no longer broken. Why? Because the file it was looking for for now exists. So, our link is no longer broken, but it's pointing to the wrong file. Specifically, it's pointing to the empty file we just created. That's not what we want at all. Let's remove these dummy files and try again. In order to use the third form of ln to correctly create a link, it's helpful to realize two things. First, ln interprets this first argument as a string. And second, if that string represents a relative path, the file system will interpret that relative path relative to the directory in which the symbolic link is to be created. Recall from above that our broken symbolic link was looking for a canlm directory within the BAS directory. So, let's think about things relative to the BAS directory. From within the BAS directory, what relative path can we use to refer to slash home slash lanes slash canlm slash license? Well, canlm and BAS are both in the home directory. In other words, they have a common parent. We can refer to the parent of the current working directory as dot dot. So, from the bar from the BAS directory, dot dot slash canlm refers to slash home slash lanes slash canlm. And dot dot slash canlm slash license refers to the file that we want. Armed with that information, let's try making that symbolic link again. It worked. We can use read link to confirm that the symbolic link is now pointing to the correct file. We have succeeded in creating a symbolic link in another directory using a relative path. To do so, we had to think about the relative path from the perspective of the directory in which the link is being created. It turns out that we can ask ln to do this change of perspective for us. When invoked with the dash r flag, ln will create the symbolic link relative to the link location. Let's remove the existing link and give this a try. By running ls dash l, we can observe that when the dash r flag was passed to ln, ln correctly translated the relative path we provided canlm slash license into a relative path that is correct in the context of the BAS directory. Dot dot slash canlm slash license. Calling read link confirms that the symbolic link in the BAS directory is indeed pointing to the correct file slash home slash lane s slash canlm slash license. Let's take a look at command line concepts using file to determine a file's type. Let's take a look. The file command accepts a file name as an argument. The command attempts to determine the type of the specified file. Using file, we observe that user local is a directory. Great. That's exactly what we would expect. Let's look at some more files and use the file command to determine their respective types. The above invocation of file tells us that mail q dot one dot gz is comprised of data that was compressed using gzip. Here we see that license is a plain text file encoded using ASCII. Let's take a look at command line basics using cp to copy a single file. The cp command can be used to copy files. cp takes two mandatory arguments. When copying a single file, the first argument is the path to the file you want to copy. The second argument is the path where you want the file copied to. In the above invocation of cp, I copied the license file from the knlm directory. The resulting copy is a file in my current working directory called abc. abc is a copy of license. We can use the diff command to verify that the two files are identical. Another way to invoke cp is by giving cp a destination directory. For example, let's say we wanted to copy the file abc into the directory baz. To do so we can call cp using abc as the source file and baz as the destination directory. As you can see, after the above invocation of cp, the baz directory now contains a copy of abc command line basics using cp to copy a single directory. The cp command can be used to copy files and directories. Let's say we want to make a copy of the knlm directory. The first thing we might try is a simple invocation of cp. What just happened? We tried making a copy of the knlm directory called wxyz. If we run ls, we see that our attempts to copy the knlm directory failed. By default, cp will not copy directories. To get cp to copy a directory, we must add an additional option when invoking cp. If cp is invoked with the dash r flag, it will copy directories, including their contents. As you can see, after the above invocation of cp with dash r, the wxyz directory now exists. And is a copy of the knlm directory. Let's take a look at command line basics using echo to print simple strings. Echo is typically used to display a single line of text. Here, the message was hello world. Echo prints this message to standard output. Notice that the message was not printed until after the enter key was pressed. While it may not always be necessary to enclose the message within quotation marks, doing so is good practice. Let's use echo to display another simple message. As you can see, the message we gave to echo is printed to standard output. It is possible to redirect the standard output stream to a file or use a pipe to send it as input to another process. In this case, we aren't doing either of those things. As a result, we see the default behavior where messages sent to standard output are displayed on the terminal. Let's use echo to display some more simple messages. Let's take a look at command line basics using echo to display multi-line messages. Echo is typically used to display a single line of text. However, echo can be used to print messages that span multiple lines of text. Let's start by using echo to print a simple message consisting of a single line of text. Let's try again, but this time we're going to make a mistake. Notice what happened. We typed the opening quotation mark, then we typed the message, then hit the enter key. Instead of printing our message, we see something that looks like a greater than sign. Notice that we forgot to type the closing quotation mark. Let's add the closing quotation mark, then hit enter again. Notice what just happened. Our message was printed, but in addition, an extra blank line was printed. Do you see the extra blank line? It's there. Let's try another example. In our next example, the second line will contain more of the message. Here, it should be clear that echo printed a message that consisted of two lines of text. When entering a multi-line message in this manner, we're not limited to just two lines. The contents of our message will continue until we enter a closing quotation mark. After we enter the closing quotation mark and then press the enter key, the entire multi-line message is printed to standard output. Let's take a look at command line basics using echo to display messages with escape sequences. Echo is typically used to display plain text messages. However, echo can be used to print messages that include special characters. Let's start by using echo to print a message consisting of a single line of text. Now, let's try again. But this time, we're going to include something new. And to do so, we're going to take a look at the documentation for echo. The documentation for most commands is found by accessing the command's manual pages using the command man. But echo is special. Echo is a bash built-in command. The documentation for bash built-in commands is obtained using the command help. By reading the bash help page, we can observe that echo is capable of reading a number of backslash escaped characters. A backslash escaped character is just a character that is immediately preceded by a backslash character. Of the backslash escape sequences you see here, it's likely that you'll only ever need to use one or two of them. The two that we'll examine here are the escape sequences for new line backslash n and for horizontal tab backslash t. Now, let's try printing our message again. However, this time, instead of placing a space between the two sentences, we're going to try to place a tab character between the two sentences. Recall that the escape sequence for a horizontal tab character is backslash t. What just happened? The escape sequence backslash t represents a horizontal tab character. We wanted echo to replace backslash t with an actual tab character. Let's take another look at the help page for echo. In the above invocation of echo, we did not use any options. Notice that echo has an option dash e that does exactly what we want. If echo is called with the dash e option, then echo will replace the escape sequence with its corresponding literal character. Let's try again, this time using the dash e flag. It looks like there is a space character between the sentences, but it's actually a tab. To see the difference more clearly, let's try again, but this time, let's add another tab. Now we can see a difference. Let's try again with three tabs. Compare that to the same thing, but with three spaces between the sentences. Now let's try again using the escape sequence for a new line, backslash n. Whoops, I did backslash t again. Let's try again with backslash n. Now let's add another new line. And now again with three new line characters. By using escape sequences, we can use echo to print a multi-line message even while we enter the command using a single line. Let's take a look at command line basics, grep. The grep command finds text patterns in files. It prints out all the lines containing a matching pattern. Grep can match very complex patterns with the use of regular expressions. Let's take a look at grep's man page. Grep searches the named input file or files or standard input if no file is named. Let's use grep to find all the files that have the word zip in the name in the directories bin and userbin. To do this, we first use ls to list the files in those directories. Then pipe the result to grep to search for the pattern zip. A list of file names containing zip is displayed. Grep pattern matching is case sensitive by default. Let's try to list the file names in bin and userbin that contain the word zip in uppercase. We get zero matches. To allow grep to ignore case when matching the pattern, we can use the dash i flag with grep. The dash i flag specifies that grep should ignore case distinctions. If instead of a list of lines that match the pattern, we want a list of lines that do not match the pattern, we can use the dash v flag with grep to invert the match. We now get a list of file names in bin and userbin that do not contain the word zip. To output the number of matches instead of the actual matching lines, we can use the dash c option with grep. Here we observe that there were 19 items which matched the pattern zip. Let's take a look at command line basics, head and tail. Head and tail are commands that print the first and last parts of a file respectively. By default, head prints the first 10 lines of a file and tail prints the last 10 lines. Let's take a look at their man pages. By default, head prints the first 10 lines of a file to standard output. This can be changed using the dash n flag to specify the number of lines instead of assuming the default of 10. Tail behaves very similarly. Let's create a text file and use head and tail to examine its first and last lines. We can observe that foo.txt now contains a sorted list of the files in userbin. We can use head to display the first 10 lines of the file. We can use tail to display the last 10 lines of the file. To view a different number of lines, say the first or last 5 lines of a file, we can use the dash n option with head and with tail. These are the first 5 lines of foo.txt and these are the last 5 lines of foo.txt. Head and tail can also be used in a pipeline. Let's list the last 7 items of the contents of the directory userbin. To do this, we will use ls to list the contents, ls to sort them, and pipe the output to tail with the appropriate option, listing the last 7 items in the directory userbin. Let's take a look at command line basics, echo. Let's take a look at echo's man page. The command echo accepts 0 or more strings provided by the user and prints those strings to standard output. If the standard output of echo has not been otherwise redirected, then those strings will be displayed to the screen separated by spaces. As we can see, echo printed the string hello. If we provide more than one string to echo, it will print each string and will put a single space between each pair of strings. Here's the first string followed by a space followed by the next string. If we provide more than one space between each string, echo ignores the extra spaces and only a single space is printed. If we want to print a string preserving all spacing and other formatting, we can enclose the string in quotation marks. When we do this, echo will treat everything within the quotation marks as a single string. Let's take a look at command line basics, wildcard expansion. Let's try to use echo to display a single line of text. See that the line we typed is displayed just as we typed it. Extra white space in the arguments of echo will be removed in the output. Here we typed extra spaces, but the output in those locations only included a single space. When there are special characters in the line of text, we see something else. To check this, let's cd to a different directory and look at the contents of that directory using ls. Now let's try to use echo with a wildcard character as the argument. The star or asterisk here is treated as a wildcard character. Notice echo did not display the character star itself. Instead, it displayed a listing of the files in the current working directory. Notice that this output of echo is the same in terms of the files listed as that we saw with ls. This is because before the echo command is executed, the shell itself has expanded the wildcard character into a list of file names in the current working directory. It is very important to understand how the shell carries out expansion for different kinds of characters. Echo is a good way to observe the effects of different special characters and their respective expansions before we use these special characters with other commands. Let's take a look at command line basics. Path name expansion. Bash is capable of performing certain types of expansions. Let's try to use ls to see how path name expansion works. In this command, the wildcard character has been expanded. The result is a listing of all file names in the specified directory whose file names end in .h. Let's try another example. Here, the wildcard expanded again, resulting in a list of all files in the user bin directory whose file names begin with the character's py. Let's take a look at command line basics. Tilda expansion. Tilda expansion is a special expansion involving the Tilda character. When the Tilda character is used at the beginning of a username, it expands into the name of the home directory for that user. Let's try to use echo to see how Tilda expansion works. Here, we see an expansion resulting in the full path to this user's home directory. If no username is supplied after the Tilda character, the result expands into the home directory of the current user, which in this case is lane s. We observe here that the Tilda character has been expanded into the home directory of the current user. Let's take a look at command line basics. Arithmetic expansion. Arithmetic expansion allows the shell to perform calculations before passing the results to a command as arguments. Arithmetic expansion uses the dollar sign character and double parentheses around an arithmetic expression. Let's use echo to see how arithmetic expansion works. See that this arithmetic expression, 7 plus 3, has been calculated with the result 10. Note that arithmetic expansion only supports integers or whole numbers. The expansion would result in an error if decimals are present in the expression. See that bash has displayed an error message for the decimal, invalid arithmetic operator indicating that the decimal point caused the error. Arithmetic expansion supports addition, subtraction, multiplication, integer division, modulo, or remainder, and exponentiation. Arithmetic expansion may also be used alongside text. Let's try to use echo to see how the integer division and modulo operators work. If the result of the division is not an integer, integer division will cause the result to be truncated to the integer part and will not be rounded. So, using integer division, 7 divided by 2 is 3 with a remainder of 1. The 1 was calculated using the modulo operator. The 3 was calculated using integer division. Now, let's use echo to observe how the exponentiation operator works. This calculation has raised 5 to the exponent of 2, or 5 squared, which is 25. Inside the double parentheses of an arithmetic expression, it is possible to nest another arithmetic expression. Here we have nested an arithmetic expression 1 plus 1 within a larger expression 5 to the power of 1 plus 1. Here, the inner expression calculates 1 plus 1, resulting in a value of 2. The outer expression performs the exponentiation 5 to the power of 2, resulting in 25. We can also use single parentheses to group the order of operations without actually causing a second expansion of the arithmetic expression to occur. This will calculate the same result of 25 using only one arithmetic expansion instead of 2. Let's take a look at command line basics. Brace expansion. Brace expansion creates multiple text strings from a pattern. The pattern takes the form of an unchanging preamble, followed by a variable expansion component, followed by an unchanging post script. The varying part of the pattern is enclosed by a pair of curly braces. The constant part before the opening brace is called a preamble, and the constant part trailing after the closing brace is a post script. Let's try to use echo to see how brace expansion works. This pattern has expanded into three text strings. Each string has the same preamble at the beginning and the same post script at the end. The middle part of each string varies, and is present in the same order as specified in the pattern. If we had changed the order in the pattern, the order would be correspondingly different in the created strings. Both the preamble and the post script are optional. Here, we expand a pattern with a preamble, but no post script. Here, we expand a pattern with a post script, but no preamble. And finally, we expand a pattern with no preamble and with no post script. Now, let's try to use brace expansion with a preamble that includes white space. Here, bash considers i, love, and Brahms Beethoven Bach to be separate tokens. As a result, the brace expansion is performed, but i, love, is not considered a preamble to the brace expansion. To get around this problem, let's try enclosing i, love in quotes. This is slightly better. Now, bash sees two tokens instead of three. The first token is the quoted string i, love, and the second token is Brahms Beethoven Bach. But bash still in this case does not consider i, love to be a preamble to the brace expansion. We can fix this by placing the quoted string immediately adjacent to the brace expansion with no intervening spaces. Now, in this case, bash sees only one token, the entire string, where i, love, is taken to be a preamble because it immediately precedes the opening brace with no intervening white space. Finally, let's add an additional space but place it inside the quoted preamble and also add a post script. I'm adding a space but placing it inside the quoted preamble and leaving no intervening space between the preamble and the start of the pattern inside the braces. Finally, I'm going to place a post script, a single period. A brace expansion can contain a comma separated list of strings as we have just seen. It can also contain a range of integers or characters using the operator dot dot. Let's try to use echo to see how to specify a range in brace expansion. Notice that I am not placing a space between the preamble and the pattern to be expanded. An underscore is fine but a space is not. This is expanded to five strings, number one, number two, number three, number four, number five. We can also use a sequence of characters with the dot dot operator. Here the pattern has expanded to a sequence of lowercase letters. Integers within a brace expansion can be zero padded. Here we have zero padded numbers one through nine and here we have zero padded numbers 90 through 100. Brace expansions can also specify numbers in reverse order. Here we have something expanded to strings where the numerical part is in reverse order from five through one. Brace expansions can specify a range of characters as we have seen above and character ranges can also be reversed. We observe that this character range has expanded to lowercase characters in reverse order. Brace expansions can also be nested. Let's work through this expansion part by part. In the expansion the preamble lowercase a and the postscript lowercase b are constant. In the variable part of the expression the brace expression is a list of items separated by comma. So bash starts with the first item a one two. This is a brace expansion as well. Now this expands to two strings uppercase a one and uppercase a two. So the first two strings produced for the entire expansion are a a one b and a a two b. Now the first nested brace expansion is complete. Bash now starts with the second item b three four. The next two strings produced are the expansions b three which is then prepended with the preamble a and postpended with the suffix b followed by the expansion b four ultimately resulting in a b four b. Brace expansions are particularly useful for making lists of files or directories where the names are of a fixed format. For example imagine that we want to organize a sequence of photos by month and year. We may wish then to create a series of directories in numeric format in chronological order. Instead of creating the directories one by one using the command maker by hand we can use a command using brace expansion. Now using a single maker command we can create a series of directories. With this one command we have created directories for all of the months over a range of 10 years. Let's take a look at command line basics. Path name expansion. Bash is capable of performing certain types of expansions. Let's try to use ls to see how path name expansion works. In this command the wildcard character has been expanded. The result is a listing of all file names in the specified directory whose file names end in .h. Let's try another example. Here the wildcard expanded again resulting in a list of all files in the user bin directory whose file names begin with the character's py. Let's take a look at command line basics. Command substitution. Command substitution allows us to use the output of a command as an argument of another command. This is done by using the dollar sign character followed by a pair of single parentheses. The command whose output we want to use goes inside the parentheses. Let's begin by using ls to list the contents of the etsy x11 directory. Now let's enclose this ls command using the command substitution syntax. Here we have first executed the command ls to output a list of items in the etsy x11 directory. Command substitution then causes this output to be used as the arguments to echo. Echo finally displays a list of those items. Note that command substitution is very different from piping. Piping allows us to redirect the output of one command to the standard input of another command. For example a pipeline could be used to pipe the output from ls to the input of sort. If we were to reverse that pipeline in an attempt to pipe the output of sort to the input of ls this wouldn't work and it would have no effect on ls because ls does not make use of standard input. On the other hand command substitution allows us to use the output of one command as the argument or arguments of another command. Therefore if we wish to configure the behavior of a command such as ls with the output of another command we would use command substitution not piping. Let's try to use command substitution to provide arguments to ls. In the outer command we are attempting to use ls with the dash l flag to create a long listing in this format. We're using the command which with an argument of cp to determine the full directory the full absolute path to the cp command. The result of which is bin cp. Bin cp is then substituted as the argument to ls dash l resulting in the output that we see here. There is also an older syntax for command substitution that we do not recommend that you use however you may occasionally see it that older syntax uses back ticks instead of the dollar sign parentheses syntax. Again we do not recommend using this back tick syntax however it's important to be able to recognize it if you see it in someone else's scripts. Let's take a look at command line basics escaping characters. By default the dollar sign has special significance to the shell. Use of the dollar sign here tells bash that we want to refer to the variable called user. Bash then looks for a variable called user gets the contents of that variable and replaces user with the contents of the user variable. If we want to print a string containing an actual dollar sign we can precede the dollar sign with a backslash. The character we wish to quote in this case a dollar sign is then preceded with a backslash which prevents this particular dollar sign from being interpreted as a special character. If that dollar sign is followed by text then the quoting of the dollar sign prevents expansion by treating the dollar sign as an actual literal dollar sign rather than a special character which in normal cases would indicate that expansion is to be done. This type of quoting is used to selectively suppress expansions. It is handy when we occasionally want a special character such as the dollar sign to appear as itself. Let's see the effect of this type of character escaping in commands. In this command there are two expansions that could take place. Here we have a variable that is expanded to the value of that variable here lane s. Secondly escaping transforms backslash dollar sign into the literal dollar sign character and prevents the prevents dollar five from being treated as a variable expansion. The dollar sign is a character with special significance to bash. There are other characters that also have special significance to bash. These include the dollar sign which we just discussed, the exclamation point, the ampersand, the backslash itself, and the space character which bash uses to delimit tokens. Any of these special characters can be escaped using a backslash. Since the backslash is itself a special character if we want a backslash character to appear as ordinary text we would also need to escape it with a preceding backslash character. Here the first backslash character escapes the second backslash character resulting in a literal backslash character. Because this second character was escaped it does not in turn escape the dollar sign and the dollar sign here normally acts as normal to cause a variable expansion. See that we get this backslash character in front of the username. Let's see an example using multiple other escaped characters. Here we have escaped a literal space, an ampersand, another literal space, and an exclamation point. The ampersand and exclamation point have special significance to bash and can be explored in other situations. Needless to say without this escaping we would not get this exact output. Another way that we can confirm that special treatment is occurring here is by using brace expansion. Recall from our discussion of brace expansion that normally brace expansion with a preamble needs the preamble to not be separated by a space. The reason is that a preamble is only considered if it is part of the same token as the token containing the braces. Here we're going to see that because we are using the backslash to escape the spaces this entire string is taken to be a single token by bash meaning that we will get greetings and salutations taken as the preamble to this brace expansion. We confirm this here, we get greetings and salutations Joe, greetings and salutations Jane. Let's take a look at command line basics. Double quoted strings. Many times when passing arguments to a command it is desirable for a string containing spaces to be treated by bash as a single token. As we previously discussed one mechanism for obtaining this behavior is to escape the relevant space characters using the backslash character. Here we have created a file with literal spaces in the file name. An alternative method to using escaped spaces is to use double quoted strings to enclose the entire file name. By first quoting the string myfirstfile.text bash treats this entire string as a single token. Within double quotes some characters which normally have special significance to bash are treated as normal characters without special meaning. Normally the ampersand character has special meaning to bash inside the quotes that special meaning is lost. Wild card characters including the star, the tilde character, curly braces will all be treated as ordinary text and not special characters. Within double quotes therefore the following operations are suppressed. Word splitting, path name expansion, tilde expansion and brace expansion. Let's observe the effects of double quotes in some commands. In this command the argument to echo includes extra spaces between two of the words. The output of echo does not have these extra spaces between the word A and the word test. This is because without double quotes space is interpreted as a special character for the purposes of performing word splitting and the extra spaces are simply ignored. If we put this argument in double quotes the spaces within the string are no longer interpreted as special characters. Rather the entire quoted string is treated as a single token for the purposes of word splitting. All of these spaces remain in the output as ordinary text. Let's try command where double quotes will suppress expansions. We observe in these examples that when the tilde is used outside of double quotes the tilde expands to the full path name of the current user. We also observe that when the star wild card character is used outside quotes it is expanded here to bar and here to foo. However when the same string is enclosed within double quotes the tilde expansion and the wild card expansion are both suppressed. The tilde is treated simply as a tilde character. The star character is treated simply as a star character. Let's look at another example. Here we observe brace expansion in action. The preamble color followed by red or green or blue. Color red, color green, color blue. This is the result of the expansion. When we enclose this same string in double quotes the brace expansion does not take place and the curly braces are treated simply as literal curly brace characters. There are other special characters that retain their special meaning inside double quotes. These exceptions include the dollar sign character, curly braces when used with the dollar sign character, single parentheses when used with the dollar sign character, double parentheses when used with the dollar sign character, back ticks and the backslash character when used to escape these other special characters. This allows the following operations to be carried out within double quotes. Parameter expansion using the dollar sign, arithmetic expansion using the dollar sign in parentheses and command substitution. Let's try a command that is not affected by these double quotes. This command contains two examples of parameter substitution here using a dollar sign and curly braces and here using simply a dollar sign. The result of that expansion is observed here for this first case where the variable user is replaced with its value lane s which is the name of the current user and again the variable user is replaced with the value of that variable lane s. Here arithmetic expansion is performed. The dollar sign double parentheses indicates that arithmetic expansion will be performed. The arithmetic expression two plus two is replaced with the result of that arithmetic operation the integer four and finally command substitution. The command cal is run and the output is substituted for this expression here. All of these operations expanded as expected despite being within double quotes. Parameter expansion gives us the value of the variable named user arithmetic expansion calculated the result of two plus two and command substitution has displayed the output of the command cal. Let's take a look at command line basics single quoted strings. Many times when passing arguments to a command it is desirable for a string containing spaces to be treated by bash as a single token. As we previously discussed one mechanism for obtaining this behavior is to escape the relevant space characters using the backslash character. Another alternative is to enclose the string within double quotes. A third alternative which we will discuss now is the use of single quotes. Just as when double quotes are used to enclose a string when a string is enclosed in single quotes that string will be treated by bash as a single token. Recall that when using double quoted strings word splitting parameter expansion tilde expansion and brace expansion are suppressed but parameter expansion arithmetic expansion and command substitution are still performed. When a string is enclosed within single quotes none of these expansion operations are performed. Let's look at an example but first let's create a new directory containing a couple of empty text files. Now let's try a command involving tilde expansion brace expansion command substitution arithmetic expansion and parameter expansion bash begins by tokenizing the argument line resulting in seven tokens which are passed as arguments to echo. The first argument is the plain text string hello comma the second argument is the plain text string world. The third argument is the string tilde slash example slash star dot txt. This argument is expanded using tilde expansion and wildcard expansion into home lanus example a dot text and home lanus example b dot text. The fourth argument is three dot dot seven within curly braces. This is expanded using brace expansion into three four five six seven. The fifth argument is file etsy chron tab within dollar parentheses. This expands via command substitution into the result of performing the file command with the argument etsy chron tab resulting in etsy chron tab colon ascii text just as if we had typed it at the command line. The sixth argument is the arithmetic operation two plus two which is expanded using arithmetic expansion into the result four. The seventh argument is the variable user which is expanded using parameter expansion into lanus. The echo command prints each of these results separated by a single space character each. Now let's see what changes when we enclose this argument list within double quotes. First of all we can see that the literal space characters in the string are preserved. This is because the entire quoted string is treated by bash as a single token when the string is enclosed in double quotes tilde expansion is suppressed wildcard expansion is suppressed brace expansion is suppressed but command substitution still takes place arithmetic expansion still takes place and parameter expansion still takes place. Now let's see what happens when we enclose the argument within single quotes instead of double quotes. Again we first see that the literal space characters are again preserved this is because as before the entire quoted string is treated by bash as a single token when the string is enclosed in single quotes all forms of expansion are suppressed tilde expansion is suppressed wildcard expansion is suppressed brace expansion is suppressed command substitution is suppressed arithmetic expansion is suppressed and parameter expansion is suppressed instead we get the exact literal string that we typed in being returned by the echo command.