YTread Logo
YTread Logo

Linux Command Line Full course: Beginners to Experts. Bash Command Line Tutorials

Jun 08, 2021
Let's take a look at the basics of

command

line

displaying a calendar for the current month On the

command

line

there is a simple command that you can use to display a calendar for the current month Cal Let's look at the basics of command line commands that display the current month date and time on the command line there is a simple command that you can use to display the current date and time the date command let's look at the basics of the command line PWD PWD is one of the simple commands you need to learn PWD means to print the working directory, this command gives us the location where we are currently located in the directory structure, let's take a look at the man page.
linux command line full course beginners to experts bash command line tutorials
PWD prints the name of the current working directory. There are a couple of options that you normally won't need. to use when running PWD currently we see that I am in my home directory. You 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 some more. I will see that wherever I go I can use PWD to find out the location where I am. Let's take a look at the basics of how to connect. Use exit to end a terminal session.
linux command line full course beginners to experts bash command line tutorials

More Interesting Facts About,

linux command line full course beginners to experts bash command line tutorials...

When you're done at the command line, it's good practice to explicitly terminate your attempt. terminal session, this is done using the exit command after running this command your

bash

session ends if you were connected to a remote server via SSH while I was here running the exit command also ends your SSH session let's take a look at the basics of how to connect using up and down arrow keys to navigate the command history, let's start by running some simple commands, we will start by running a command to see the current date and time, then we will print a simple message and then display a calendar of the current date and time. month when working on the command line, you'll probably want to run a command again.
linux command line full course beginners to experts bash command line tutorials
Bosch provides a simple medical mechanism to navigate through the commands you have recently used. Arrows up and down. By pressing the up arrow, Bosch will prompt you 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. Now the next most recently used command appears, which in this case was echo. 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 back in time through the command history, we can also Use the down arrow to navigate forward in time. command history, let's try pressing the down arrow.
linux command line full course beginners to experts bash command line tutorials
Doing so will advance one command to the echo command. Let's try pressing the down arrow again. By doing this again, we will advance one command this time to the Cal command and finally press the down arrow once again. The time we do this takes us back to an empty command line, this corresponds to where we were before we first pressed the up arrow, let's take a look at the basics of the command line using the left arrow keys and right to navigate within the current command, let's start 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 when using the command. left and right arrow keys I can navigate back and forth within the command as I type, let's take a look at the basics of the command line make Durr make Durr is used to create directories after using make Durr to create a directory we can use the LS command verify that that directory was created success

full

y, let's try again this time bothering ATS, let's ask Durr to be verbose by calling make dirt with the flag - to feed print twice a message for each directory created, of

course

still we can use LS to verify that the directory was created make Durr can also be used to create multiple directories at once if you try to create a directory in a directory with that name already exists maker will produce an error message in the above examples we create directories directly inside the current working directory It is also possible to use make dirt to create directories elsewhere.
This command creates a subdirectory called edu within the SRC directory. This behavior can be extremely useful; However, note that if the parent directory does not exist, make Durr will generate an error message and fail. to create the subdirectory, this command failed because the examples directory does not exist. There is a solution. Let's take a look at the manual to make Durr find it. PFLAG instructs the creator to create parent directories as needed. PFLAG can also be used. That manufacturer doesn't complain if the directory already exists. Remember that we already created a directory called bin as we saw before.
If we try to create a directory that already exists, Viktor will normally fail, but by calling the creator with -PFLAG, Viktor will silently succeed. In all the examples so far we have asked nature to create directories within the current working directory. Alternatively, we can call make dirt using the absolute path creator. It is an essential Linux command that you will use frequently. You should practice using it to create directories in your current directory. working directory and elsewhere, although you may never use the Z script or M script flags, you should learn to use the PFLAG script, let's take a look at whether we can describe the basics of using LS to list content of the current working directory.
LS is one of the most commonly used commands, let's take a look. If I run LS without arguments, it will display the contents of the current working directory. Now we can see that this directory contains five other directories. Baz foo homework kennel m and Zork, let's navigate to another directory and use LS. to see its contents, we can now see that the current Ken LM working directory contains several files and directories. Let's use CD to change to a different directory. Now if I run LS without parameters it will print the contents of the current working directory. which is a slash user, in conclusion, invoking LS without parameters will display the contents of the current working directory.
Let's take a look at the basics of the command line. Use less to view text files when working at the command line. You probably want it normally. To view the contents of multiple files you were working with, there are a number of programs you can use to achieve this goal. One of the most commonly used programs for viewing text files is less similar to many programs you will find. The file name is a play on words. Words Les was developed as a more feature-rich replacement for a previous text viewing application whose name was more. It can be used to view the contents of text files.
Note that unlike Windows, on Linux, file extensions like MD txt zip and dot PI are not. Significant even though the MD Readme file has an extension, it is still a plain text file and can be opened with less. It can be navigated up and down using various key shortcuts, including Space for forward and B for back to exit. Press q files. It has many options, one useful option is the display of line numbers. This option can be enabled with the dash and flag. Please note that if necessary the files will rap lines if the line is too wide to see on the current screen, start line 10 in this file. here but continue to here this line is marked as line 10 throughout let's look at other files here's George Washington's inaugural address and here's Johnson's and here's Obama's the text files don't have to be in English files are capable of displaying text in other languages, for example here is a Swadesh list for Russian files.
More than one file can also be opened at a time when using less to view multiple files. The command: n is used to navigate to the next file and the command: P is used. to navigate to the previous file is one of the most used programs you will find when using the command line. It is worth learning how to use it and knowing some of its most used shortcuts. Let's take a look at the command. line basics using LS to list the contents of a current directory using a relative path, let's take a look if I run LS without arguments it will display the contents of the current working directory.
LS also accepts an argument when I provide an argument to LS. will list the contents of that directory instead of the current directory, so here we see that there are multiple files and directories within the can LM directory. If we want to view the contents of one of these subdirectories, one approach would be to use CD. to navigate to that subdirectory 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 instead of calling CD and then calling LS, we can directly call LS providing the directory as an argument. in the previous invocation of LS we provided a relative path Ken LM/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 use dot and dot. we call that dot dot refers to the parent of the current working directory in this case the parent of the current working directory is Ken L M let's try another one in this case dot dot refers to the parent of the current working directory Ken LM and dot dot slash util refers to the ull directory inside the Ken LM directory. Let's take a look at the basics of the command line using LS to list the contents of a non-current directory using an absolute path.
Let's take a look if I run LS without arguments. displays the contents of the current working directory. LS also accepts an argument when I provide an argument; LS will list the contents of that directory instead of the current directory, so here we see that there are multiple files and directories inside the kennel. directory if we want to view the contents of one of these subdirectories, one approach would be to use CD to navigate to that subdirectory 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 instead of calling CD and then calling LS, we can call LS directly by providing the directory as an argument in the above invocation of LS, we provide an absolute path forward slash start forward slash Lina's /kennel m/include as an argument to LS, let's take a look at the basics of online connection, identifying and understanding symbolic links, let's take a look so far, everything seems normal. user bin Python is a file, more specifically, we can use this file to invoke the Python interpreter.
Let's take a closer look at this file in the previous LS invocation. used the -L flag to tell LS to use the long list format. Note that in this long list there is an arrow. The arrow means that the Python user bin is not a normal file, but is a symbolic link pointing to another file in this case. The Python user bin points to the Python 2.7 file. We can confirm that the user bin Python is a symbolic link by invoking the program file. The file can be used to determine the file type. This confirms that the Python user bin is a symbolic link.
Let's take a look. in user in Python 2.7, we now see 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. Now let's look at a slightly more complex example, we see that the user bin Emacs is a symbolic link to Etsy alternatives, Emacs. Okay, that's a little strange. Normally executable files are located in the user's container, not on Etsy. Let's take a look at Etsy alternatives. Emacs. We see now that we have another symbolic link which is the 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 Emacs alternatives and then finally to user bin Emacs 24 X.
In conclusion, symbolic links as shortcuts in Windows and aliases on Mac OS provide a mechanism for referencing another file, symbolic links can be easily identified using LS with the L dash flag and also using the file command. Let's take a look at the basics of command line using LS to view hidden files. If I run LS without arguments it will show the contents of the current working directory we can now see that this directory contains five other directories such as foo homework can LM and Zork however this directory actually contains a number of other hidden files by default LS ignores any file whose namestart with dot we can force LS to show these otherwise hidden files using - a flag, as you can see when we invoke LS with - a flag in the home directory, several hidden files can be seen.
Take a look at command line basics using LS with additional options. options if I run LS without arguments it will show the contents of the current working directory. Now we can see that this directory contains five other directories as foo Ken LM and Zork's task. There are several additional options we can use to configure LS one. The commonly used option is the flag - the the flag - the causes LS to use a long list format using the long list format shows us additional information for each file this information includes the file type file permissions the owner and the group associated with the file the file size the modification date and file name the file sizes reported by LS script L are not particularly readable using the -H flag LS will report file sizes in a more human-readable format.
Note that when we specify multiple flags we can list each flag separately or list the flags together, the above two commands are equivalent. There are several other useful indicators in LS which can be found by reading the LS man page. Let's take a look at the basics of command line using RM to delete files and directories. take a look, RM command can be used to delete files. Let's use RM to remove the license from the file in the current directory. After using RM, the specified file has been deleted. Note that by default RM does not ask you for confirmation.
It simply deletes the file if you use the -I flag RM will ask you for confirmation before starting to delete files. Let's use RM to delete a file in the food directory because we specified the -I flag RM asked us for confirmation before deleting 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 will say yes to the confirmation. We can also use the -V flag to force RM to explain what is being done. Let's try deleting another file. this time using the flag script invoking RM with the V flag script RM printed a message confirming that the file was deleted we can also invoke RM with an absolute path now let's try using RM to delete the food directory, which just happened I called to RM by providing Foo as an argument on what to delete and RM was unable to delete the directory.
Let's look at the RM man page to see if we can figure out what just happened by default. RM does not delete directories to force RM to delete a directory. and whatever content it may have, we can invoke RM with - our flag in many cases, especially when you are new to the command line, it is advisable to use the - I flag or - uppercase I when invoking RM recursively. Here we will use the - The capital I flag also uses the - V flag for RM to confirm which files it deletes. Let's take a look at the basics of the command line.
Using CD to navigate to a directory using a relative path. Let's take a look at where we are currently working. directory now use LS to view the contents of the current working directory we can use the built-in

bash

CD command to change directories to use CD we provide the name of the directory we want to navigate to let's use PWD to verify that we have changed directories notice that in the previous prompt of CD we only specify the name bass we do not write slash home slash Lane ass slash bass this style of referring to a directory with only part of its name shows the use of CD using a path relative to the absolute path in this case it would be slash home slash Lane ass slash bass the relative path we used was simply bass because we were located in the directory slash home slash Lane ass at the time we invoked CD the part of the path corresponding to the current directory can be skipped by using a relative path.
There are two special relative path components. Point and Point. Spot. Period refers to the current working directory. Spot. Dot refers to the parent of the current working directory. Let's remember where we are in the current working directory. Baz is located inside the directory lain s, we could refer to the parent by its absolute path slash start 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 the 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, which just happened, we were in slash home slash Lane ass / - We used dot dot twice from /home forward slash Lane ass / Fuu dot dot would refer to the home directory slash home forward slash Lane ass but we used the relative path dot dot slash dot dot if dot dot is the father then dot dot slash dot dot is the father of the father, in this case the father is slash home slash Lane ass and his father is slash home, so we invoke CD dot dot slash dot dot from home - foo takes us home, notice what we just did, we use a relative path lane s forward slash Ken LM to navigate from /home to horizontal slash forward slash Lane ass / Ken om we could have called CD twice but this way way was faster, let's go back and see the slower way we use Siddhi here to navigate one directory at a time just like we can use LS to search in subdirectories, we can also use CD to navigate directly to subdirectories, let's take a look at the concepts from the command line, let's understand complex relative paths using dot and dot, now let's take a look at an example of a relative path that uses dot and dot dot several times now let's go back and take a closer look at this complex relative path.
We will start by visualizing the directory tree in which we are operating. The directory tree looks like this to make it easier to keep track of the subdirectories. I have color coded the subdirectories we will discuss the current working directory is forward slash home forward slash lanus forward slash Ken LM useful forward slash flow note that I have color coded the names in this path to match the corresponding subdirectories in the tree of directories now let's look at our complex relative path again. Note that I have color-coded the names in this relative path to match the corresponding subdirectories in the directory tree dot dot seen here in red refers to the parent of our current working directory in case the parent is the util directory which is also drawn in red here in the tree, the double cast is a subdirectory of util, so since stream is the current working directory, dot, slash, the double cast refers to the subdirectory colored in gold on the diagonal bar of the tree. slash lanus forward slash ken om / Yuto / double conversion dot is another name for the current directory, this means that dot dot slash double conversion slash dot means exactly the same as dot dot slash double conversion the father of double conversion is what you say so dot dot forward slash double conversion forward slash dot forward slash dot dot refers to the red node in the tree whose absolute path is its forward slash home forward slash Lane LS Lane ass / can om / you tell Yuto's father that he is can- am so dot dot slash double conversion forward slash dot forward slash dot slash dot refers to forward slash home forward slash silly slash klm that we see in orange in the LM tree that 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 lanús / kennel m / LM and because the dot that 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 also refers to LM rappers is a sub-directory of LM so home dot dot slash double conversion slash dot slash dot dot slash slash dot slash dot slash LM slash slash dot slash rappers refers to the slash forward slash Lena slash Ken LM / LM / rappers dot dot we see here in blue refers to the parent of the current working directory, so this path refers to LM and finally the constructor is a subdirectory of LM, so dot dot slash double conversion slash dot slash dot slash slash dot slash dot slash LM slash dot slash rappers slash slash dot slash dot slash builder refers to home lane as Ken om LM Builder let's take a look at the command line concepts to understand complex relative paths using dot and dot dot now let's look at an example of a relative path that uses both dot and dot dot several times note that the following example is intentionally complex deliberately made complicated to illustrate how dot and dot dot can be use in other paths it may take a while before you find an example that is this complex in real life, but it's good to understand what's going on now, let's go back and look at that. unordered path dot dot refers to the parent of the current working directory in our case the parent is the directory you say the conversion is a subdirectory of which you say its absolute path is slash start slash Lane us / can L m/Yuto/double conversion dot is another name for the current directory which means dot dot slash double conversion slash dot means exactly the same as dot dot slash double conversion the parent of double conversion is you tells the parent of you tells is can LM then dot dot slash double conversion forward slash dot forward slash dot dot forward slash dot refers to the home lane since Ken LM is the subdirectory of the kennel n then dot dot forward slash double conversion forward slash dot forward slash dot dot forward slash dot dot slash to LAN refers to the home lane ass 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 refers to house Lane ass Ken om LM rappers is a subdirectory of LM, so dot dot slash double conversion slash dot slash dot dot slash dot dot slash LM slash slash rappers refers to the start lanus ken LM LM rappers dot refers to the parent directory of the current working directory, so dot slash double conversion slash dot slash dot slash slash dot slash LM slash dot slash rappers slash dot dot refers to the local lane as Ken LM LM and finally constructor is a subdirectory of LM so dot dot slash double conversion slash slash dot slash dot slash dot dot slash LM slash slash dot slash rappers slash dot dot slash builder bar refers to main rail ass Ken LM LM Builder let's take a look at the basics of the command line using CD to navigate to a directory using an absolute path let's take a look at where we are current working directory now let's use LS to view the contents of the current working directory we can use the bash CD built-in command to change directories to use CD we provide the name of the directory we want to navigate to let's use PWD to verify that we have changed directories, note that in the previous invocation of CD we specified

full

path forward slash home forward slash Lane ass forward slash under this style of referring to a directory by its full name shows the use of CD using an absolute path let's navigate to another place in the previous command, the absolute path we used was forward slash user local slash Note that an absolute path always begins with a slash the layout of the Linux directory structure is a tree there is a single root of the file system tree the slash notation represents the root of the file system all directories have a slash as their final ancestor each absolute path starts with a slash each absolute path specifies a sequence of relationships that start with the current file or directory and end at the root of the file system let's look at another absolute path We use Siddhi to navigate to /user/share/man/user/share/man is an absolute path, let's decompose this absolute path to understand it better man is a directory that we can use LS to view its contents, the main directory of man is share in other words the directory shared contains the man directory.
Let's verify this using LS to view the shared directory. The shared directory contains the man directory. The home directory of the share is the user. In other words, the user directory contains the shared directory. Let's check this using LS to see the users directory, the users directory contains the shared directory and finally the parent of the user is root, in other words the root directory contains theuser directory. Let's check this using LS to see the contents of the root directory, the root directory contains the user directory let's take a look at the basics of the command line using CD without options to navigate to the home directory let's take a look at where we are in the directory current working 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 use PWD to verify that we have changed directory now let's call CD again this time we are going to call CD without providing a directory path which normally happens 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 don't provide a directory, so where do we go? PWD and CD documentation to find 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 a forward slash. We invoke CD without any options. Let's go to the home directory, take a look at the CD documentation to find out why remember that CD is a bash built-in command. Documentation for bash's built-in commands can be accessed using the help command. The documentation indicates what the CD is used for. changing the shell working directory specifically CD is used to change the current directory Tudor is normally provided by the user; however, the square brackets in the usage mean that providing this value is optional;
In other words, users can call CD without providing a directory when this happens, CD reverts to a default value for dur, the default dur is the value of the startup shell variable, as we saw earlier, the shell variable home stores the value of the user's home directory, so calling CD without any options takes us to the home directory. let's take a look at the command line basics using MV to move files the MV command can be used to move files MV takes two required 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 to be moved in the previous evan invocation in the previous MV invocation I moved the license file from the can-am directory the result is a file in my current working directory called ABC another way to invoke MV is by giving an v a destination directory, for example, let's say we want to move file ABC from the current directory to the directory, to do this we call it V using ABC as the source file and bass as the destination directory, as you can see after the previous invocation of MB, the bass directory now contains ABC.
It is usually not necessary to provide any option to mV; However, if you want to confirm what MV is doing, invoke MV with - flag will explain what is being done by calling MV with - V Flag and confirm that you moved the bathroom/ABC file - m/kennel MV license can also be done. use to move multiple files to a common destination directory, let's use touch to create multiple empty files now let's use MV to move all four these files into the food directory the dot-dot-dot notation here indicates that MV allows us to specify multiple source files , as you can see, the four files have been moved to the food directory, let's take a look at the basics of the command line using CD to navigate using tilde, let's take a look at where we are in the current working directory we are currently located in the home directory each user has a unique home directory the home directory path can also be observed by printing the value stored in the home environment variable let's look and see what other users have in their home directories on this system browse or reference to a user's home directory is so common that there is a special shorthand syntax for doing it tilde notation tilde username refers to the home directory for the username, for example, let's try navigating to the user's home directory price - we can use PWD to verify that we have successfully navigated to the home directory for user price - 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 lanús so I can refer to my own home directory using tilde.
It turns out that referring to your own home directory is even more common than referring to someone else's home directory, so there is an even shorter shorthand notation for referring to your own home directory with an tilde when using an tilde as the directory. of bear without an accompanying username refers to the user's home directory. You can also use this notation to refer to files and directories within your home directory. Note that in the above invocation of CD tilde slash kennel m refers to the directory kennel M. which is in my home directory, including the tilde notation username can be used to refer to the home directory associated with the name of specified user, for example, and tilde notation can be used to reference your own home directory, let's look at the command line basics of using Ln to create symbolic links the Ln command, when used with the -s flag, it can be used to create symbolic links.
Symbolic links such as shortcuts, windows, and aliases in Mac OS provide a mechanism to reference another file in its first form. Ellen takes two required 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 to be created in the previous invocation of Ln I created a new symbolic link called ABC that points to the file license in the KLM ABC directory is not a copy of the license, it is a symbolic link to the license. We can verify this by using the file command to determine the type of ABC.
We can also check this by calling LS with the -L flag. The long file format is displayed. that ABC is a link and that points to kennel m/license now let's take a look at the second way of invoking Ln in the second way we only provide the path to the file that already exists when we invoke Ln in this way by providing only a single file as argument ellen creates a symbolic link to that file with the same name in the current working directory. The third way to summon Ln is more advanced and may involve some additional subtleties, so we'll cover it in a separate video. a look at command line concepts using Ln to create symbolic links to another directory, the Elland command when used with the -s flag can be used to create symbolic links.
Symbolic links such as shortcuts in Windows and aliases in Mac OS provide a mechanism for referencing. to another file let's see the third way to invoke Ln the first argument is the path to a file that already exists the second argument is a directory in which you want to create the new symbolic link mmm something is not right here the symbolic link is broken, let's remove the broken link and try again on the previous elan invocation. We try to create a symbolic link in another directory when we supply the first argument. It was a relative link.
This use of a relative link in the third form of Ln. is the cause of our broken link, there are a couple of possible solutions, the first solution is to simply use an absolute path instead of a relative path. Now let's remove the symbolic link and find out how to create a symbolic link in another directory using a relative link. path, let's try to find out why this link is broken inside the baz directory. license is a symbolic link pointing to kennel am slash licensed kennel m/license is a relative path within the baz directory. What does the relative path kennel m/license mean? it would mean that there should be a directory, a subdirectory called kennel am inside the current directory paths and inside that subdirectory there should be a file called license.
There's the problem, is there a kennel m directory inside Baz? No, we just run LS from Baths. and there is no kennel m subdirectory, the broken link is looking for something that doesn't exist, that's why it is broken, we can confirm this by using the read link to determine the absolute path that the symlink is trying to point to. This confirms that the symlink the link is looking for a file that doesn't exist slash home slash Lina's slash Baz slash kennel am slash license so what would happen if the missing file was created? Let's find out how to do it.
Let's create a directory called can om inside Baz. directory now let's use the touch command to create an empty file called license inside our newly created can-am directory finally see if our symlink is still broken the symlink license in bowser's directory is no longer broken why because the file was Search now exists, so our link is no longer broken, but it points to the wrong file specifically, it points to the empty file we just created and that's not what we want at all. Let's delete these dummy files and try again to use the third form. In order for ln2 to successfully create a link, it is useful 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. where the symbolic link will be located.
I remember created from above that it has a broken symlink with searching for a KLM directory inside the baz directory, so let's think about things relative to the baz directory from inside the bass directory, what relative path can we use to refer to slash home slash lame- ass / k om / license well, Ken LM and bass are both in the home directory; In other words, they have a common father. We can refer to the parent of the current working directory as dot dot, so from slash directly from directory Baz dot dot forward slash Ken L M refers to forward slash home forward slash lanus forward slash Ken L m and dot dot can't /kennel am/license refers to the file we want to assemble with that information let's try making that symlink again, it worked, we can use the read link to confirm that the symlink link now points to the correct file.
We have managed to create a symbolic link in another directory using a relative path. To do this, we had to think about the relative path from the perspective of the directory in which the link is being created. that we can ask Ln to do this perspective change for us when invoked with the script, our Ln flag will create the symbolic link relative to the link location, let's remove the existing link and test it by running LS script L, we can observe that when the script passed our flag to Ln Ln correctly translated the relative path we provided to kennel m/license to a relative path that is correct in the context of the Baths directory dot dot forward slash Ken LM forward slash call license read link confirms that the symbolic link in the bass directory actually points to the correct file forward slash home forward slash Lane ass / Ken om / license let's look at command line concepts using the file to determine a file type let's look at the command file accepts a file name as an argument, the command attempts to determine the specified file type using file.
We note that the local user is an excellent directory. That's exactly what we would expect. Let's look at a few more files and use the file command to determine their respective types. The file invocation above. tells us that the 1gz mail queue is made up of data that was compressed using gzip here we see that the license is a plain text file encoded using ASCII, let's look at the basics of the command line using CP to copy a single file, you can use the CP command to copy files CP takes two required 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 to copy the file in the previous invocation of CP I copied the license file from the Ken LM directory the resulting copy is a file in my current working directory called ABC ABC is a copy of the 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 want to copy file ABC into the directory path so we can call CP using ABC as source file and Baz as destination directory, as you can see after the previous invocation of CP the bass directory now contains a copy from ABC let me add basic concepts 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 can-am directory the first thing we can try is a simple invocation of CP what just happen we try to make a copy of the can-am directory called WXYZ if we run LS we see that ourattempts to copy the can-am directory failed by default CP will not copy directories for CP to copy a directory we must add an additional option when invoking CP if CP is invoked with - our flag will copy directories, including their contents, as can see after the previous invocation of CP with - the WXYZ directory now exists and is a copy of the KLM directory let's take a look at the basics of Kamiya Blind 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 note that the message was not printed until after the Enter key was pressed, although it may not always be necessary to enclose the message in quotes, doing so is good practice, let's use echo to display another simple message, as you can see, the message we gave echo is printed to stdout, it is possible to redirect the stdout stream to a file or use a pipe to send it as input to another process, in this case we are not doing any of those things, as a result we see that the default behavior where messages sent to stdout are displayed in the terminal let's use echo to display some simpler messages let's take a look at the basics that come online using echo to display multi-line messages echo is normally used to display a single line of text, however echo can be used to print messages spanning multiple lines of text Let's start by using echo to print a simple message consisting of a single line of text .
Now let's try again, but this time we're going to make a mistake. Notice what happened. We type the opening quotes, then we type the message, and then we press Enter. key instead of printing our message we see something that looks like a greater sign that notice that we forgot to write the closing quotes let's add the closing quotes and then press Enter again notice what just happened our message was printed but also a blank space additional The line was printed. See the extra blank line? 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 consisting of two lines of text when entering a multiple message. The multi-line message in this way was not limited to only two lines, the content of our message we will continue until we enter the closing quotes, then we enter the closing quotes and then press the Enter key, the entire multi-line message is printed lines. to standard output, let's take a look at the basics of command line 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 containing a single line of text now let's try again but this time we are going to include something new and to do so we are going to take a look at the echo documentation. Documentation for most commands can be found by accessing the command manual. pages that use the man command but echo is special echo is a bash builtin command the documentation for bash builtin commands is obtained using the command help by reading the Bosch help page we can see that echo is able to read a number backslash escape characters a backslash is just a character that is immediately preceded by a backslash character from the backslash escape sequences you see here, you will probably only need to use one or two of them, the two that What we will examine here are the escape sequences for the newline backslash N and for the horizontal tab backslash T.
Now let's try to print our message again, however, this time, instead of placing a space between the two sentences, we will try place a tab character between the two sentences. Remember that the escape sequence for a horizontal tab character is backslash T. What just happened? The backslash escape sequence T represents a horizontal tab character. We wanted echo to replace the backslash T with an actual tab character. Let's take another look at the help page for the echo in the previous invocation. in fact we don't use any options notice that echo has an option - e which does exactly what we want if echo is called with the option - II then echo will replace this escape sequence with its corresponding literal character.
Let's try again this time using the -' 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 add another tab. Now we can see a difference. Let's try again with three tabs. Compare it to Same but with three spaces between the sentences. Now let's try again using the escape sequence for a newline backslash. Oh! I did a 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 using escape sequences we can use echo to print a multi line message even while entering the command using a single line, let's take a look at the basics From the grep command line the grep command finds text patterns in files, printing all lines that contain a matching pattern. grep can find very complex patterns with the use of regular expressions.
Let's take a look at the graphics man page. grep searches for the named input file(s) or standard input if there is no named file, let's use grep to search for all files that have the word zip in the name in the bin directories and in the bin user to do this, first we use LS to list the files in those directories and then pipe the result to grab it and search it. The zip pattern displays a list of file names that contain zip. Grep pattern matching is case-sensitive by default. Let's try to list the file names in bin and user container that contain the word zip in uppercase.
We get zero matches to allow grep to ignore case when To match the pattern, we can use the -I flag with grep. The -I flag specifies that grap should ignore case sensitivity. If instead of a list of lines matching the pattern we want a list of lines not matching the pattern, we can use the dash V flag with grep to reverse the match, now we get a list of file names in bin and user bin that do not contain the word zip to generate the number of matches instead of the actual matching lines, we can use the C script option with grep here we observed that there were 19 elements that matched the zip pattern.
Let's take a look at the basics of the command line. head and tail head and tail are commands that print the first and last part 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 its man pages by default, head prints the first 10 lines of a file to standard output. This can be changed by using the dash and flag to specify the number of lines instead of assuming. the default value of 10 tail behaves very similarly. Let's create a text file and use head and tail to examine its first and last line.
We notice that foo text now contains an ordered list of the files in the user. 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 see different number of lines say first or last 5 lines of a file we can use dash n option with head and with tail these are the first 5 lines of food text and these are the last 5 lines of food text, the header and the tail, they can also be used in a pipe, let's list the last 7 elements of the contents of the bin directory of the user to do this we will use LS to enumerate the contents sort to sort them and pipe the output to the queue with the appropriate option which lists the last 7 items in the user's bin directory, let's look at the basics of the command line echo , let's take a look at the main page of echo the echo command accepts 0 or more strings supplied by the user and prints those strings to stdout if echo's stdout has not been redirected otherwise those strings will be displayed in the screen separated by spaces as we can see echo printed the string hello if we provide more than one string to echo will print each string and we will put a single space between each pair of strings here is the first string followed by a space followed by the next string if we provide more of one space between each string echo ignores extra spaces and only one space is printed if we want to print a string retaining all spaces and other formatting, we can enclose this string in quotes when we do this. echo will treat everything in quotes as a single string, let's take a look at the command: line basics wildcard expansion let's try using echo to display a single line of text.
Let's see that the line we wrote is displayed as we wrote it. Extra whitespace in echo arguments will be removed in the output. Here we write extra spaces, but the output. in those locations a space is only included when there are special characters in the text line, we see something else to check, this allows the CD to go to a different directory and view the contents of that directory using LS. Now let's try using echo with a wildcard. -character as argument, the star or asterisk here is treated as a wildcard character. Notice that echo did not display the star character itself, but instead displayed a list of the files in the current working directory.
Note that this echo output is the same. In terms of the listed files we saw with LS, this is because before running the echo command, 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 shell performs expansions for different character types echo is a good way to observe the effects of different special characters and their respective expansions before using these special characters with other commands, let's look at the basics of Kemah online expansion pathname: is capable of When performing certain types of expansions, let's try using LS to see how pathname expansion works in this command.
The wild character has been expanded. The result is a list of all file names in the specified directory whose file names end in dot H. Let's try another example. here the wildcard was expanded again, resulting in a list of all the files in the user's bin directory whose file names start with the characters py, let's take a look at the basics of command line tilde expansion expansion tilde is a special expansion involving the tilde character when the tilde character is used at the beginning of a username and expands to the name of that user's home directory.
Let's try using echo to see how tilde expansion works. Here we see an expansion that results in the full path to this user's home directory, if not. The username is provided after the tilde character, the result is expanded to the current user's home directory, which in this case is Lane. Notice here that the tilde character has been expanded to the current user's home directory, let's take a look at the command line. basics of 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 the arithmetic expansion let's see that this arithmetic expression seven plus three has been calculated with the result ten note that arithmetic expansion only supports integers for integers the expansion would result in an error if decimals are present in the expression see that Bosch has shown a error message for invalid decimal arithmetic operator indicating that the decimal point caused the error arithmetic expansion supports addition subtraction multiplication division integer module or remainder and exponentiation arithmetic expansion can also be used in conjunction with text let's try using echo to see how the division and integer modulo operators work if the result of division is not an integer Integer division will cause the result to be truncated to the integer part and will not be rounded, so use integer division 7 divide times 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 v to the exponent of 2 or 5 tosquare which is 25 inside the double parenthesis of an arithmetic expression it is possible to nest another arithmetic expression here we have nested an arithmetic expression 1+ 1 inside a larger expression 5 to the power of 1 plus 1 here the inner expression calculates 1+1 resulting in a value of for the outer expression performs 5^2 exponentiation resulting in 25 we can also use simple parentheses to group the order of operations without actually causing a second expansion of the arithmetic expression this will calculate the same result of 25 using only one arithmetic expansion instead of two let's look at the basics of the command line curly expansion curly brace creates multiple text strings from a pattern The pattern takes the form of an immutable preamble followed by a variable expansion component followed by an immutable PostScript.
The variable part of the pattern is enclosed by a pair of braces. The constant part before the opening brace is called the preamble and the constant part after the. the closing brace is a postscript, let's try using echo to see how brazing expansion works, this pattern has been expanded into three text strings, each string has the same preamble at the beginning and the same PostScript at the end, the middle part of each chain varies and is present. in the same order specified in the pattern Brahms Beethoven Bach Brahms Beethoven bah if we had changed the order in the pattern the order would be correspondingly different in the created strings both the preamble and the PostScript are optional here we extend a pattern with a preamble but there is no PostScript here we expand a pattern with a postscript but without preamble and finally we expand a pattern without preamble and without postscript now let's try to use brace expansion with a preamble including whitespace here Bosch considers I love and Brahms Beethoven Bach to be separate tokens, as a result , brace expansion is performed, but I love it, a preamble of brace expansion is not considered to solve this problem, let's try to close.
I love it quote unquote, this is a little better now Bosch sees two tokens instead of three. The first token is the quoted string I love and the second token is Brahms Beethoven Bach, but even in this case Bosch does not consider I love to be a preamble to the key expansion. We can solve this problem by placing the quoted string immediately adjacent to the Bray expansion. no intervening spaces now, in this case Bosch sees only one token, the entire string where I love it is taken as a preamble because it immediately precedes the opening brace with no intervening whitespace, finally let's add an extra space but place it inside the preamble quoted and also add a postscript.
I'm adding a space but placing it inside the quoted preamble and leaving no intermediate space between the preamble and the start of the pattern inside the braces. Finally I'm going to put in a single point postscript. A brace expansion can contain a list of strings separated by commas, as we just saw, it can also contain a range of integers or characters using the dot dot operator, let's try using echo to see how to specify a range in brace expansion. Note that I am NOT putting a space between the preamble and the pattern to expand an underscore is fine but a space does not this expands 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 The pattern has been expanded to a sequence of lowercase letters.
Integers within a brace expansion can be 0-padded. Here we have 0-padded numbers from 1 to 9 and here we have 0-padded numbers from 90 to 100. Brace expansions can also specify numbers in reverse order. Here we have something. expanded to strings where the numeric part is in reverse order from 5 to 1, curly brace expansions can specify a range of characters as we have seen above and character ranges can also be reversed. We note that this character range has been expanded to lowercase characters in reverse order. expansions can also be nested, let's work on this expansion part by part in the expansion, the lowercase a in the preamble and the lowercase B in PostScript are constants in the variable part of the expression the brace expression is a list of elements separated by commas , so Bosch starts with first element a1: this is a key expansion and also expands to two strings uppercase one and uppercase two, so the first two strings produced for the entire expansion are a a one B and a a for be now the first nested brace expansion.
Complete bash now starts with the second element b3 for the next two strings produced are the b3 expansions which are then prepended with the preamble a and then the suffix B is added followed by the b4 expansion, finally resulting in a B for B. The Brace expansions are particularly useful for making lists of files or directories where the names have a fixed format, for example imagine that we want to organize a sequence of photos by month and year, then perhaps we want to create a series of directories in numerical format in order chronological instead of creating the directories one by one using make tur command by hand we can use one command using curly brace expansion now using a single make dur command we can create a series of directories with this command we have created directories for all the months over a range of 10 years let's take a look at the online basics of Kemah pathname expansion bash is capable of certain types of expansions let's try using LS to see how pathname expansion works in this command the wildcard character has been expanded the result is a list of all file names in the specified directory whose file names end in dot H, let's try another example here, the wildcard was expanded again resulting in a list of all files in the bin directory of the user whose file names begin with the characters py, let's take a look at command line basics command substitution command substitution allows us to use the output of one command as an argument to another command.
This is done using the dollar sign character followed by a pair of simple parentheses. The command whose output we want to use goes inside the parenthesis let's start by using LS to list the contents of the 11 Substituting the command then causes this the output to be used as arguments to echo echo finally displays a list of those elements. Note that command substitution is very different from piping. The pipe allows us to redirect the output of one command to the standard input of another command, for example a pipe could be used to pipe the output of 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 would not work and would have no effect. in LS because LS does not make use of standard input, on the other hand, command substitution allows us to use the output of a command as the argument or arguments of another command, therefore, if we want to configure the behavior of a command like LS with the output of another command we would use command substitution not pipe, let's try to use command substitution to provide arguments to LS in the external command, we are trying to use LS with the -L flag to create a long list in this format, we are using command that with an argument of CP to determine the full directory, the full absolute path to the CP command, the result of which is CP, then CP is substituted as an argument to LS dash L, resulting in the output we see here. an older syntax for command substitution that we do not recommend that you use, however you may occasionally see that the above syntax uses backticks instead of the dollar sign in parentheses syntax again, we do not recommend using this older text syntax However, it's important to be able to recognize If you see it in someone else's scripts, let's take a look at the basics of the command line.
Escape characters by default, the dollar sign has special meaning to the shell. Using the dollar sign here tells bash that we want to reference the variable called user. bash then looks for a variable called user gets the content of that variable and replaces user with the content 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 that We want in this case the dollar sign to be preceded by a backslash which prevents this particular dollar sign from being interpreted as a special character.
If that dollar sign is followed by text, then quoting the dollar sign prevents expansion by treating the dollar sign as an actual literal dollar sign rather than a special character that in normal cases would indicate that an expansion should be performed. This type of quote is used to selectively suppress expansions. It's useful when we occasionally want special characters like the dollar sign to appear as themselves. let's look at the effect of this type of escape character in commands in this command there are two expansions that could take place here we have a variable that expands to the value of that variable here Lane's second escape transforms the dollar sign backslash into the literal dollar sign character and prevents dollar 5 from being treated as a variable expansion. sign is a character with a special meaning to hit.
There are other characters that also have a special meaning for hitting. These include the dollar sign we just discussed. The exclamation point. The backslash itself and the space character that 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 normal text, we would also need to escape 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, in turn it doesn't escape the dollar sign and the dollar sign here normally acts normally to cause the variable expansion, see we have this backslash character in front of the username.
Let's look at an example using many other escape characters. Here we have escaped a literal space and an exclamation point. Another literal space in an exclamation point. The exclamation mark and exclamation point have a special meaning for bash and can be explored in other situations needless to say without this escape we would not get this exact result. Another way we can confirm that special treatment is occurring here is by using brace expansion. you need the preamble not to 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 are going to look at that because we are using the backslash to escape the spaces, bash considers this entire chain to be a single token, which means we will get greetings and greetings as a preamble to this key expansion.
We confirm this here. We get greetings and greetings Jo, greetings and greetings Jane, let's take the basics of the double command line. Quoted strings Many times when passing arguments to a command, it is desirable for bash to treat a string containing spaces as a unique token, as we discussed above. One mechanism to get 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 escaping spaces is to use double-quoted strings to enclose the full file name by first quoting the string my first file dot txt: Treat this entire string as a single token within double quotes some characters that normally have meaning special for bash are treated as normal characters with no special meaning normally the ampersand character has a special meaning for bash inside the quotes that special meeting is lost while calling wildcard characters including star, tilde character, curly braces will all be used should be treated as normal text and not as special characters enclosed in double quotes, therefore the following operations are suppressed word splitting path name expansion tilde expansion and curly brace expansion let's look at 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, the space is interpreted as a special character to perform word splitting and the extra spaces are simply ignored if you put thisargument enclosed in double quotes, spaces within the string are no longer interpreted as special characters, but rather the entire quoted string is treated as a single token for hyphenation purposes. All of these spaces remain in the output as normal text. Let's try a command. where double quotes will suppress expansions, we note in these examples that when the tilde is used outside the double quotes, the tilde expands to the full pathname of the current user.
We also notice that when the star wildcard character is used outside the quotes, it expands here. to bar and here to Foo however, when the same string is enclosed in double quotes, tilde expansion and wildcard expansion are suppressed the tilde is treated simply as a tilde character the star character is treated simply as a star character let's see another example here we see the race expansion in action the color of the preamble followed by color 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 curly brace expansion has no place and braces are treated simply as literal brace characters our other special characters retain their special meaning in double quotes these exceptions include braces from the dollar sign character when used with the dollar sign character single parentheses when used with the dollar sign character double parentheses when used with the backticks of the dollar sign character and the backslash character when used to escape these other special characters, this allows the following operations to be performed between double quotes parameter expansion using dollar sign arithmetic expansion using 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 sign of dollar and braces and here using simply a dollar sign the result of that expansion is observed here for this first case where the user variable is replaced with its value rail s which is the name of the current user and again the user variable is replaced with the value of that variable Lane s here the arithmetic expansion is performed the dollar sign double parentheses indicates that the 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 the substitution of the command, the Cal command is executed and the output is replaced with this expression here, all these operations were expanded as expected despite being enclosed in double quotes, the parameter expansion gives us the value of the variable called user arithmetic expansion calculated the result of two plus two and the command substitution has shown the output of the command Cal let's look at the basics of command line strings enclosed in single quotes many times when passing arguments to a command for which a string is desirable that contains spaces should be treated by bash as a unique token, as we discussed above.
One mechanism to obtain this behavior is to escape the relevant space characters using the backslash character. Another alternative is to enclose the string in double quotes. A third alternative that we will discuss now is the use of single quotes, just as when using double quotes to enclose a string, when a string is enclosed in single quotes, bash will treat that string as a single token. Remember that when using double-quoted strings, hyphenation parameter expansion. Tilde expansion and curly brace expansion are suppressed, but parameter expansion, arithmetic expansion, and command substitution still occur when a string is enclosed in 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 files. text files, now let's try a command that involves tilde expansion, brace expansion, command substitution, arithmetic expansion and parameter expansion; starts by tokenizing the argument line, resulting in seven tokens passed as arguments to echo. The first argument is the plain text string. Hello, comma. The second argument is. the world of plain text strings the third argument is the string tilde / example / star dot txt this argument is expanded using tilde and wildcard expansion in the start lanus example a text with dots and the start rail s example b text with points the fourth argument is 3.7 inside curly braces, this is expanded using brace expansion into two, three, four, five, six, seven, the fifth argument is the Etsy crontab file in dollar parentheses.
This is expanded as a command substitution in the result of running the file command with the Etsy crontab argument, resulting in etsy crontab: ASCII text. just as if we had written it on the command line the sixth argument is the arithmetic operation two plus two that is expanded using arithmetic expansion in the result for the seventh argument is the user variable that is expanded using parameter expansion in lanús the echo command prints each of these results is separated by a single space character. Now let's see what changes when we enclose this list of arguments in double quotes.
First, we can see that the literal space characters in the string are preserved. This is because the entire string is enclosed in quotes. by Bosch as a single token when the string is enclosed in double quotes tilde expansion is suppressed wildcard expansion is suppressed augmentation 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 in single quotes instead of double quotes again, first we see that the literal space characters are preserved again, this is because, as before, bash treats all the quoted string as a single token when the string is enclosed in single quotes, all forms of the expansion are suppressed until the wildcard expansion is depressed the expansion is depressed the race expansion is suppressed the license plate is depressed the arithmetic expansion is suppressed and parameter expansion is suppressed instead we get the exact string literal we typed being returned by the echo command

If you have any copyright issue, please Contact