{"id":158,"date":"2017-04-19T15:39:46","date_gmt":"2017-04-19T19:39:46","guid":{"rendered":"https:\/\/carleton.ca\/rcs\/?page_id=158"},"modified":"2026-04-09T12:46:52","modified_gmt":"2026-04-09T16:46:52","slug":"linux-basics","status":"publish","type":"page","link":"https:\/\/carleton.ca\/rcs\/rcdc\/linux-basics\/","title":{"rendered":"Linux Basics"},"content":{"rendered":"\n<section class=\"w-screen px-6 cu-section cu-section--white ml-offset-center md:px-8 lg:px-14\">\n    <div class=\"space-y-6 cu-max-w-child-5xl  md:space-y-10 cu-prose-first-last\">\n\n            <div class=\"cu-textmedia flex flex-col lg:flex-row mx-auto gap-6 md:gap-10 my-6 md:my-12 first:mt-0 max-w-5xl\">\n        <div class=\"justify-start cu-textmedia-content cu-prose-first-last\" style=\"flex: 0 0 100%;\">\n            <header class=\"font-light prose-xl cu-pageheader md:prose-2xl cu-component-updated cu-prose-first-last\">\n                                    <h1 class=\"cu-prose-first-last font-semibold !mt-2 mb-4 md:mb-6 relative after:absolute after:h-px after:bottom-0 after:bg-cu-red after:left-px text-3xl md:text-4xl lg:text-5xl lg:leading-[3.5rem] pb-5 after:w-10 text-cu-black-700 not-prose\">\n                        Linux Basics\n                    <\/h1>\n                \n                                \n                            <\/header>\n\n                    <\/div>\n\n            <\/div>\n\n    <\/div>\n<\/section>\n\n\n\n<h2 id=\"navigating-the-filesystem\" class=\"wp-block-heading\">Navigating the Filesystem<\/h2>\n\n\n\n<p>This section will give a brief overview on some linux commands you can use to navigate and interact with the filesystem on your VM. If you do not have a basic understanding of&nbsp;what a file system is, it is suggested that you do some further background reading. The Unix Shell lesson by Software Carpentry is a good suggested starting point:&nbsp;https:\/\/swcarpentry.github.io\/shell-novice\/. Below is a list of commands you may find useful. This list is not exhaustive, so please feel free to explore this topic further on the internet. To get further information on a given command x, enter the command &#8220;man x&#8221; in your terminal window while logged into your VM. This will bring up the manual page on that command.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong class=\"myprefix-text-bold\">pwd<\/strong>: This command prints the full filename of the current working directory. This allows you to easily determine where in the filesystem you are currently sitting.<\/li>\n\n\n\n<li><strong class=\"myprefix-text-bold\">ls<\/strong>: This command lists the contents (files and directories) of the current directory.<\/li>\n\n\n\n<li><strong class=\"myprefix-text-bold\">cd &lt;dir><\/strong>: This command\u00a0is used to navigate the filesystem. If &lt;dir> is not included, you will be moved to your home directory. Otherwise, you will be moved to &lt;dir>.<\/li>\n\n\n\n<li><strong class=\"myprefix-text-bold\">mkdir &lt;name><\/strong>: This command will create an empty directory called &lt;name>.<\/li>\n\n\n\n<li><strong class=\"myprefix-text-bold\">rmdir &lt;name><\/strong>: This command will remove an empty directory called &lt;name>. It will fail if the directory &lt;name> is not empty.<\/li>\n\n\n\n<li><strong class=\"myprefix-text-bold\">rm &lt;name><\/strong>: This command will remove the file called &lt;name>. If &lt;name> is a directory, the command will fail. To remove a directory with rm, add the parameter -r (<strong class=\"myprefix-text-bold\">rm -r &lt;name><\/strong>). This removes &lt;name> recursively (ie. that directory and everything in it will be deleted).<\/li>\n\n\n\n<li><strong class=\"myprefix-text-bold\">mv &lt;old> &lt;new><\/strong>: This command will move the file\/directory &lt;old> to &lt;new> (ie. renames the file\/directory)<\/li>\n\n\n\n<li><strong class=\"myprefix-text-bold\">cp &lt;old> &lt;new><\/strong>:\u00a0This command will copy\u00a0the file\/directory &lt;old> to &lt;new>.<\/li>\n<\/ul>\n\n\n\n<h2 id=\"file-permissions\" class=\"wp-block-heading\">File Permissions<\/h2>\n\n\n\n<p>Every file and directory in Linux is owned by a user, and a group. &nbsp;Linux is a multiuser environment, where your files are separated from others on the same Linux system.<\/p>\n\n\n\n<p>Linux has three levels of permissions &#8211;\u00a0<em class=\"myprefix-text-italic\">user,\u00a0group, and\u00a0other<\/em>. \u00a0Each of these three levels lets you set a\u00a0<em class=\"myprefix-text-italic\">read,\u00a0write, and\u00a0execute<\/em> permission. \u00a0So in total there are 9 standard permissions in Linux. \u00a0Read means you are able to look at a file&#8217;s content; write means you can save to the file. \u00a0And execute means that if the file is a program, then you are can run it.<\/p>\n\n\n\n<p>If your user matches a files, then the user permissions apply to you. &nbsp;If one of your groups matches a file&#8217;s group, then group permissions apply to you.<\/p>\n\n\n\n<p>When you run\u00a0<strong class=\"myprefix-text-bold\">ls -l<\/strong> you will see the long listing format for files. \u00a0In this format, the third and fourth column shows the user and group associated with each file. \u00a0The file&#8217;s permissions are shown in the first column as a sequence o\u00a0<strong class=\"myprefix-text-bold\">r, w, x<\/strong>, <strong>&#8211;<\/strong> characters. \u00a0The nine permissions are listed in the order rwx for each of the three user, group, other levels. \u00a0If a permission is replaced with a &#8211; then that file does not have the particular permission.<\/p>\n\n\n\n<p>You can change permissions with the<strong class=\"myprefix-text-bold\"> chmod<\/strong> command. For example, to remove group read from a file:\u00a0<strong class=\"myprefix-text-bold\">chmod g-r example.txt<\/strong><\/p>\n\n\n\n<h2 id=\"basic-text-editing\" class=\"wp-block-heading\">Basic Text Editing<\/h2>\n\n\n\n<p>A good basic text editor for the Linux command-line is\u00a0<strong class=\"myprefix-text-bold\">nano<\/strong>. \u00a0To edit a file just run the command<em class=\"myprefix-text-italic\">\u00a0nano<\/em> followed by the filename. \u00a0In the <strong class=\"myprefix-text-bold\">nano<\/strong> editor, special commands are listed at the bottom with the &#8220;^&#8221; character representing the CTRL\u00a0key. If you prefer a\u00a0graphical text editor, you may used\u00a0<strong class=\"myprefix-text-bold\">gedit<\/strong> instead of\u00a0<strong class=\"myprefix-text-bold\">nano<\/strong>.<\/p>\n\n\n\n<h2 id=\"monitoring-load-resources-and-processes\" class=\"wp-block-heading\">Monitoring Load, Resources and Processes<\/h2>\n\n\n\n<p>This section will give a set of commands that you can use to monitor the current load and resource use on your VM.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong class=\"myprefix-text-bold\">top \/ htop<\/strong>: Both top and htop gives you a dynamic, real-time view of all of the processes running on your system. There is a lot of data displayed for each process. Likely the most important information for you is the %CPU and %MEM details of the processes you are running. If you are running a multithreaded application, %CPU can go over 100%. The max %CPU will be the number of cores assigned to your VM (n) times 100%. If you notice your process (or sum of the CPU usage over you processes) are using close to n00% CPU, you are completely using all available cores. You need to also monitor %MEM. If this gets too high (ie. reaches 100%), your process will crash. If you notice that your process is slowly but continually using more memory it will likely crash eventually.<\/li>\n\n\n\n<li><strong class=\"myprefix-text-bold\">ps &lt;ID><\/strong>: Every process running on your system is given a unique ID. The ID assigned to each process is listed in the first column of the\u00a0<strong>top<\/strong> output. This command gives more information on a specific running process.<\/li>\n\n\n\n<li><strong class=\"myprefix-text-bold\">free -h<\/strong>: This command gives a quick summary of the free and used memory across your VM. Including the option\u00a0<strong>-h<\/strong> displays the output using human readable units.<\/li>\n\n\n\n<li><strong class=\"myprefix-text-bold\">df -h<\/strong>: This command gives a quick usage summary of the available disk storage. An intervention should be made if you notice any listed volume approaching 100%\u00a0usage.<\/li>\n<\/ul>\n\n\n\n<h2 id=\"running-processes-in-the-background\" class=\"wp-block-heading\">Running Processes in the Background<\/h2>\n\n\n\n<p>Sometimes if a job is going to take a long time to execute, we would like to run this process in the background. This allows us to have our job execute but still lets us have full control over our terminal. To run a job in the background, simply add an &amp; to the end of the command line before executing it. For example:<\/p>\n\n\n<div class=\"not-prose cu-quote cu-component-spacing\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>command<\/em> &amp;<\/p>\n<\/blockquote>\n<\/div>\n\n\n<p>When we do this it will launch\u00a0<em class=\"myprefix-text-italic\">command<\/em> and return us to the command prompt. If we run\u00a0<strong>top<\/strong>, we should see it in our process list. This method allows us to run one process in the background. To be able to run multiple background processes, after executing the command above we much commit it to the background, we must follow it by\u00a0<strong class=\"myprefix-text-bold\">bg<\/strong>:<\/p>\n\n\n<div class=\"not-prose cu-quote cu-component-spacing\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>command<\/em> &amp;<\/p>\n\n\n\n<p><strong>bg<\/strong><\/p>\n<\/blockquote>\n<\/div>\n\n\n<p>If you have already started a job and want to relegate\u00a0it to the background, press CTRL-Z. This will suspend the job. When you follow this by\u00a0<strong class=\"myprefix-text-bold\">bg<\/strong> it will have it run in the background.<\/p>\n\n\n\n<p>To get a list of jobs running in the background, we use the\u00a0<strong class=\"myprefix-text-bold\">jobs<\/strong> command. Each background job is assigned a job ID. If we want to switch to a background job (ie. bring it to the foreground), we use the command\u00a0<strong class=\"myprefix-text-bold\">fg &lt;ID>.\u00a0&lt;ID><\/strong> can be omitted if there is only one background process running.<\/p>\n\n\n\n<p>If you want to end a process that is running, you can use the\u00a0<strong class=\"myprefix-text-bold\">kill &lt;ID><\/strong> command. The kill command takes a process ID as a parameter. This ID can be determined using the\u00a0<strong class=\"myprefix-text-bold\">top <\/strong>command.<\/p>\n\n\n\n<h2 id=\"redirecting-process-output-to-a-file\" class=\"wp-block-heading\">Redirecting Process Output to a File<\/h2>\n\n\n\n<p>Running certain programs cause a lot of information to be dumped to the console. Sometimes this is done so quickly that we cannot follow what is going on or we would like to save this output for later. To do this, we can use something called a redirect. This redirect causes the information normally dumped to your screen to be saved to a file. You do this by using &#8216;&gt;&#8217;:<\/p>\n\n\n<div class=\"not-prose cu-quote cu-component-spacing\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>command<\/em> &gt; results.txt<\/p>\n<\/blockquote>\n<\/div>\n\n\n<p>This will save the output of\u00a0<em class=\"myprefix-text-italic\">command <\/em>to results.txt. This is great, however there are actually two sets of outputs being produced here. The first is the regular output produced by <em class=\"myprefix-text-italic\">command <\/em>(known are stdout) as well as all of the errors produced (known as stderr). These &#8220;output streams&#8221; are normally dumped to the same location so the end user does not know where a given line came from. Sometimes it is useful to separate the stdout from the stderr. We can redirect either of these streams to a file by identifying them with &#8216;1&#8217; (stdout) or &#8216;2&#8217; (stderr). For example, if we want to save the stdout to a file and have the errors print to screen, we would do the following:<\/p>\n\n\n<div class=\"not-prose cu-quote cu-component-spacing\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>command<\/em>&nbsp;1&gt; results.txt<\/p>\n<\/blockquote>\n<\/div>\n\n\n<p>On the other hand, if we would like to print the stdout to screen and save the errors to a file, we would do the following:<\/p>\n\n\n<div class=\"not-prose cu-quote cu-component-spacing\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>command<\/em>&nbsp;2&gt; errors.txt<\/p>\n<\/blockquote>\n<\/div>\n\n\n<p>If we want to save both streams to separate files, we would do the following:<\/p>\n\n\n<div class=\"not-prose cu-quote cu-component-spacing\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>command<\/em>&nbsp;1&gt; results.txt&nbsp;2&gt; errors.txt<\/p>\n<\/blockquote>\n<\/div>\n\n\n<p>Finally, we can combine this with what we learned in the previous section to send this entire process to the background:<\/p>\n\n\n<div class=\"not-prose cu-quote cu-component-spacing\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>command<\/em>&nbsp;1&gt; results.txt&nbsp;2&gt; errors.txt &amp;<\/p>\n<\/blockquote>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"keep-jobs-running-after-logout\">Keep jobs running after logout<\/h2>\n\n\n\n<p>Running jobs in the background a useful way to run many long programs at once. However, your shell session stops all its jobs when you logout or disconnect. Even background jobs are stopped. For jobs that run a long time, they will be stopped if your local computer turns off, or if there are any network interruptions. It is also convenient to be able to switch between various computers, e.g. at home and school, and continue monitoring your long jobs from both places.<\/p>\n\n\n\n<p>To run a job that can be disconnected from your shell, you should to do two things. First, tell your job to ignore any disconnect (\u201changup\u201d or HUP) signals from your shell using the <strong class=\"myprefix-text-bold\">nohup<\/strong> command. Second, redirect your output to a file for later viewing. For example:<\/p>\n\n\n<div class=\"not-prose cu-quote cu-component-spacing\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>nohup <em>command<\/em> &gt; results.txt 2&gt; errors.txt &amp;<\/p>\n<\/blockquote>\n<\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Navigating the Filesystem This section will give a brief overview on some linux commands you can use to navigate and interact with the filesystem on your VM. If you do not have a basic understanding of&nbsp;what a file system is, it is suggested that you do some further background reading. The Unix Shell lesson by [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":96,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_cu_dining_location_slug":"","footnotes":"","_links_to":"","_links_to_target":""},"cu_page_type":[],"class_list":["post-158","page","type-page","status-publish","hentry"],"acf":{"cu_post_thumbnail":""},"_links":{"self":[{"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":3,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages\/158\/revisions"}],"predecessor-version":[{"id":1170,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages\/158\/revisions\/1170"}],"up":[{"embeddable":true,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages\/96"}],"wp:attachment":[{"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"cu_page_type","embeddable":true,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/cu_page_type?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}