{"id":763,"date":"2015-08-16T23:17:46","date_gmt":"2015-08-16T23:17:46","guid":{"rendered":"https:\/\/www.eskimo.com\/support\/?page_id=763"},"modified":"2023-12-07T23:59:44","modified_gmt":"2023-12-08T07:59:44","slug":"old-school-cli","status":"publish","type":"page","link":"https:\/\/www.eskimo.com\/support\/using-linux\/old-school-cli\/","title":{"rendered":"Old School CLI"},"content":{"rendered":"<p style=\"text-align: center;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 20pt; color: #008000;\">Using Linux<br \/>\nOld School Command Line Interface<\/span><\/p>\n<p style=\"text-align: left;\"><strong><span style=\"font-family: arial,helvetica,sans-serif; font-size: 14pt;\">Derivation of Various Shells (Command Line Interpreters)<\/span><\/strong><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Before Linux there was Unix.\u00a0 Unix was a multi-tasking multi-user operating system created at Bell Labs, originally to share the resources of a PDP-7.\u00a0 In those days, computers didn&#8217;t have the horsepower or graphics hardware to support a graphical interface so things were done using a command line interface.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The shell or command line interpreter is still widely used today because of it&#8217;s ability to connect various tools together and perform scripted operations.\u00a0 Most graphical programs are more monolithic and quite different in their approach to solving problems.\u00a0 It is best to be familiar with and fluent in both environments as both have advantages and disadvantages.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 AT&amp;T licensed Unix to Berkeley, University of Southern California, and from there a variant known as BSD emerged.\u00a0 The AT&amp;T product by this point was known as System-V, and almost every other version of Unix derived from one of these two.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The original AT&amp;T Unix used an interpreter which ran on Version 7 (which oddly enough predated System V) was developed by Stephen Bourne at Bell Labs and is referred to as the Bourne Shell, \/bin\/sh.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Bill Joy (of Sun Microsystems fame) and others at Berkeley developed an alternative shell called C-shell or csh, \/bin\/csh or Tenex, Total, or Terrible C-Shell (depending upon whom you ask), \/bin\/tcsh a superset of csh.\u00a0 This shell added features like job control, command line history, and aliases.\u00a0 However, it featured an entirely different syntax and as a result could not run scripts written for the Bourne shell.\u00a0 Today most Linux systems use a derivative of Bourne shell canned Born Again Shell, or Bash. Some Debian derived systems use Dash shell, Debian Almquist shell, \/bin\/dash, which is a super-set of Bash which itself is a superset of sh,<br \/>\n<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Linux code is not derived from Unix but the functionality of Linux is essentially identical. Modern commercial Unixes owe a lot of their newer enhancements to Linux.\u00a0 Most notably a Linux streamlined system call interface significantly improved performance over the older Unix method and now has been incorporated into Unix as well. While this article focuses on Linux, most of what is written here will perform identically on Unix systems.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The instructions I am providing here assume a Bourne shell derivative though most will also work with csh and tcsh as what I am describing are simple commands that don&#8217;t invoke the greater complexities of these shells.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Bourne shell derivatives include the Almquist shell or ash, which primarily was written to provide Bourne shell functionality without an AT&amp;T license, the Bourne Again Shell, or bash, the Debian Almquist shell or dash, the Korn shell or ksh which was written by David Korn while at Bell Labs, the pdksh which is a semi-functional public domain version of ksh, MirBSD shell mksh which is descended from the original ksh and pdksh, and Zsh which is backwards compatible with bash, which in turn is backwards compatible with sh.\u00a0 We have most if not all of these shells available for your use and what is shown in the following examples should work with any of these.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Because these shells are supersets of the original Bourne shell, often a link from \/bin\/sh to one of these shells, most frequently bash and dash, is provided on Linux systems, If you pull up a man page for sh, you will frequently get a man page for bash or dash depending on whether the system is Redhat or Debian based.\u00a0 Likewise, because tcsh is a superset of csh, often you will find csh is a link to tcsh on Linux systems and the man page for csh will refer to tcsh.<br \/>\n<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Derivatives of the C-shell, csh, include tcsh (which I&#8217;ve heard referred to as the Tenex C Shell, Total C Shell, and Terrible C Shell, I&#8217;ll leave it to you to determine which fits best), and something called the Hamilton C Shell, to which I&#8217;ve never been exposed.\u00a0 If you are familiar enough with the csh or tcsh to be using them then you probably don&#8217;t need this article so I won&#8217;t be covering them here.<\/span><\/p>\n<p style=\"text-align: left;\"><strong><span style=\"font-family: arial,helvetica,sans-serif; font-size: 14pt;\">\u00a0Terminal Window Command Prompt<\/span><\/strong><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Windows 10 and 11 have ssh built in.\u00a0 These features are not enabled by default so you have to enable them before first use.\u00a0 Once enabled, ssh will work either in command prompt or power shell.\u00a0 I recommend power shell because it will honor either windows commands like dir, or Linux commands like ls, allowing you to use whichever you prefer.\u00a0\u00a0 Older windows systems require putty. <a href=\"http:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/download.html\">Putty<\/a> provides a terminal window and an ssh connection to a remote host such as one of our shell servers.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 When you connect from either a Mac OS X based machine or Linux, you will typically open a terminal window and then use ssh to connect to a remote host by typing &#8220;<strong>ssh login@hostname<\/strong>&#8220;, for example I would connect to ubuntu by typing &#8220;<strong>ssh nanook@ubuntu.eskimo.com<\/strong>&#8220;. <strong>You can find a complete list of shell servers at<\/strong> <a href=\"https:\/\/www.eskimo.com\/services\/shells\/servers\/\">https:\/\/www.eskimo.com\/services\/shells\/servers\/<\/a>. I would then get a password prompt and enter my password unless I had setup public key authentication.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Here is an example of a terminal window which is connected to shellx via ssh and configured for the default command prompt.<\/span><\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/terminal.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-816\" src=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/terminal.jpg\" alt=\"terminal\" width=\"489\" height=\"326\" srcset=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/terminal.jpg 489w, https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/terminal-300x200.jpg 300w, https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/terminal-450x300.jpg 450w\" sizes=\"auto, (max-width: 489px) 100vw, 489px\" \/><\/a><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\"> \u00a0\u00a0\u00a0 The default primary command prompt for Bourne shell derived shells is &#8220;$ &#8220;.\u00a0 The default secondary prompt is &#8220;&gt; &#8220;.\u00a0 However, most of our servers have a default login script that changes the primary command prompt to: <span style=\"color: #800000;\">&#8220;user<\/span>@<span style=\"color: #003300;\">server<\/span>:<span style=\"color: #0000ff;\">current working directory<\/span>$.<br \/>\n<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The primary prompt is the prompt you receive when the shell is ready <span style=\"color: #0000ff;\">to<\/span> receive a command.\u00a0 The secondary prompt is a prompt you receive when more input is needed to complete the command.<\/span><\/p>\n<p style=\"text-align: left;\"><strong>\u00a0<span style=\"font-family: arial,helvetica,sans-serif; font-size: 14pt;\">Shell Variables, Environmental Variables<\/span><\/strong><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The shell isn&#8217;t only an interactive command line interpreter.\u00a0 It can also take input from a file or pipe.\u00a0 The shell is a complete programming language with variables, mathematical operators, comparison operators, conditional branching, loop constructs, meta-evaluation, and more.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The command prompts I just mentioned, these are not fixed.\u00a0 Those are only the defaults and they are actually two variables, <strong>PS1<\/strong> is the primary command prompt and <strong>PS2<\/strong> is the secondary command prompt.\u00a0 When you read these variables they are prefixed with a $, but when you set them or export them the $ prefix is not included.\u00a0 Also, until exported, these variables are available only inside the shell in which they are set, but once exported they become part of the environment available to any program that you run from the shell.<\/span><\/p>\n<p style=\"text-align: left;\">\u00a0\u00a0\u00a0\u00a0 For example:<\/p>\n<pre><code>STUFF=\"Hello, World!\"\r\necho $STUFF<\/code><\/pre>\n<p>Would result in:<\/p>\n<pre>Hello, World!<\/pre>\n<p><a href=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/hello-world.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-821\" src=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/hello-world.jpg\" alt=\"hello-world\" width=\"488\" height=\"326\" srcset=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/hello-world.jpg 488w, https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/hello-world-300x200.jpg 300w, https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/hello-world-449x300.jpg 449w\" sizes=\"auto, (max-width: 488px) 100vw, 488px\" \/><\/a><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 One hand feature of a shell is the ability to set a variable to the output of a program. Often times people use multiple hosts and work in different directories.\u00a0 To help them keep track of where they are they will set their primary prompt to include the hostname and current working directory.\u00a0 To include the output of a program in an environmental variable, include the program name in backticks like so:<\/span><\/p>\n<pre>VARIABLE=\"`program`\"<\/pre>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 For example:<\/span><\/p>\n<p><a href=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/backticks.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-823\" src=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/backticks.jpg\" alt=\"backticks\" width=\"489\" height=\"326\" srcset=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/backticks.jpg 489w, https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/backticks-300x200.jpg 300w, https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/backticks-450x300.jpg 450w\" sizes=\"auto, (max-width: 489px) 100vw, 489px\" \/><\/a><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\"> \u00a0\u00a0\u00a0 In this example, I set the environmental variable PS1, which is my primary prompt, to equal the output of hostname followed by a colon, then the output of pwd which prints the current working directory, followed by a space and then a greater than &#8220;&gt;&#8221; symbol.\u00a0 You can see that my prompt became &#8220;shellx.eskimo.com:\/home\/nanook &gt;&#8221; as a result, but if I was on a different hostname or changed to a different directory, that would be reflected in the prompt such that I would always know where I was. <strong>BTW: shellx is no longer a valid server name here, see <\/strong><a href=\"https:\/\/www.eskimo.com\/services\/shells\/servers\/\">https:\/\/www.eskimo.com\/services\/shells\/servers\/<\/a><strong> for a current list of valid servers.<\/strong><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 There are start-up scripts that a shell always runs at start-up if it is a login shell, and there are scripts that it runs every time whether it is a login shell or not.\u00a0 The default startup script for sh is &#8220;.profile&#8221; and for bash, &#8220;.bash_profile&#8221;.\u00a0 The per instance script that is read for every interactive bash shell is &#8220;.bashrc&#8221;.\u00a0 When bash is invoked as &#8220;sh&#8221;, it will read &#8220;.profile&#8221; rather than &#8220;.bash_profile&#8221;.\u00a0 These scripts are typically used to do things like setting your environmental variables such as PS1 and PS1 and exporting them.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 There is a system wide start-up script read by all Bourne shell derived shells called \/etc\/profile that sets system wide defaults.\u00a0 Because it is read before your personal &#8220;.profile&#8221;, you can override these settings.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Variables that you do not export are not available to programs you invoke except if they are exported by the system wide start up scripts or your start up script.<\/span><\/p>\n<p><strong><span style=\"font-family: arial,helvetica,sans-serif; font-size: 14pt;\">Input \/ Output Redirection and Pipes<\/span><\/strong><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 There are three descriptors associated with an interactive shell and any programs you start from that shell.\u00a0 File descriptor 0, also referred to as stdin, is normally attached to your keyboard.\u00a0 That is whatever you type, is fed to the program which it can read from file descriptor 0, or stdin.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 File descriptor 1 is stdout.\u00a0 This is normally fed back to your display as normal non-error output. File descriptor 2 is stderr.\u00a0 It also is normally fed back to your display but contains only error output.\u00a0 Having error output go to a different descriptor allows you to process errors differently than normal output.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 It is possible to redirect the input of a program, including the shell itself to take input from a file or another device rather than your keyboard.\u00a0 In Linux, every device except for the ethernet controller, is represented by a device.\u00a0 In other Unix systems the ethernet is also represented by a device.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 One common device is called a data sink and it is \/dev\/null.\u00a0 Any data redirected to this device goes into a black hole never to be seen again.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Let&#8217;s say you are going to compile a large program and the make process generates a huge amount of useless noise.\u00a0 You are only interested in any errors that may occur.\u00a0 You could do this:<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">make program &gt; make.out 2&gt; make.err &amp;<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The &#8216;&amp;&#8217; tells the shell to run the command in the background so you can go do other things while it&#8217;s running.\u00a0 The &#8216;&gt;&#8217; symbol without a number redirects stdout, in this case to a file named &#8220;make.out&#8221;.\u00a0 The &#8216;&gt;&#8217; symbol proceeded by a number redirects that file descriptor.\u00a0 So in this case you are redirecting stderr (error output) to a file named make.err.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 It is possible to append to an existing file rather than creating a new file or overwriting an existing one by using the &#8216;&gt;&gt;&#8217; redirection symbol in place of &#8216;&gt;&#8217;.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 When the process completes you can examine these files to check if the process completed normally and if not what errors occurred.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0\u00a0 One very useful feature of Unix and Linux are pipes.\u00a0 Pipes allow you take the output of one program and chain it into another.\u00a0 For example, if you wanted to know how many files are in your directory you could type:<\/span><\/p>\n<pre><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">ls -a | wc -l<\/span><\/pre>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The program &#8220;ls&#8221; lists directory entries one per line.\u00a0 The &#8216;-a&#8217; says to also list files that begin with a &#8216;.&#8217;, otherwise they are hidden from view.\u00a0 The program &#8220;wc&#8221; is word count, counts words by default, but with the &#8216;-l&#8217; it counts lines instead.\u00a0 So by piping ls -a into wc -l, you get a count of all of the files in your directory.\u00a0 This is a trivial example of what you can do with a pipe.<\/span><\/p>\n<p><strong><span style=\"font-family: arial,helvetica,sans-serif; font-size: 14pt;\">Three Very Important Commands<\/span><\/strong><\/p>\n<dl>\n<dt><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">apropos<\/span><\/dt>\n<dd><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">Apropos is used like this, &#8220;apropos topic&#8221;. It will find man pages that contain the topic specified. It is useful when you want to do something but can&#8217;t remember or don&#8217;t know the name of the command to do it.<\/span><\/dd>\n<dt><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">man<\/span><\/dt>\n<dd><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">This command displays manual pages. It is used like this, &#8220;man man&#8221;, in this example it provides a manual page on the man command. The manual pages are divided into sections with ordinary user commands in section 1, system calls in section 2, C library functions in section 3, devices and special files in section 4, file formats and special conventions in section 5, games in section 6, miscellaneous stuff that doesn&#8217;t fit elsewhere in section 7, and system administration commands in section 8. Normally it is not necessary to specify a section unless the same topic exists in more than one and it becomes necessary to disambiguate them.<\/span><\/dd>\n<dt><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">info<\/span><\/dt>\n<dd><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">A lot of software developers don&#8217;t like to document enough to bother to learn troff in which man pages are written. As a result a lot of modern Linux documentation exists as info pages which are difficult to navigate and horridly formatted. None the less, sometimes that is the only place you can get information on modern Linux software.<\/span><\/dd>\n<\/dl>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 14pt;\">The Linux File System<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Actually there are many different Linux file systems but on the user level they all share common attributes.\u00a0 They all are hierarchical, basically a tree structure that always starts with the root directory, &#8220;\/&#8221;, then various directories under the root such as &#8220;\/home&#8221;,\u00a0 where home directories generally reside, &#8220;\/dev&#8221;, where devices reside, &#8220;\/tmp&#8221;, for temporary files, etc.\u00a0 For example, if your username is quebert, then your home directory would be &#8220;\/home\/quebert&#8221;.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The differences in file systems are largely internal.\u00a0 The most commonly used Linux file system at this time is ext4.\u00a0 It is also used by new Mac OS X systems and some other Unixes.\u00a0 However there are many competing file systems also supported by Linux such as &#8220;xfs&#8221;.\u00a0 These other file systems have different advantages.\u00a0 Some are faster under certain circumstances, some make more efficient use of disk space.\u00a0 Some support larger file systems than ext4 can.\u00a0 Most of these advantages are moot to the average home user.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">A command which will show a text representation of a file system layout, or a portion of that file system starting at the current working directory, is &#8220;tree&#8221;.\u00a0 Here is an example of the output of tree on my Pictures directory:<\/span><\/p>\n<p><a href=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/tree.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-841\" src=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/tree.jpg\" alt=\"tree\" width=\"490\" height=\"698\" srcset=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/tree.jpg 490w, https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/tree-211x300.jpg 211w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><\/a><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Since a typical Linux system will contain anywhere between several hundred thousand files and several tens of millions, this is not a practical way to view a large file system but is illustrative of the file system layout.<\/span><\/p>\n<p><strong><span style=\"font-family: arial,helvetica,sans-serif; font-size: 14pt;\">Navigation<\/span><\/strong><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The normal way to view a listing of files in a directory is with the command &#8220;ls&#8221;.\u00a0 Given by itself with no arguments, it will show the non-hidden file names in the current working directory without any attributes.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 File names beginning with a &#8220;.&#8221; cause the file or directory to be hidden from view.\u00a0 These are normally used for things like personal configuration files for various applications.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 To see these files, use &#8220;ls -a&#8221;, the &#8220;-a&#8221; says to show all files.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Often you will want to know more about a file besides it&#8217;s name.\u00a0 In this case, use\u00a0 <\/span><a href=\"https:\/\/www.eskimo.com\/support\/man\/ls\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">&#8220;<\/span><\/a><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">ls<\/span><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">-l&#8221; to get a listing of files with their attributes,\u00a0 This will normally list the type of file, it&#8217;s permissions, the owner and group of the file, it&#8217;s size, modification date, and filename.\u00a0 Some versions of &#8220;ls&#8221; require an &#8220;&#8211;author&#8221; argument to show the owner, &#8220;ls -l &#8211;author&#8221;.\u00a0 It is also possible that some sites may define aliases to &#8220;ls&#8221; in \/etc\/profile that alter the normal behavior.<br \/>\n<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 For a complete listing of all the arguments available to &#8220;ls&#8221; and the meaning of the output generated, see the &#8220;ls&#8221; man page.\u00a0 The specific arguments available to &#8220;ls&#8221; and the output varies with different Linux distributions.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 So far these commands have shown you how to see a list of files in your current directory.\u00a0 To see a list of files in other directories use &#8220;ls \/some\/path&#8221;, where \/some\/path is the path that you are interested.\u00a0 If the path starts with &#8220;\/&#8221; it is what is known as an absolute path\u00a0 and is the full path of a file or directory starting at the root directory.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 If a path doesn&#8217;t start with a &#8220;\/&#8221; then the path is a relative path.\u00a0 That is to say it is relative to the current working directory.\u00a0 Let&#8217;s say you are in your home directory and you type &#8220;ls Pictures&#8221; and your login is &#8220;smug&#8221;, then the path would be \/home\/smug\/Pictures.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 There are two special directory entires in every directory.\u00a0 They are &#8220;.&#8221; which is the current working directory and &#8220;..&#8221; which is the parent directory, the directory the current working directory resides in.\u00a0 In the root directory, the &#8220;..&#8221; is also the current working directory since there is no where else to back up to.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">To change to a different directory, use the &#8220;cd&#8221; command.\u00a0 The cd command has several potential arguments.<\/span><\/p>\n<dl>\n<dt><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">cd<\/span><\/dt>\n<dd><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">Typing &#8220;cd&#8221; with no arguments returns you to your home directory.<\/span><\/dd>\n<dt><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">cd \/absolute\/path<\/span><\/dt>\n<dd><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">Takes to you the absolute path relative to root. This must be a directory, you can not change directories to a non-directory.<\/span><\/dd>\n<dt><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">cd relative\/path<\/span><\/dt>\n<dd><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">This takes you to a path relative to where you are. Again, you can not change directories to a non-directory.<\/span><\/dd>\n<dt><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">cd ~<\/span><\/dt>\n<dd><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">This also takes you to your home directory but in addition can be used to form paths relative to your home directory.<\/span><\/dd>\n<dt><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">cd ~\/path<\/span><\/dt>\n<dd><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">This is an example of a path relative to your home directory.<\/span><\/dd>\n<dt><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">cd &#8211;<\/span><\/dt>\n<dd><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">This takes you to the last directory you were in.<\/span><\/dd>\n<dt><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">cd ..<\/span><\/dt>\n<dd><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">This takes you to the parent directory of the directory you are presently in.<\/span><\/dd>\n<dt><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">cd .<\/span><\/dt>\n<dd><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">This is essentially a non-operation since &#8220;.&#8221; is your current working directory.<\/span><\/dd>\n<\/dl>\n<p><strong><span style=\"font-family: arial,helvetica,sans-serif; font-size: 14pt;\">Ending a Terminal Session<\/span><\/strong><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 If the shell is a login shell (you connected via ssh and logged in), you can usually exit with &#8220;logout&#8221; or control-D (hold the control button down and press D).<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 If the shell is not a login shell, for example if you logged in via a graphical remote desktop and then fired up a terminal, &#8220;exit&#8221;, will end the terminal session.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 14pt;\"><strong>Disk Usage<\/strong><\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The command to find out how much disk space you are using out of your allowed disk quota is &#8220;quota -v&#8221;.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 On some machines you can get a more readable form by adding &#8220;-s&#8221; but this is not supported on all systems.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The command &#8220;du -s ~&#8221; will show you the disk usage in terms of the total of the files in your directory however it will not accurately reflect your usage in terms of quota.\u00a0 The reason for this is that du bases it&#8217;s output on the file size, but the file size can be less than the disk space allocated.\u00a0 The reason for this is that the ext4 file system allocates a minimum disk unit of one block and on modern drives this is usually 4kb.\u00a0 So a file might only be 1 byte long but will use 4096 bytes of disk space.\u00a0 This is a minor drawback of the ext4 file system.<\/span><\/p>\n<p><strong><span style=\"font-family: arial,helvetica,sans-serif; font-size: 14pt;\"> File Manipulation<\/span><\/strong><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0 On modern Linux systems, renaming a file is synonymous with moving it.\u00a0 This was not true of early systems which were incapable of moving a file across partitions.\u00a0 But today whether you are renaming a file or moving it to an entirely different part of the file system or even another partition, the command is the same:<\/span><\/p>\n<pre>mv oldpath newpath<\/pre>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 If the destination path is a directory then the file will be moved with it&#8217;s original name into that destination directory.\u00a0 If the source path is a directory, then the entire directory and all of it&#8217;s contents are moved.<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 To remove a file use the rm command is used.\u00a0 The general form of the command is:<\/span><\/p>\n<pre><span style=\"font-size: 12pt;\">rm -args filename(s)<\/span><\/pre>\n<p><span style=\"font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Some generally useful arguments are &#8220;-r&#8221; which says to recursively remove a directory and it&#8217;s contents, &#8220;-f&#8221;, which says to remove the contents even if they don&#8217;t have write permissions, and &#8220;-i&#8221; which is interactive and generally used with a wildcard file argument to remove only those you really want to remove.\u00a0 It asks for confirmation for each file that is to be removed.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 To copy files, the simplest command to use is &#8220;cp&#8221;.\u00a0 The &#8220;cp&#8221; command can copy files or entire directories.\u00a0 It has many options, see the cp man page for details.<\/span><\/p>\n<pre><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">cp filename [newfilename] [-a newdirectory]<\/span><\/pre>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 These are examples of copying an individual file or entire directory.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 To concatenate two or more files into one file containing the contents of the first two you can use the cat command.\u00a0 If you get a SSL certificate, it typically will contain the local portion, any intermediary certificates, and the root certificate in separate files, but a lot of Linux software expects them to all be in one so you can use the cat command to combine them like this:<\/span><\/p>\n<pre><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">cat local.crt intermediate.crt root.crt &gt; all.crt<\/span><\/pre>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Often times cat can also be used to output the file verbatim with no paging.\u00a0 Any characters, control codes, binaries, everything will be output exactly as it exists in the file with the cat command.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 You can view a file with more or less.\u00a0 More is a simple paging program that pages the output of a file to your screen.\u00a0 Less is an advanced version of more that permits backwards paging and other capabilities lacking in the original version of more.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 For example, you can view the contents of the system message of the day file with the following command:<\/span><\/p>\n<pre><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">more \/etc\/motd<\/span><\/pre>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The more command is available on even the earliest Linux systems and less is available on all modern Linux systems.<\/span><\/p>\n<p><strong><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">Commands<\/span><\/strong><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Linux is unique in it&#8217;s ability to allow commands to be written in virtually any language and executed in a way that is completely transparent to the user.\u00a0 <\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Commands can be built-in to the shell you are using, &#8220;echo&#8221; is an example of a command that is typically built-in.\u00a0 Commands can be external binary executable programs compiled from a wide variety of languages although C and C++ are most commonly used, and lastly commands can be written in any scripting language such as shell scripts, python, perl, php, ruby, and many others.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The first line of a scripted language command contains, &#8220;#&#8221; followed by the path to the interpreting language.\u00a0 For example, a shell script would start with &#8220;#\/bin\/sh&#8221;, a php script with &#8220;\/usr\/bin\/php&#8221;, perl with &#8220;#\/usr\/bin\/perl&#8221;, etc.\u00a0 In some cases there would be an argument after the path, particularly with perl to specify taintperl.<\/span><\/p>\n<p><strong><span style=\"font-family: arial,helvetica,sans-serif; font-size: 14pt;\">Terminal Parameters<\/span><\/strong><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 In the old days, the way we&#8217;d normally connect to a computer is through a serial RS-232 port.\u00a0 In modern times we usually connect through ssh over a TCP\/IP network of some kind.\u00a0 In order to provide the same functionality as provided over a serial port, Linux has PTYs, psuedo-ttys.\u00a0 These basically make it look to the application like\u00a0 you&#8217;re coming over a serial connection even though you are not.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The keystrokes used to do things like backspace, interrupt, or kill a program are not fixed in Linux, rather they can be set with the command stty.\u00a0 The most common key to change is the erase key, the key that backs up one position and erases the character.\u00a0 Some people prefer to use the erase key, some people prefer to use the backspace key, and some keyboards generate altogether weird characters when the backspace or delete key is used.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The stty command allows you to set this key and more.\u00a0 To set the erase key to backspace, the following command will work:<\/span><\/p>\n<pre><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">stty erase ^h<\/span><\/pre>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 To set the erase key to delete use:<\/span><\/p>\n<pre><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">stty erase ^?<\/span><\/pre>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 The ^h stands for control-H, and ^? for Delete.\u00a0 Backspace normally generates control-H.\u00a0 Other keystroke functions such as the key to interrupt or kill a program can be set.\u00a0 Another useful key to set is the eof key.\u00a0 On most machines ^D indicates an end of file, but on Mac systems it is ^Z.\u00a0 This is also true of old CP\/M machines though you are unlikely to run into one of those these days.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 Please note that the baud rate is irrelevant over a TCP\/IP connection and only applies to a true serial connection or a USB serial port converter connection.\u00a0 You can see all of the settings by typing:<\/span><\/p>\n<pre><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">stty -a<\/span><\/pre>\n<p><span style=\"font-family: arial,helvetica,sans-serif;\"><a href=\"https:\/\/www.eskimo.com\/support\/man\/who\/\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-886\" src=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/stty.jpg\" alt=\"stty\" width=\"488\" height=\"323\" srcset=\"https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/stty.jpg 488w, https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/stty-300x199.jpg 300w, https:\/\/www.eskimo.com\/support\/wp-content\/uploads\/2015\/08\/stty-453x300.jpg 453w\" sizes=\"auto, (max-width: 488px) 100vw, 488px\" \/><\/a><strong><span style=\"font-size: 12pt;\">Who Else is Online<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 There are several related commands for finding who else is online.\u00a0 The &#8220;who&#8221; command and &#8220;w&#8221; command show who is online locally.\u00a0 The &#8220;who&#8221; command shows what tty or pty they are on.\u00a0 It also shows where they connected from.\u00a0 The &#8220;w&#8221; command also shows this information but the hostname field is shortened to make room for other data and so is often truncated. The &#8220;w&#8221; command also shows how long they&#8217;ve been idle and what command they are executing.<\/span><\/p>\n<p><span style=\"font-family: arial,helvetica,sans-serif; font-size: 12pt;\">\u00a0\u00a0\u00a0\u00a0 You can see who is logged in to other machines on the local network by using the command &#8220;rwho&#8221;.\u00a0 It does not provide any information about what they are doing.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Linux Old School Command Line Interface Derivation of Various Shells (Command Line Interpreters) \u00a0\u00a0\u00a0\u00a0 Before Linux there was Unix.\u00a0 Unix was a multi-tasking multi-user operating system created at Bell Labs, originally to share the resources of a PDP-7.\u00a0 In &hellip; <a href=\"https:\/\/www.eskimo.com\/support\/using-linux\/old-school-cli\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":761,"menu_order":0,"comment_status":"open","ping_status":"open","template":"showcase.php","meta":{"footnotes":""},"class_list":["post-763","page","type-page","status-publish","hentry","wpautop"],"_links":{"self":[{"href":"https:\/\/www.eskimo.com\/support\/wp-json\/wp\/v2\/pages\/763","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.eskimo.com\/support\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.eskimo.com\/support\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.eskimo.com\/support\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.eskimo.com\/support\/wp-json\/wp\/v2\/comments?post=763"}],"version-history":[{"count":4,"href":"https:\/\/www.eskimo.com\/support\/wp-json\/wp\/v2\/pages\/763\/revisions"}],"predecessor-version":[{"id":1098,"href":"https:\/\/www.eskimo.com\/support\/wp-json\/wp\/v2\/pages\/763\/revisions\/1098"}],"up":[{"embeddable":true,"href":"https:\/\/www.eskimo.com\/support\/wp-json\/wp\/v2\/pages\/761"}],"wp:attachment":[{"href":"https:\/\/www.eskimo.com\/support\/wp-json\/wp\/v2\/media?parent=763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}