{"id":204,"date":"2018-09-28T02:38:00","date_gmt":"2018-09-27T18:38:00","guid":{"rendered":"https:\/\/yeslq.com\/201809204.html"},"modified":"2019-05-07T10:40:51","modified_gmt":"2019-05-07T02:40:51","slug":"the-linux-command-line-navigation-2","status":"publish","type":"post","link":"https:\/\/yeslq.com\/?p=204","title":{"rendered":"The Linux Command Line&#8212;Navigation"},"content":{"rendered":"<h1 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\">\n<i style=\"font-size: x-small;\"><a href=\"http:\/\/linuxcommand.org\/tlcl.php\" style=\"color: #002740;\">The Linux Command Line&nbsp;<\/a><\/i><span style=\"font-size: xx-small;\">by William Shotts<\/span><\/h1>\n<h1 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\">\n<span style=\"font-size: small;\">Navigation<\/span><\/h1>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nIn this lesson, I will introduce your first three commands:&nbsp;<a href=\"http:\/\/linuxcommand.org\/lc3_man_pages\/pwdh.html\" style=\"color: #002740;\">pwd<\/a>&nbsp;(print working directory),&nbsp;<a href=\"http:\/\/linuxcommand.org\/lc3_man_pages\/cdh.html\" style=\"color: #002740;\">cd<\/a>&nbsp;(change directory), and&nbsp;<a href=\"http:\/\/linuxcommand.org\/lc3_man_pages\/ls1.html\" style=\"color: #002740;\">ls<\/a>&nbsp;(list files and directories).<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nIf you have not worked with a command line interface before, you will need to pay close attention to this lesson, since the concepts will take some getting used to.<\/div>\n<h2 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\">\n<span style=\"font-size: small;\">File System Organization<\/span><\/h2>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nLike that legacy operating system, the files on a Linux system are arranged in what is called a&nbsp;<i>hierarchical directory structure<\/i>. This means that they are organized in a tree-like pattern of&nbsp;<i>directories<\/i>&nbsp;(called folders in other systems), which may contain files and other directories. The first directory in the file system is called the&nbsp;<i>root directory<\/i>. The root directory contains files and subdirectories, which contain more files and subdirectories and so on and so on.<\/div>\n<div class=\"separator\" style=\"clear: both; text-align: center;\">\n<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nMost graphical environments today include a file manager program to view and manipulate the contents of the file system. Often you will see the file system represented like this:<br \/><a href=\"http:\/\/yeslq.com\/wp-content\/uploads\/2018\/09\/file_manager.jpg\" imageanchor=\"1\" style=\"font-family: &quot;Microsoft YaHei&quot;; margin-left: 1em; margin-right: 1em; text-align: center;\"><img decoding=\"async\" border=\"0\" data-original-height=\"287\" data-original-width=\"275\" src=\"http:\/\/yeslq.com\/wp-content\/uploads\/2018\/09\/file_manager.jpg\" \/><\/a><\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nOne important difference between the legacy operating system and Unix-like operating systems such as Linux is that Linux does not employ the concept of drive letters. While drive letters split the file system into a series of different trees (one for each drive), Linux always has a single tree. Different storage devices may contain different branches of the tree, but there is always a single tree.<\/div>\n<h2 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\">\n<span style=\"font-size: small;\">pwd<\/span><\/h2>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nSince a command line interface cannot provide graphic pictures of the file system structure, it must have a different way of representing it. Think of the file system tree as a maze, and you are standing in it. At any given moment, you are located in a single directory. Inside that directory, you can see its files and the pathway to its&nbsp;<i>parent directory<\/i>&nbsp;and the pathways to the subdirectories of the directory in which you are standing.<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nThe directory you are standing in is called the&nbsp;<i>working directory<\/i>. To find the name of the working directory, use the&nbsp;pwd&nbsp;command.<\/div>\n<div class=\"display\" style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\">\n[me@linuxbox me]$&nbsp;pwd<br \/>\/home\/me<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nWhen you first log on to a Linux system, the working directory is set to your&nbsp;<i>home directory<\/i>. This is where you put your files. On most systems, your home directory will be called \/home\/your_user_name, but it can be anything according to the whims of the system administrator.<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nTo list the files in the working directory, use the&nbsp;ls&nbsp;command.<\/div>\n<div class=\"display\" style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\">\n<pre style=\"font-family: courier, lucidatypewriter, monospace;\">[me@linuxbox me]$ ls\nDesktop     Xrootenv.0    linuxcmd\nGNUstep     bin           nedit.rpm\nGUILG00.GZ  hitni123.jpg  nsmail\n<\/pre>\n<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nI will come back to&nbsp;ls&nbsp;in the next lesson. There are a lot of fun things you can do with it, but I have to talk about pathnames and directories a bit first.<\/div>\n<h2 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\">\n<span style=\"font-size: small;\">cd<\/span><\/h2>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nTo change your working directory (where you are standing in the maze) you use the&nbsp;cd&nbsp;command. To do this, type&nbsp;cd&nbsp;followed by the&nbsp;<i>pathname<\/i>&nbsp;of the desired working directory. A pathname is the route you take along the branches of the tree to get to the directory you want. Pathnames can be specified in one of two different ways;&nbsp;<i>absolute pathnames<\/i>&nbsp;or&nbsp;<i>relative pathnames<\/i>. Let&#8217;s look with absolute pathnames first.<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nAn absolute pathname begins with the root directory and follows the tree branch by branch until the path to the desired directory or file is completed. For example, there is a directory on your system in which most programs are installed. The pathname of the directory is \/usr\/bin. This means from the root directory (represented by the leading slash in the pathname) there is a directory called &#8220;usr&#8221; which contains a directory called &#8220;bin&#8221;.<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nLet&#8217;s try this out:<\/div>\n<div class=\"display\" style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\">\n<pre style=\"font-family: courier, lucidatypewriter, monospace;\">[me@linuxbox me]$ cd \/usr\/bin\n[me@linuxbox bin]$ pwd\n\/usr\/bin\n[me@linuxbox bin]$ ls\n[                     lwp-request\n2to3                  lwp-rget\n2to3-2.6              lxterm\na2p                   lz\naalib-config          lzcat\naconnect              lzma\nacpi_fakekey          lzmadec\nacpi_listen           lzmainfo\nadd-apt-repository    m17n-db\naddpart               magnifier\n\nand many more...\n<\/pre>\n<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nNow we can see that we have changed the current working directory to \/usr\/bin and that it is full of files. Notice how your prompt has changed? As a convenience, it is usually set up to display the name of the working directory.<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nWhere an absolute pathname starts from the root directory and leads to its destination, a relative pathname starts from the working directory. To do this, it uses a couple of special notations to represent relative positions in the file system tree. These special notations are &#8220;.&#8221; (dot) and &#8220;..&#8221; (dot dot).<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nThe &#8220;.&#8221; notation refers to the working directory itself and the &#8220;..&#8221; notation refers to the working directory&#8217;s parent directory. Here is how it works. Let&#8217;s change the working directory to \/usr\/bin again:<\/div>\n<div class=\"display\" style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\">\n[me@linuxbox me]$&nbsp;cd \/usr\/bin<br \/>[me@linuxbox bin]$&nbsp;pwd<br \/>\/usr\/bin<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nO.K., now let&#8217;s say that we wanted to change the working directory to the parent of \/usr\/bin which is \/usr. We could do that two different ways. First, with an absolute pathname:<\/div>\n<div class=\"display\" style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\">\n[me@linuxbox bin]$&nbsp;cd \/usr<br \/>[me@linuxbox usr]$&nbsp;pwd<br \/>\/usr<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nOr, with a relative pathname:<\/div>\n<div class=\"display\" style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\">\n[me@linuxbox bin]$&nbsp;cd ..<br \/>[me@linuxbox usr]$&nbsp;pwd<br \/>\/usr<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nTwo different methods with identical results. Which one should you use? The one that requires the least typing!<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nLikewise, we can change the working directory from \/usr to \/usr\/bin in two different ways. First using an absolute pathname:<\/div>\n<div class=\"display\" style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\">\n[me@linuxbox usr]$&nbsp;cd \/usr\/bin<br \/>[me@linuxbox bin]$&nbsp;pwd<br \/>\/usr\/bin<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nOr, with a relative pathname:<\/div>\n<div class=\"display\" style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\">\n[me@linuxbox usr]$&nbsp;cd .\/bin<br \/>[me@linuxbox bin]$&nbsp;pwd<br \/>\/usr\/bin<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nNow, there is something important that I must point out here. In almost all cases, you can omit the &#8220;.\/&#8221;. It is implied. Typing:<\/div>\n<div class=\"display\" style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\">\n[me@linuxbox usr]$&nbsp;cd bin<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nwould do the same thing. In general, if you do not specify a pathname to something, the working directory will be assumed. There is one important exception to this, but we won&#8217;t get to that for a while.<\/div>\n<h2 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\">\n<span style=\"font-size: small;\">A Few Shortcuts<\/span><\/h2>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nIf you type&nbsp;cd&nbsp;followed by nothing,&nbsp;cd&nbsp;will change the working directory to your home directory.<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nA related shortcut is to type&nbsp;cd ~<i>user_name<\/i>. In this case,&nbsp;cd&nbsp;will change the working directory to the home directory of the specified user.<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nTyping&nbsp;cd &#8211;&nbsp;changes the working directory to the previous one.<\/div>\n<div class=\"sidebar\" style=\"background-color: #e0e0e0; font-family: verdana, arial, helvetica, sans-serif; padding: 1em;\">\n<h2 style=\"font-weight: normal;\">\n<span style=\"font-size: small;\">Important facts about file names<\/span><\/h2>\n<ol>\n<li>File names that begin with a period character are hidden. This only means that&nbsp;ls&nbsp;will not list them unless you say&nbsp;ls -a. When your account was created, several hidden files were placed in your home directory to configure things for your account. Later on we will take a closer look at some of these files to see how you can customize your&nbsp;<i>environment<\/i>. In addition, some applications will place their configuration and settings files in your home directory as hidden files.<\/li>\n<li>File names in Linux, like Unix, are case sensitive. The file names &#8220;File1&#8221; and &#8220;file1&#8221; refer to different files.<\/li>\n<li>Linux has no concept of a &#8220;file extension&#8221; like legacy operating systems. You may name files any way you like. However, while Linux itself does not care about file extensions, many application programs do.<\/li>\n<li>Though Linux supports long file names which may contain embedded spaces and punctuation characters, limit the punctuation characters to period, dash, and underscore.&nbsp;<strong>Most importantly, do not embed spaces in file names.<\/strong>&nbsp;If you want to represent spaces between words in a file name, use underscore characters. You will thank yourself later.<\/li>\n<\/ol>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Linux Command Line&nbsp;by William Shotts Navigatio &#8230; <a title=\"The Linux Command Line&#8212;Navigation\" class=\"read-more\" href=\"https:\/\/yeslq.com\/?p=204\" aria-label=\"\u9605\u8bfb The Linux Command Line&#8212;Navigation\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[51,52,53],"class_list":["post-204","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-linux","tag-shell","tag-the-linux-command-line"],"_links":{"self":[{"href":"https:\/\/yeslq.com\/index.php?rest_route=\/wp\/v2\/posts\/204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yeslq.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yeslq.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yeslq.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yeslq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=204"}],"version-history":[{"count":1,"href":"https:\/\/yeslq.com\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":299,"href":"https:\/\/yeslq.com\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions\/299"}],"wp:attachment":[{"href":"https:\/\/yeslq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yeslq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yeslq.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}