{"id":203,"date":"2018-09-29T06:55:00","date_gmt":"2018-09-28T22:55:00","guid":{"rendered":"https:\/\/yeslq.com\/201809203.html"},"modified":"2019-05-07T10:40:53","modified_gmt":"2019-05-07T02:40:53","slug":"the-linux-command-line-looking-around-2","status":"publish","type":"post","link":"https:\/\/yeslq.com\/?p=203","title":{"rendered":"The Linux Command Line&#8212;Looking Around"},"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<p><span style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">Looking Around<\/span><\/p>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\n<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nNow that you know how to move from working directory to working directory, we&#8217;re going to take a tour of your Linux system and, along the way, learn some things about what makes it tick. But before we begin, I have to teach you some tools that will come in handy during our adventure. These are:<\/div>\n<ul style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\n<li type=\"disk\"><a href=\"http:\/\/linuxcommand.org\/lc3_man_pages\/ls1.html\" style=\"color: #002740;\">ls<\/a>&nbsp;(list files and directories)<\/li>\n<li type=\"disk\"><a href=\"http:\/\/linuxcommand.org\/lc3_man_pages\/less1.html\" style=\"color: #002740;\">less<\/a>&nbsp;(view text files)<\/li>\n<li type=\"disk\"><a href=\"http:\/\/linuxcommand.org\/lc3_man_pages\/file1.html\" style=\"color: #002740;\">file<\/a>&nbsp;(classify a file&#8217;s contents)<\/li>\n<\/ul>\n<h2 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\">\n<span style=\"font-size: small;\">ls<\/span><\/h2>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nThe&nbsp;ls&nbsp;command is used to list the contents of a directory. It is probably the most commonly used Linux command. It can be used in a number of different ways. Here are some examples:<\/div>\n<table border=\"\" cellpadding=\"8\" style=\"background-color: white; color: black; font-family: verdana, arial, helvetica, sans-serif;\" summary=\"Table containing examples of the ls command.\">Examples of the ls command<\/p>\n<tbody>\n<tr>\n<th valign=\"top\" width=\"150\"><strong>Command<\/strong><\/th>\n<th><strong>Result<\/strong><\/th>\n<\/tr>\n<tr>\n<td>ls<\/td>\n<td valign=\"top\">List the files in the working directory<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"150\">ls \/bin<\/td>\n<td valign=\"top\">List the files in the \/bin directory (or any other directory you care to specify)<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"150\">ls -l<\/td>\n<td valign=\"top\">List the files in the working directory in long format<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"150\">ls -l \/etc \/bin<\/td>\n<td valign=\"top\">List the files in the \/bin directory and the \/etc directory in long format<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"150\">ls -la ..<\/td>\n<td valign=\"top\">List all files (even ones with names beginning with a period character, which are normally hidden) in the parent of the working directory in long format<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nThese examples also point out an important concept about commands. Most commands operate like this:<\/div>\n<pre style=\"background-color: white; font-family: courier, lucidatypewriter, monospace;\">    <i>command -options arguments<\/i>\n<\/pre>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nwhere&nbsp;<i>command<\/i>&nbsp;is the name of the command,&nbsp;<i>-options<\/i>&nbsp;is one or more adjustments to the command&#8217;s behavior, and&nbsp;<i>arguments<\/i>&nbsp;is one or more &#8220;things&#8221; upon which the command operates.<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nIn the case of&nbsp;ls, we see that&nbsp;ls&nbsp;is the name of the command, and that it can have one or more options, such as&nbsp;-a&nbsp;and&nbsp;-l, and it can operate on one or more files or directories.<\/div>\n<h3 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\n<span style=\"font-size: small;\">A Closer Look At Long Format<\/span><\/h3>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nIf you use the&nbsp;-l&nbsp;option with&nbsp;ls, you will get a file listing that contains a wealth of information about the files being listed. Here&#8217;s an example:<\/div>\n<pre style=\"background-color: white; font-family: courier, lucidatypewriter, monospace;\">\n-rw-------   1 bshotts  bshotts       576 Apr 17  1998 weather.txt\ndrwxr-xr-x   6 bshotts  bshotts      1024 Oct  9  1999 web_page\n-rw-rw-r--   1 bshotts  bshotts    276480 Feb 11 20:41 web_site.tar\n-rw-------   1 bshotts  bshotts      5743 Dec 16  1998 xmas_file.txt\n\n----------     -------  -------  -------- ------------ -------------\n    |             |        |         |         |             |\n    |             |        |         |         |         File Name\n    |             |        |         |         |\n    |             |        |         |         +---  Modification Time\n    |             |        |         |\n    |             |        |         +-------------   Size (in bytes)\n    |             |        |\n    |             |        +-----------------------        Group\n    |             |\n    |             +--------------------------------        Owner\n    |\n    +----------------------------------------------   File Permissions\n\n<\/pre>\n<p><strong>File Name<\/strong><br \/>\nThe name of the file or directory.<br \/>\n<strong>Modification Time<\/strong><br \/>\nThe last time the file was modified. If the last modification occurred more than six months in the past, the date and year are displayed. Otherwise, the time of day is shown.<br \/>\n<strong>Size<\/strong><br \/>\nThe size of the file in bytes.<br \/>\n<strong>Group<\/strong><br \/>\nThe name of the group that has file permissions in addition to the file&#8217;s owner.<br \/>\n<strong>Owner<\/strong><br \/>\nThe name of the user who owns the file.<br \/>\n<strong>File Permissions<\/strong><br \/>\nA representation of the file&#8217;s access permissions. The first character is the type of file. A &#8220;-&#8221; indicates a regular (ordinary) file. A &#8220;d&#8221; indicates a directory. The second set of three characters represent the read, write, and execution rights of the file&#8217;s owner. The next three represent the rights of the file&#8217;s group, and the final three represent the rights granted to everybody else. I&#8217;ll discuss this in more detail in a later lesson.<\/p>\n<h2 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\">\n<span style=\"font-size: small;\">less<\/span><\/h2>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nless&nbsp;is a program that lets you view text files. This is very handy since many of the files used to control and configure Linux are human readable.<\/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;\">What is &#8220;text&#8221;?<\/span><\/h2>\n<p>There are many ways to represent information on a computer. All methods involve defining a relationship between the information and some numbers that will be used to represent it. Computers, after all, only understand numbers and all data is converted to numeric representation.<br \/>\nSome of these representation systems are very complex (such as compressed multimedia files), while others are rather simple. One of the earliest and simplest is called&nbsp;<i>ASCII text<\/i>.&nbsp;<a href=\"http:\/\/linuxcommand.org\/lc3_man_pages\/ascii7.html\" style=\"color: #002740;\">ASCII<\/a>&nbsp;(pronounced &#8220;As-Key&#8221;) is short for American Standard Code for Information Interchange. This is a simple encoding scheme that was first used on Teletype machines to map keyboard characters to numbers.<br \/>\nText is a simple one-to-one mapping of characters to numbers. It is very compact. Fifty characters of text translates to fifty bytes of data. Throughout a Linux system, many files are stored in text format and there are many Linux tools that work with text files. Even the legacy operating systems recognize the importance of this format. The well-known NOTEPAD.EXE program is an editor for plain ASCII text files.<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nThe&nbsp;less&nbsp;program is invoked by simply typing:<\/div>\n<pre style=\"background-color: white; font-family: courier, lucidatypewriter, monospace;\">less <i>text_file<\/i>\n<\/pre>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nThis will display the file.<\/div>\n<h3 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\n<span style=\"font-size: small;\">Controlling less<\/span><\/h3>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nOnce started,&nbsp;less&nbsp;will display the text file one page at a time. You may use the Page Up and Page Down keys to move through the text file. To exit&nbsp;less, type &#8220;q&#8221;. Here are some commands that&nbsp;less&nbsp;will accept:<\/div>\n<table border=\"\" cellpadding=\"8\" style=\"background-color: white; color: black; font-family: verdana, arial, helvetica, sans-serif;\" summary=\"Table containing summary of keyboard commands for the less program.\">Keyboard commands for the less program<\/p>\n<tbody>\n<tr>\n<th valign=\"top\"><strong>Command<\/strong><\/th>\n<th valign=\"top\"><strong>Action<\/strong><\/th>\n<\/tr>\n<tr>\n<td valign=\"top\">Page Up or b<\/td>\n<td valign=\"top\">Scroll back one page<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Page Down or space<\/td>\n<td valign=\"top\">Scroll forward one page<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">G<\/td>\n<td valign=\"top\">Go to the end of the text file<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">1G<\/td>\n<td valign=\"top\">Go to the beginning of the text file<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/<i>characters<\/i><\/td>\n<td valign=\"top\">Search forward in the text file for an occurrence of the specified&nbsp;<i>characters<\/i><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">n<\/td>\n<td valign=\"top\">Repeat the previous search<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">h<\/td>\n<td valign=\"top\">Display a complete list less commands and options<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">q<\/td>\n<td valign=\"top\">Quit<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\">\n<span style=\"font-size: small;\">file<\/span><\/h2>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nAs you wander around your Linux system, it is helpful to determine what kind of data a file contains before you try to view it. This is where the&nbsp;file&nbsp;command comes in.&nbsp;file&nbsp;will examine a file and tell you what kind of file it is.<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nTo use the&nbsp;file&nbsp;program, just type:<\/div>\n<pre style=\"background-color: white; font-family: courier, lucidatypewriter, monospace;\">file <i>name_of_file<\/i>\n\n<\/pre>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nThe&nbsp;file&nbsp;program can recognize most types of files, such as:<\/div>\n<table border=\"\" cellpadding=\"8\" style=\"background-color: white; color: black; font-family: verdana, arial, helvetica, sans-serif;\" summary=\"Table describing various types of files.\">Various kinds of files<\/p>\n<tbody>\n<tr>\n<th valign=\"top\"><strong>File Type<\/strong><\/th>\n<th valign=\"top\"><strong>Description<\/strong><\/th>\n<th valign=\"top\"><strong>Viewable as text?<\/strong><\/th>\n<\/tr>\n<tr>\n<td valign=\"top\">ASCII text<\/td>\n<td valign=\"top\">The name says it all<\/td>\n<td valign=\"top\">yes<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Bourne-Again shell script text<\/td>\n<td valign=\"top\">A&nbsp;bash&nbsp;script<\/td>\n<td valign=\"top\">yes<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">ELF 32-bit LSB core file<\/td>\n<td valign=\"top\">A core dump file (a program will create this when it crashes)<\/td>\n<td valign=\"top\">no<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">ELF 32-bit LSB executable<\/td>\n<td valign=\"top\">An executable binary program<\/td>\n<td valign=\"top\">no<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">ELF 32-bit LSB shared object<\/td>\n<td valign=\"top\">A shared library<\/td>\n<td valign=\"top\">no<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">GNU tar archive<\/td>\n<td valign=\"top\">A tape archive file. A common way of storing groups of files.<\/td>\n<td valign=\"top\">no, use&nbsp;tar tvf&nbsp;to view listing.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">gzip compressed data<\/td>\n<td valign=\"top\">An archive compressed with&nbsp;gzip<\/td>\n<td valign=\"top\">no<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">HTML document text<\/td>\n<td valign=\"top\">A web page<\/td>\n<td valign=\"top\">yes<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">JPEG image data<\/td>\n<td valign=\"top\">A compressed JPEG image<\/td>\n<td valign=\"top\">no<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">PostScript document text<\/td>\n<td valign=\"top\">A PostScript file<\/td>\n<td valign=\"top\">yes<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">RPM<\/td>\n<td valign=\"top\">A Red Hat Package Manager archive<\/td>\n<td valign=\"top\">no, use&nbsp;rpm -q&nbsp;to examine contents.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Zip archive data<\/td>\n<td valign=\"top\">An archive compressed with&nbsp;zip<\/td>\n<td valign=\"top\">no<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\nWhile it may seem that most files cannot be viewed as text, you will be surprised how many can. This is especially true of the important configuration files. You will also notice during our adventure that many features of the operating system are controlled by shell scripts. In Linux, there are no secrets!<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Linux Command Line&nbsp;by William Shotts Looking A &#8230; <a title=\"The Linux Command Line&#8212;Looking Around\" class=\"read-more\" href=\"https:\/\/yeslq.com\/?p=203\" aria-label=\"\u9605\u8bfb The Linux Command Line&#8212;Looking Around\">\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-203","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\/203","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=203"}],"version-history":[{"count":1,"href":"https:\/\/yeslq.com\/index.php?rest_route=\/wp\/v2\/posts\/203\/revisions"}],"predecessor-version":[{"id":300,"href":"https:\/\/yeslq.com\/index.php?rest_route=\/wp\/v2\/posts\/203\/revisions\/300"}],"wp:attachment":[{"href":"https:\/\/yeslq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yeslq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yeslq.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}