{"id":182,"date":"2020-08-18T19:23:47","date_gmt":"2020-08-18T20:23:47","guid":{"rendered":"http:\/\/www.linux-tutorial.info\/?page_id=77"},"modified":"2020-08-22T19:26:40","modified_gmt":"2020-08-22T20:26:40","slug":"this-is-the-page-title-toplevel-16","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=182","title":{"rendered":"The Shell"},"content":{"rendered":"\n<title>The Shell<\/title>\n<concept id=\"\" description=\"The shell is an user's interface to the operating system.\" \/>\n<p>\nAs I mentioned in the section on introduction to operating systems, the shell\nis essentially a user&#8217;s interface to the <glossary>operating system<\/glossary>.\nThe <glossary>shell<\/glossary> is a\ncommand line interpreter, just like other operating systems. In Windows you\nopen up a &#8220;command window&#8221; or &#8220;DOS box&#8221; to input commands, which is nothing other\nthan a <glossary>command line<\/glossary> interpreter. Through it, you issue commands that are\ninterpreted by the system to carry out certain actions. Often, the state where\nthe system is sitting at a prompt, waiting for you to type input, is referred to\n(among other things) as being at the <glossary>shell<\/glossary>\nprompt or at the <glossary>command line<\/glossary>.\n<\/p>\n<p>\nFor many\nyears before the invention of graphical user interfaces, such as X-Windows (the\nX Windowing System, for purists), the only way to input commands to the\noperating system was through a <glossary>command line<\/glossary>\ninterpreter, or <glossary>shell<\/glossary>. In fact,\nshells themselves were thought of as wondrous things during the early days of\ncomputers because prior to them, users had no direct way to interact with the\noperating system.\n<\/p>\n<concept id=\"\" description=\"Most shells have the same basic input characteristics.\" \/>\n<p>\nMost shells, be they under <glossary>DOS<\/glossary>, <glossary>UNIX<\/glossary>,\n VMS, or other\noperating systems, have the same input characteristics. To get the operating\nsystem to do anything, you must give it a command. Some commands, such as the\ndate command under <glossary>UNIX<\/glossary>,\n do not require anything else to get them to work. If\nyou type in date and press Enter, that&#8217;s what appears on your screen: the date.\n<\/p>\n<concept id=\"\" description=\"Some commands only work with a single argument, whiles other require multiple arguments.\" \/>\n<p>\nSome commands need something else to get them to work: an\n<em>argument<\/em>. Some commands, like <command>mkdir<\/command> (used to create directories), work\nwith only one <glossary>argument<\/glossary>,\n as in mkdir directory_name. Others, like <command>cp<\/command> (to copy\nfiles), require multiple arguments, as in\n<p>\n<commandexample command=\"cp\">cp file1 file2<\/commandexample>\n<\/p>\n<concept id=\"\" description=\"Flags to commands that change their behaviour are commonly referred to as options.\" \/>\n<question id=\"\" type=\"MC\" text=\"What is the term commonly used to refered to flags that change a commnd's behaviour.\" \/>\n<p>\nIn many cases,\nyou can pass flags to commands to change their behavior. These flags are\ngenerally referred to as <em>options<\/em>. For example, if you wanted to create\na series of sub-directories without creating every one individually, you could\nrun <command>mkdir<\/command> with the <keyinput>-p<keyinput> option, like this:\n<\/p>\n<p>\n<commandexample command=\"mkdir\">mkdir -p one\/two\/three\/four<\/commandexample>\n<\/p>\n<concept id=\"\" description=\"By convention is it said that options change a command's behavior and arguments are acted upon.\" \/>\n<question id=\"\" type=\"MC\" text=\"What is the common convention use to differentiate between an option and and arguement.\" \/>\n<p>\nIn principle, anything added to the <glossary>command line<\/glossary>\nafter the command itself is an <glossary>argument<\/glossary>\nto that command. The convention is that an\noption changes the behavior, whereas an <glossary>argument<\/glossary>\nis acted upon by the command. Let&#8217;s take the <command>mkdir<\/command> command as an example:\n<\/p>\n<p>\n<commandexample command=\"mkdir\">mkdir dir_name<\/commandexample>\n<\/p>\n<p>\nHere we have a single argument which is the name of the directory to be created. Next,\nwe add an option:\n<\/p>\n<p>\n<commandexample command=\"mkdir\">mkdir  -p sub_dir\/dir_name<\/commandexample>\n<\/p>\n<p>\nThe <keyinput>-p<\/keyinput> is an option. Using the terminology discussed above, some\narguments are optional and some options are required. That is, with some commands you must always\nhave an option, such as the <command>tar<\/command> command. Some commands don&#8217;t always\nneed to have an argument, like the <command>date<\/command> command.\n<\/p>\n<concept id=\"\" description=\"Generally, options are preceded by a dash (-), whereas arguments are not.\" \/>\n<p>\nGenerally, options are preceded by a dash (-), whereas arguments are not. I&#8217;ve\nsaid it before and I will say it again, nothing is certain when it comes to\nLinux or <glossary>UNIX<\/glossary>,  in general. By realizing that these two terms are often\ninterchanged, you won&#8217;t get confused when you come across one or the other. I\nwill continue to use <i>option<\/i> to reflect something that changes the\ncommand&#8217;s behavior and <i>argument <\/i>to indicate something that is acted\nupon.\nIn some places, you will also see arguments referred to as &#8220;operands&#8221;. An operand is\nsimply something on which the shell &#8220;operates&#8221;, such as a file, directory or maybe even\nsimple text.\n<\/p>\n<p>\nEach program or utility has its own set of arguments and options,\nso you will have to look at the man-pages for the individual commands. You can\ncall these up from the <glossary>command line<\/glossary>\nby typing in\n<\/p>\n<p>\n<commandexample command=\"man\">man &lt;command_name&gt;<\/commandexample>\n<\/p>\n<p>\nwhere &lt;command_name&gt; is the name of the\ncommand you want information about. Also, if you are not sure what the command\nis, many Linux versions have the whatis command that will give you a brief\ndescription. There is also the <command>apropos<\/command> command, which searches through the\nman-pages for words you give as arguments. Therefore, if you don&#8217;t know the name\nof the command, you can still find it.\n<\/p>\n<p>\nArguments (whether they are options or operands) which are\nenclosed in square brackets ([ ]) are optional.  In some cases, there are optional components\nto the optional arguments, so you may end up having brackets within brackets.\n<\/p>\n<p>\nAn ellipsis (&#8230;) Indicates that the preceding arguments can be repeated.  For example, the ls\ncommand can take multiple file or directory names as arguments as well as multiple options.\nTherefore, you might have a usage message that looks like this:<\/p>\n<p>\n<commandexample command=\"ls\">ls [OPTION] &#8230; [FILE] &#8230;<\/commandexample>\n<\/p>\n<p>\nThis tells us that no options are required, but if you wanted you could use multiple options.  It\nalso tells us that no file name is required, but if you wanted you could use multiple ones.\n<\/p>\n<p>\nWords that appeared in angle brackets (&lt; &gt;) or possibly in italics in the printed form, indicate\nthat the word is a place holder.  Like in the example below:<\/p>\n<p>\n<commandexample command=\"man\">man &lt;filename&gt;<\/commandexample>\n<\/p>\n<p>\nMany commands require that an\noption appear immediately after the command and before any arguments. Others\nhave options and arguments interspersed. Again, look at the <glossary>man-page<\/glossary>\nfor the specifics of a particular command.\n<\/p>\n<concept id=\"\" description=\"You can option get information about a command by using the --help option.\" \/>\n<concept id=\"\" description=\"When an option is not recognized, most commands will typically present you with a usage\nmessage.\" \/>\n<p>\nOften, you just need a quick reminder\nas to what the available options are and what their syntax is. Rather than going\nthrough the hassle of calling up the <glossary>man-page<\/glossary>,\na quick way is to get the command to give you a <em>usage message<\/em>. As its\nname implies, a usage message\nreports the usage of a particular command. I normally use <keyinput>-?<keyinput> as the option to\nforce the usage message, as I cannot think of a command where <keyinput>-?<keyinput> is a valid\noption. Your system may also support the <keyinput>&#8211;help<keyinput> (two dashes) option. More\nrecent versions of the various commands will typically give you a usage\nmessage if you use the wrong option.\nNote that fewer and fewer commands support the <keyinput>-?<keyinput>.\n<\/p>\n<concept id=\"\" description=\"To make things easier, the letter used for a particular option is often related to the function it\nserves.\" \/>\n<p>\nTo make things easier, the letter used for a particular option is often related to the function it\nserves.  For example, the <keyinput>-a<keyinput> option to <command>ls<\/command>  says to list\n&#8220;all&#8221; files, even those that are\n&#8220;hidden&#8221;. On older versions of both Linux and Unix, options typically consisted of a single\nletter, often both upper and lowercase letters.  Although this meant you could have 52\ndifferent options it made remembering them difficult, if they were multiple functions that all\nbegan with the same letter. This means that in a number of cases, the developers had to make a decision\nas to which letter stood for which option.\n<\/p>\n<p>\nTo make things easier, when using the short options, multiple options can either be placed separately,\neach preceded by a dash, or combined. For example, both of these commands are valid and have\nthe exact same effect:\n<\/p>\n<p>\n<commandexample command=\"ls\">ls -a -l<\/commandexample>\n<\/p>\n<p>\n<commandexample command=\"ls\">ls -al<\/commandexample>\n<\/p>\n<p>\nIn both cases you get a long listing (<keyinput>-l<keyinput>) which also included\nall of the hidden files (<keyinput>-a<keyinput>).\n<\/p>\n<p>\nNewer versions of commands typically allow for <b>both<\/b> single letter options and\n&#8220;long options&#8221; which use full words.  For\nexample, the long equivalent of <keyinput>-a<keyinput> would be <keyinput>&#8211;all<keyinput>.\nNote that the long options are preceded\nwith <i>two<\/i> dashes because it would otherwise be indistinguishable\nfrom the <keyinput>-a<keyinput> followed by two <keyinput>-l<keyinput> options.\n<\/p>\n<p>\nNote that saying &#8220;newer&#8221; might be somewhat confusing. As of this writing (Dec 2006),\nI cannot think of any current distribution which has no commands that support long options.\nTherefore it would probably better to say, that with <i>older<i> distribution you\n<i>may<i> find that long options are not supported.\n<\/p>\n<p>\nAlthough it doesn&#8217;t happen too often, you might end up with a situation where one of the\narguments to your command starts with a  dash (-), for example a file name. This &#8220;normally&#8221;\ndoesn&#8217;t happen, but you can run into problems if it does. Since options\ntypically start with a dash, the shell cannot figure out that it is an argument and not\na long line of options. Let&#8217;s assume that some application created a file\nnamed &#8220;<file type=\"\">-jim<\/file>&#8220;. If I wanted to do a simple listing of the file, I might try this:\n<p>\n<commandexample command=\"ls\">ls -jim<\/commandexample>\n<p>\nHowever, since the shell first tries to figure out what options are being used before it shows you the listing,\nit thinks that these are all options and gives you the error message:\n<\/p>\n<p>\n<screenoutput>\nls: invalid option &#8212; j\nTry `ls &#8211;help&#8217; for more information.\n<\/screenoutput>\n<\/p>\n<concept id=\"\" description=\"If an argument to a command starts with a dash, you can use a double dash to prevent the shell from trying to interpret it as an option.\" \/>\n<p>\nYou can solve this problem with <i>some<\/i> commands by using two dashes to tell the command that\nwhat follows is actually an argument. So to get the listing in the previous example, the command\nmight look like this:\n<\/p>\n<p>\n<commandexample command=\"l\">ls &#8212; -jim<\/commandexample>\n<\/p>\n<p>\nA frequently overlook aspect of working with the shell are resource limitations, which can prevent problems for improperly implemented programs.\nOne example, is the maximim number of files that a shell can have open at one time. This usually defaults to 1024, which can seem like a lot, but I have\nrun across applications were where even this was too few.  To see the currently set values, simply run <commandexample command=\"ulimit\">ulimit -a<\/commandexample>,\nwhich might show you something like this:\n<\/p>\n<p>\n<screenoutput>\ncore file size          (blocks, -c) 0\ndata seg size           (kbytes, -d) unlimited\nfile size               (blocks, -f) unlimited\npending signals                 (-i) 1024\nmax locked memory       (kbytes, -l) 32\nmax memory size         (kbytes, -m) unlimited\nopen files                      (-n) 1024\npipe size            (512 bytes, -p) 8\nPOSIX message queues     (bytes, -q) 819200\nstack size              (kbytes, -s) 10240\ncpu time               (seconds, -t) unlimited\nmax user processes              (-u) 4096\nvirtual memory          (kbytes, -v) unlimited\nfile locks                      (-x) unlimited\n<\/screenoutput>\n<\/p>\n<p>\nOne important aspect is that each of these values has both a <glossary>soft limit<\/glossary> and a <glossary>hard limit<\/glossary>.\nA user can decreate the soft limit, as well as adjust the respective soft limit up to the respective hard limit. To go beyond the hard limit,\nthe root must make changes to the file <file>\/etc\/security\/limits.conf<\/file>.\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Shell As I mentioned in the section on introduction to operating systems, the shell is essentially a user&#8217;s interface to the operating system. The shell is a command line interpreter, just like other operating systems. In Windows you open &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=182\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-182","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=182"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/182\/revisions"}],"predecessor-version":[{"id":756,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/182\/revisions\/756"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}