You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
7.8 KiB
99 lines
7.8 KiB
<!doctype html> |
|
<html> |
|
<head> |
|
<meta charset="utf-8"> |
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
|
<title>My Learning Website</title> |
|
<link href="/styles/styles.css" rel="stylesheet" type="text/css"> |
|
<link href="/linux/styles/styles.css" rel="stylesheet" type="text/css"> |
|
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> |
|
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> |
|
<!--[if lt IE 9]> |
|
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> |
|
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> |
|
<![endif]--> |
|
</head> |
|
<body> |
|
|
|
<div class="banner"> |
|
<h1 class="courselink">Learning Linux Command Line</h1> |
|
<h2 class="lecturer">LinkedIn Learning : Scott Simpson</h2> |
|
<h2 class="episodetitle">Command-Line Basics</h2> |
|
</div> |
|
|
|
<article> |
|
<h2 class="sectiontitle">What is the Command Line?</h2> |
|
<p>The basic structure of a command is:</p> |
|
<pre class="inset"> |
|
Command Option(s) Argument(s)</pre> |
|
<p>A command is always required but both options and arguments are optional.</p> |
|
<p>Options are usually a single letter but often have a longer equivalent. For instance</p> |
|
<pre class="inset">$ls -a</pre> |
|
<p>will list all files in a directory, but so will</p> |
|
<pre class="inset">$ls --all</pre> |
|
<p>Note the double hyphen when using the longer version. Actually, in this example, is you execute the command (with a single hyphen)</p> |
|
<pre class="inset">$ls -all</pre> |
|
<p>this may appear to work, however, it is interpreting the a in all as the short version of the option and the l as the shortened version of the option for a long directory listing (and is seeming to simply ignore the second l). So, in other words, this is equivalent to typing</p> |
|
<pre class="inset">$ls -al</pre> |
|
<p>To see all of the options available for a particular command you can view its manual page using the command man followed by the command you want to investigate so for the ls command this would be</p> |
|
<pre class="inset">$man ls</pre> |
|
<p>It maty be worth noting that if you use the short versions of the options, you can group them together but if you use the longer versions, each option must be separated by a space (which is why the long version of the option all was interpreted as two separate options, a followed by l).</p> |
|
<p>The arguments modify the command by specifying what we want it to operate on. For instance, let’s say we want to display the contents of the folder /var/lib without navigating to that folder, we can do that with the command</p> |
|
<pre class="inset">$ls -al /var/lib</pre> |
|
<h2 class="sectiontitle">Helpful Keyboard Shortcuts in the Terminal</h2> |
|
<p>Tab completion, when you are typing something out at the prompt such as a directory or file name, you can type part of the name and press tab to auto-complete it, provided the full name can be inferred unambiguously.</p> |
|
<figure> |
|
<img src=" images\figure1.png " alt="Figure 1 - a typical directory listing for a home directory"> |
|
<figcaption>Figure 1 - a typical directory listing for a home directory</figcaption> |
|
</figure> |
|
<p>For instance, the contents of a typical home directory might be something like that shown in figure 1.</p> |
|
<p>Now, let’s say we want to navigate to the Desktop directory, we can do this by typing</p> |
|
<pre class="inset">$cd De</pre> |
|
<p>followed by the tab key. This will autocomplete the command giving us</p> |
|
<pre class="inset">$cd Desktop</pre> |
|
<p>and we can then complete the operation by pressing return. This is possible because Desktop is |
|
the only directory starting with De. If we were to type</p> |
|
<pre class="inset">$Do</pre> |
|
<p>followed by tab, we would see that nothing happens because Linux is unable to determine whether we want to change to the Documents folder or the Downloads folder However, if we press tab a second time, we will see that Linux lists all possible options and then repeats the command so that we can complete it with one of the available directory names. This is shown in figure 2.</p> |
|
<figure> |
|
<img src=" images\figure2.png" alt="Figure 2 - an attempt to use tab autocomplete when there is ambiguity over the directory name selected"> |
|
<figcaption> Figure 2 - an attempt to use tab autocomplete when there is ambiguity over the directory name selected </figcaption> |
|
</figure> |
|
<p>You can also use tab autocomplete if you can’t quite remember the name of a command. For instance, if you type a followed by a tab, nothing happens. But if you press tab again, you will see a list of commands that start with an a.</p> |
|
<p>If you then press space followed by tab twice, you will see a list of possible arguments for the command a. Of course, a is not a genuine command so we are really seeing everything in the directory which Linux is presenting as possible arguments for the command. Since it doesn’t recognize the command, it cannot make a good decision about possible arguments and this is |
|
presumably why it shows us everything!</p> |
|
<p>If we need to edit a command in the terminal, we can use Control + A to move to the beginning of the line or control + E to move to the end of the line (note that in documentation, such shortcuts can be shown with a caret character representing the control character so control + A would be shown as |
|
<pre class="inset">^A</pre> |
|
<p>and similarly,</p> |
|
<pre class="inset">^E</pre> |
|
<p>represents control + E). A more complete list of shortcuts which was copied from <a href="https://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-suse-redhat-linux-etc/">https://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-suse-redhat-linux-etc/</a> is provided in appendix A.</p> |
|
<h2 class="sectiontitle">Finding Help for Commands</h2> |
|
<p>I mentioned the use of man with a command name previously to display a help file (actually, man is short for manual so we might call this a manual page) for a command such as ls. This actually displays the help info using a tool called less and when we are viewing this, we can press q to quit or h for help. In this case, help means help in navigating through a page displayed in less so it would be used for info on how to navigate around one of these manual (man) pages.</p> |
|
<p>Another way to find help for a specific command is to type the name of the command followed by –help. There is also a help command so you could try typing help followed by the name of the command although in many cases, this will simply refer you to the appropriate man page.</p> |
|
<p>So it is easy to help when you know the name of the command. However, if you don’t you can use the command apropos followed by some text relating to the command and this will search for something appropriate. For instance, let’s say we want to find out what commands are used for printing, we can type</p> |
|
<pre class="inset">$apropos print</pre> |
|
<p>or</p> |
|
<pre class="inset">$apropos cups</pre> |
|
<p>Both of which will list commands relevant to printing (cups being the Linux print server).</p> |
|
</article> |
|
|
|
<div class="btngroup"> |
|
<button class="button" onclick="window.location.href='environment.html';"> |
|
Previous Chapter - Setting Up Your Environment |
|
</button> |
|
<button class="button" onclick="window.location.href='files.html';"> |
|
Next Chapter - Files, Folders and Permissions |
|
</button> |
|
<button class="button" onclick="window.location.href='learninglinuxcommandline.html'"> |
|
Course Contents |
|
</button> |
|
<button class="button" onclick="window.location.href='/linux/linux.html'"> |
|
Linux Page |
|
</button> |
|
<button class="button" onclick="window.location.href='/index.html'"> |
|
Home |
|
</button> |
|
</div> |
|
</body> |
|
</html>
|
|
|