{"id":79,"date":"2017-01-02T19:18:47","date_gmt":"2017-01-02T19:18:47","guid":{"rendered":"http:\/\/cellbiol.com\/test-bioinfo\/?page_id=79"},"modified":"2017-06-01T12:21:47","modified_gmt":"2017-06-01T12:21:47","slug":"the-linux-filesystem","status":"publish","type":"page","link":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/chapter-2-the-linux-operating-system-setting-up-a-linux-web-server\/the-linux-filesystem\/","title":{"rendered":"2-2: The Linux Filesystem"},"content":{"rendered":"<p>On approaching Linux systems for the first time, it is essential to understand how files and directories are organized in a Linux system and how to refer to a particular file or directory in order to perform actions. In order to refer to file or directory we need to know it&#8217;s relative or absolute path in the filesystem.<\/p>\n<h2>The Linux root directory<\/h2>\n<p>Everything in the Linux filesystem is included within a top directory (you can think of a directory just as a folder that contains other folders or files) that is called the Root directory.<\/p>\n<p><em>Table 2-2-1: Subdirectories of the root directory in Linux systems<\/em><br \/>\nSource: <a href=\"http:\/\/tldp.org\/LDP\/intro-linux\/html\/sect_03_01.html\">This page<\/a>\u00a0of <a href=\"http:\/\/tldp.org\/\">The Linux Documentation Project<\/a><\/p>\n<div class=\"table\">\n<table class=\"CALSTABLE\" border=\"1\">\n<thead>\n<tr>\n<th align=\"LEFT\" valign=\"MIDDLE\">Directory<\/th>\n<th align=\"LEFT\" valign=\"MIDDLE\">Content<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/bin<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">Common programs, shared by the system, the system administrator and the users.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/boot<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">The startup files and the kernel, <tt class=\"filename\">vmlinuz<\/tt>. In some recent distributions also <tt class=\"filename\">grub<\/tt> data. Grub is the <span class=\"application\">GRand Unified Boot<\/span> loader and is an attempt to get rid of the many different boot-loaders we know today.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/dev<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">Contains references to all the CPU peripheral hardware, which are represented as files with special properties.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/etc<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">Most important system configuration files are in <tt class=\"filename\">\/etc<\/tt>, this directory contains data similar to those in the Control Panel in Windows<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/home<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">Home directories of the common users.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/initrd<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">(on some distributions) Information for booting. Do not remove!<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/lib<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">Library files, includes files for all kinds of programs needed by the system and the users.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/lost+found<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">Every partition has a <tt class=\"filename\">lost+found<\/tt> in its upper directory. Files that were saved during failures are here.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/misc<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">For miscellaneous purposes.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/mnt<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">Standard mount point for external file systems, e.g. a CD-ROM or a digital camera.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/net<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">Standard mount point for entire remote file systems<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/opt<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">Typically contains extra and third party software.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/proc<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">A virtual file system containing information about system resources. More information about the meaning of the files in <tt class=\"filename\">proc<\/tt> is obtained by entering the command <b class=\"command\">man <tt class=\"parameter\"><i>proc<\/i><\/tt><\/b> in a terminal window. The file <tt class=\"filename\">proc.txt<\/tt> discusses the virtual file system in detail.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/root<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">The administrative user&#8217;s home directory. Mind the difference between \/, the root directory and \/root, the home directory of the <em>root<\/em> user.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/sbin<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">Programs for use by the system and the system administrator.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/tmp<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">Temporary space for use by the system, cleaned upon reboot, so don&#8217;t use this for saving any work!<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/usr<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">Programs, libraries, documentation etc. for all user-related programs.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\">\/var<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\">Storage for all variable files and temporary files created by users, such as log files, the mail queue, the print spooler area, space for temporary storage of files downloaded from the Internet, or to keep an image of a CD before burning it.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2>Absolute paths<\/h2>\n<p>For path purposes, the root directory is indicated with a slash. The absolute path of the root directory is<\/p>\n<p>\/<\/p>\n<p>An absolute path, is a path that indicates the position of a file or directory with respect to the root directory. Therefore, <strong>absolute paths always start with a slash<\/strong>. For example the absolute path of the folder &#8220;etc&#8221; contained directly within the root folder in all Linux system is:<\/p>\n<p>\/etc<\/p>\n<p>where the slash indicates the root folder.<\/p>\n<h2>The Linux Shell &#8211; Using the Terminal<\/h2>\n<p>Let&#8217;s start using a Linux shell to explore the filesystem. In Ubuntu, a Terminal window can be opened with the following keyboard shortcut:<\/p>\n<p>Ctrl + Alt + T<\/p>\n<p>Or, in Ubuntu Unity: Dash -&gt; Search Terminal<\/p>\n<p>Or, in Gnome: Applications menu -&gt; Accessories -&gt; Terminal<\/p>\n<figure id=\"attachment_357\" aria-describedby=\"caption-attachment-357\" style=\"width: 656px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/ubuntu_shell_screenshot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-357\" src=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/ubuntu_shell_screenshot.png\" alt=\"Linux Terminal to access the Shell\" width=\"656\" height=\"464\" srcset=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/ubuntu_shell_screenshot.png 656w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/ubuntu_shell_screenshot-300x212.png 300w\" sizes=\"auto, (max-width: 656px) 85vw, 656px\" \/><\/a><figcaption id=\"caption-attachment-357\" class=\"wp-caption-text\">Figure 2-2-1: Linux Terminal to access the Shell<\/figcaption><\/figure>\n<p>When we open the Terminal, we see a line that ends with a dollar sign $. This line is called <strong>the prompt<\/strong>, this is where we can type commands to interact with the computer.<\/p>\n<h2>Typing Shell Commands &#8211; The pwd Present Working Directory command<\/h2>\n<p>As a first command, let us type &#8220;pwd&#8221;:<\/p>\n<p>andrea@ubuntu:~$ pwd<\/p>\n<p>and press the enter key<\/p>\n<figure id=\"attachment_80\" aria-describedby=\"caption-attachment-80\" style=\"width: 320px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-80\" src=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/shell_pwd_screenshot.png\" alt=\"Issuing a shell command\" width=\"320\" height=\"155\" srcset=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/shell_pwd_screenshot.png 320w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/shell_pwd_screenshot-300x145.png 300w\" sizes=\"auto, (max-width: 320px) 85vw, 320px\" \/><figcaption id=\"caption-attachment-80\" class=\"wp-caption-text\">Figure 2-2-2: Issuing a shell command<\/figcaption><\/figure>\n<p>pwd stands for &#8220;<strong>P<\/strong>resent <strong>W<\/strong>orking <strong>D<\/strong>irectory&#8221; and returns the absolute path of the current directory, the folder in which we are virtually currently located within the file system, as show in figure 2-2-2. In this case, we are in the user &#8220;andrea&#8221; home directory. In Linux, every user is assigned a home folder within the<\/p>\n<p>\/home<\/p>\n<p>directory, with the same name as the user. So the user &#8220;andrea&#8221; has a folder called &#8220;andrea&#8221;, located in a &#8220;home&#8221; folder, contained in the root directory &#8220;\/&#8221;:<\/p>\n<p>\/home\/andrea<\/p>\n<h2>Absolute Path Anatomy<\/h2>\n<p>In this absolute path of the &#8220;andrea&#8221; folder, as in all absolute paths, the first slash indicates the root folder, while the subsequent slashes in the path are just separators to delimitate the directories names.<\/p>\n<figure id=\"attachment_81\" aria-describedby=\"caption-attachment-81\" style=\"width: 583px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/slashes_in_absolute_paths.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-81 size-full\" src=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/slashes_in_absolute_paths.png\" alt=\"The meaning of the slashes in an absolute path\" width=\"583\" height=\"301\" srcset=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/slashes_in_absolute_paths.png 583w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/slashes_in_absolute_paths-300x155.png 300w\" sizes=\"auto, (max-width: 583px) 85vw, 583px\" \/><\/a><figcaption id=\"caption-attachment-81\" class=\"wp-caption-text\">Figure 2-2-3: The meaning of the slashes in an absolute path. While the first slash indicates the root directory, the subsequent slashes are separators for the directories or file names<\/figcaption><\/figure>\n<p>When a user opens a terminal window, either locally or from a remote location (by connecting to the server by SSH, this will be discussed later on in this chapter), the default location within the file system is his home directory \/home\/username.<\/p>\n<h2>The ls shell command to list directory contents<\/h2>\n<p>Let&#8217;s have a look to the contents of the Linux root directory by using the &#8220;ls&#8221; (<strong>L<\/strong>i<strong>S<\/strong>t) command. The &#8220;ls&#8221; command can take as an optional argument the name of the directory of which we wish to list the contents. So if we wish to list the contents of the Root directory we can type:<\/p>\n<p>andrea@ubuntu:~$ ls \/<\/p>\n<p>Without arguments, it will list the contents of the present working directory, the one we &#8220;are in&#8221; when issuing the ls command.<\/p>\n<figure id=\"attachment_82\" aria-describedby=\"caption-attachment-82\" style=\"width: 656px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/listing_the_root_directory_contents.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-82 size-full\" src=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/listing_the_root_directory_contents.png\" alt=\"Listing the contents of the Root directory with the ls command\" width=\"656\" height=\"194\" srcset=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/listing_the_root_directory_contents.png 656w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/listing_the_root_directory_contents-300x89.png 300w\" sizes=\"auto, (max-width: 656px) 85vw, 656px\" \/><\/a><figcaption id=\"caption-attachment-82\" class=\"wp-caption-text\">Figure 2-2-4: Listing the contents of the Root directory with the ls command<\/figcaption><\/figure>\n<p>You can check that the listed directories and files are the same we can see in the graphical user interface on the same machine. In the graphical user interface, the Root folder is called &#8220;File System&#8221;.<\/p>\n<figure id=\"attachment_83\" aria-describedby=\"caption-attachment-83\" style=\"width: 600px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/graphical_root_directory_contents.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-83 size-full\" src=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/graphical_root_directory_contents.png\" alt=\"Listing the contents of the Root directory with the Ubuntu graphical interface\" width=\"600\" height=\"389\" srcset=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/graphical_root_directory_contents.png 600w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/graphical_root_directory_contents-300x195.png 300w\" sizes=\"auto, (max-width: 600px) 85vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-83\" class=\"wp-caption-text\">Figure 2-2-5: Listing the contents of the Root directory with the Ubuntu graphical interface<\/figcaption><\/figure>\n<p>As you can see, the Root directory contains a number of files and folders. These are created at the time of system installation. During this course we will become familiar with some of these locations. For now, we can remind that the <strong>home<\/strong> folder in the root directory contains the users folders, one for each user, with the same name as the user. The <strong>etc<\/strong> folder contains important configuration files, for the various software packages installed on Linux. For example, the configuration files for the Apache web server software are located in:<\/p>\n<p>\/etc\/apache2\/<\/p>\n<p>while the <strong>php.ini<\/strong> file, important for the configuration of PHP, is located in a directory whose name is, or starts with, &#8220;php&#8221;, located within the \/etc directory. The exact location varies according to the PHP version installed on your Linux OS. For example, for PHP 5 the location was:<\/p>\n<p>\/etc\/php5\/apache2\/php.ini<\/p>\n<p>while for PHP 7, the location is:<\/p>\n<p>\/etc\/php\/7.0\/apache2\/php.ini <\/p>\n<p>Actually the configuration files for Apache and PHP will only be present on the machine after we have installed a LAMP server (<strong>L<\/strong>inux, <strong>A<\/strong>pache, <strong>P<\/strong>HP, <strong>M<\/strong>ySql server).<\/p>\n<h2>The cd shell command to change directory<\/h2>\n<p>Let us introduce the Change Directory &#8220;cd&#8221; command, that allows us to change our present working directory and move around in the file system. If called with no arguments, the cd command will return us to our default directory, our home directory. Lost in the file system? Here is a neat trick: just type cd and hit the return key to go back home.<\/p>\n<p>andrea@ubuntu:~$ cd<\/p>\n<p>We can call &#8220;cd&#8221; by supplying an absolute or relative (we&#8217;ll come to those in a moment) path to a directory in the filesystem. For example:<\/p>\n<p>andrea@ubuntu:~$ cd \/etc<\/p>\n<p>will move us to the \/etc directory.<\/p>\n<p>We can then list the current directory contents with &#8220;ls&#8221;, with no arguments. This shell session is shown in the next figure. Note how, when we move to the \/etc directory with the cd command, the propt line changes from:<\/p>\n<p>andrea@ubuntu:~$<\/p>\n<p>to<\/p>\n<p>andrea@ubuntu:\/etc$<br \/>\nto reflect our new current directory location.<\/p>\n<figure id=\"attachment_84\" aria-describedby=\"caption-attachment-84\" style=\"width: 610px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/shell_session1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-84 size-full\" src=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/shell_session1.png\" alt=\"A shell session\" width=\"610\" height=\"777\" srcset=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/shell_session1.png 610w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/shell_session1-236x300.png 236w\" sizes=\"auto, (max-width: 610px) 85vw, 610px\" \/><\/a><figcaption id=\"caption-attachment-84\" class=\"wp-caption-text\">Figure 2-2-6: A shell session<\/figcaption><\/figure>\n<p>Please note, in the listing of the \/etc content, the apache2 folder (only available after the apache web server installation). As already mentioned before, this is the directory that contains all the apache web server configuration files. We will spend some time discussing those files and the apache configuration later in this chapter.<\/p>\n<h2>Linux Relative paths<\/h2>\n<p>The absolute path is the path of a file with respect to the root (\/) folder. <strong>All absolute paths start with a slash. If a path starts with a slash, it is an absolute path.<\/strong> It&#8217;s good to have some fixed reference points in life, this is one.<\/p>\n<p>A relative path is the position of a file\/directory with respect to another directory different from root. It could be our present working directory or to the directory a script is executing from, for example. Relative paths never start with a slash. Let us consider the example situation in the next figure.<\/p>\n<figure id=\"attachment_85\" aria-describedby=\"caption-attachment-85\" style=\"width: 809px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/linux_filesystem_example.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-85 size-full\" src=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/linux_filesystem_example.png\" alt=\"sample linux filesystem\" width=\"809\" height=\"652\" srcset=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/linux_filesystem_example.png 809w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/linux_filesystem_example-300x242.png 300w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/linux_filesystem_example-768x619.png 768w\" sizes=\"auto, (max-width: 809px) 85vw, 809px\" \/><\/a><figcaption id=\"caption-attachment-85\" class=\"wp-caption-text\">Figure 2-2-7: sample linux filesystem<\/figcaption><\/figure>\n<p>The figure represents a linux filesystem with a root directory &#8220;\/&#8221;, a number of child directories, including &#8220;etc&#8221; and &#8220;home&#8221; that we are already somewhat familiar with as the first contains configuration files for a number of Linux applications, including the web server apache (when installed), and the second contains the user&#8217;s home directories.<\/p>\n<p>In this example we have four users: andrea (home directory \/home\/andrea), joe (home directory \/home\/joe), anne and carl. Each user&#8217;s home directory also contains a folder called &#8220;seqs&#8221; that in turn contains two subfolders called &#8220;dna&#8221; and &#8220;protein&#8221;. In the figure we have only represented the &#8220;seqs&#8221; folders of joe and carl.<\/p>\n<p>Let&#8217;s imagine joe logs into the machine by remote ssh. He will see a prompt similar to this one:<\/p>\n<p>joe@ubuntu:~$<\/p>\n<p>the absolute path of his present working directory will be:<\/p>\n<p>\/home\/joe<\/p>\n<p>the relative path of joe&#8217;s present working directory will be, instead, just a dot:<\/p>\n<p>.<\/p>\n<p>the relative path of the \/home\/joe parent directory, that is the \/home directory, relatively to joe&#8217;s home directory \/home\/joe is indicated by two dots:<\/p>\n<p>..<\/p>\n<p>The command<\/p>\n<p>cd ..<\/p>\n<p>brings us &#8220;up one directory&#8221; in the filesystem hierarchy.<\/p>\n<p>So, back to joe&#8217;s example, if joe now types:<\/p>\n<p>joe@ubuntu:~$ cd ..<\/p>\n<p>he will change his working directory from \/home\/joe to \/home. This will reflect in the prompt:<\/p>\n<p>joe@ubuntu:\/home$ pwd<\/p>\n<p>\/home<\/p>\n<p>joe@ubuntu:\/home$ <\/p>\n<p>joe can now type &#8220;cd&#8221; without arguments to go back to his home directory \/home\/joe:<br \/>\njoe@ubuntu:\/home$ cd<\/p>\n<p>joe@ubuntu:~$<\/p>\n<p>So we now know how to use the &#8220;cd&#8221; command in combination with a relative path in order to move up one directory (cd ..) or stay where we are (cd .). You may notice that latter one is exquisitely useless in practice, although it makes sense to mention it here, for educational purposes. Please note that each directory can contain several other directories, called the <strong>child directories<\/strong>, but can only have one single <strong>parent directory<\/strong>.<\/p>\n<p>How can joe move to his seqs folder (see figure 2-2-7)? What is the relative path of \/home\/joe\/seqs with respect to \/home\/joe?<\/p>\n<p>This is especially easy, it is simply:<\/p>\n<p>seqs<\/p>\n<p>or, which is equivalent:<\/p>\n<p>.\/seqs<\/p>\n<p>in which the dot stands for the current directory, the slash is a separator, and seqs is the seqs folder.<\/p>\n<p>You should start to get the feel of what a relative path is. Let&#8217;s further clarify this through some examples, in which pwd is the our present location (present working directory) and target is the directory of which we need to know the relative path, with respect to our present location in the filesystem.<\/p>\n<p><strong>pwd<\/strong>: \/home\/joe<br \/>\n<strong>target<\/strong>: \/home\/joe\/seqs\/protein<br \/>\n<strong>relative path<\/strong>: seqs\/protein<\/p>\n<p><strong>pwd<\/strong>: \/home\/joe<br \/>\n<strong>target<\/strong>: \/home\/carl<br \/>\n<strong>relative path<\/strong>: ..\/carl<\/p>\n<p><strong>pwd<\/strong>: \/home\/joe\/seqs\/protein<br \/>\n<strong>target<\/strong>: \/home\/carl\/seqs\/protein<br \/>\n<strong>relative path<\/strong>: ..\/..\/..\/carl\/seqs\/protein<\/p>\n<p><strong>pwd<\/strong>: \/<br \/>\n<strong>target<\/strong>: \/ect\/apache2<br \/>\n<strong>relative path<\/strong>: etc\/apache2<\/p>\n<p><strong>pwd<\/strong>: \/home\/joe\/seqs\/dna<br \/>\n<strong>target<\/strong>: \/home\/joe\/seqs\/protein<br \/>\n<strong>relative path<\/strong>: ..\/protein<\/p>\n<p>We encourage you to carefully understand each one of these examples, also by referring to figure 2-2-7 to get a &#8220;visual&#8221; scheme of what is going on.<\/p>\n<p>Since the absolute path is able to locate univocally a file\/directory in the filesystem, you may wonder why there is the need for such a thing as a relative path and all these dots notations.<\/p>\n<p>The answer is that this is extremely useful when you want to make things &#8220;portable&#8221; for example from one computer to another, from a user account to another, or simply to change the location of a folder within your own account.<\/p>\n<p><a href=\"http:\/\/www.thefreedictionary.com\/Portability\" target=\"_blank\">Portability<\/a>: <em>&#8220;Relating to or being software that can run on two or more kinds of computers or with two or more kinds of operating systems.&#8221;<\/em><\/p>\n<p>It is quite common to have all the files composing a software project, grouped in a folder. For example a folder &#8220;website1&#8221; could contain a number of .html files for a website, and a subfolder called &#8220;images&#8221; with all the image files for the same website. The html files contain pointers to image files in the &#8220;images&#8221; folder. If these pointers are coded as relative paths<\/p>\n<p>images\/image1.png<\/p>\n<p>instead of as absolute paths<\/p>\n<p>\/home\/joe\/public_html\/website1\/images\/image1.png<\/p>\n<p>and similarly, all the links between the web pages in the folder are typically coded as relative<\/p>\n<p>page1.html<\/p>\n<p>instead of as absolute<\/p>\n<p>\/home\/joe\/public_html\/website1\/page1.html<\/p>\n<p>when you move the folder around in the filesystem, or even to a different PC, all the pointers and links between the various html files will still be valid, while the same is obviously not true if the links are coded as absolute paths.<\/p>\n<p>By now you should have a solid basic understanding of what the Linux filesystem is, and how you can move around with the <strong>cd<\/strong> command and list directories and files with <strong>ls<\/strong>. You can use this knowledge to start to have a look at your linux filesystem. If you are lost, just type <strong>pdw<\/strong> to know your current directory. Type cd and hit the return key to go back home.<\/p>\n<h2>More on Linux files: invisible files, ownership and permission<\/h2>\n<p>We have seen that using the ls command returns a list of the filenames of the files contained within our present working directory (figure 2-6) or in the directory we supply the path as argument to ls.<\/p>\n<p>As with many commands in Linux, we can however call &#8220;ls&#8221; with some additional options. Calling &#8220;ls&#8221; with options will modify the kind of output we get from the command. There are two options that are particularly useful:<\/p>\n<p>&#8211; the &#8220;l&#8221; option, that gives an output with a file for each line, with a number of details on the file<br \/>\n&#8211; the &#8220;a&#8221; option, that lists the invisible files in addition to the visible files. In Linux, an invisible file is a file whose name starts with a dot. You can make a file &#8220;invisible&#8221; by adding a dot at the beginning of the file name.<\/p>\n<p>We can call &#8220;ls&#8221; with both the &#8220;l&#8221; and the &#8220;a&#8221; options, like this:<\/p>\n<p>andrea@ubuntu:~$ ls -la<\/p>\n<p>Let&#8217;s have a look to a sample output<\/p>\n<figure id=\"attachment_86\" aria-describedby=\"caption-attachment-86\" style=\"width: 560px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-86\" src=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/linux_ls-la_command_sample_output.png\" alt=\"Listing files with ls -la\" width=\"560\" height=\"560\" srcset=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/linux_ls-la_command_sample_output.png 560w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/linux_ls-la_command_sample_output-150x150.png 150w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/linux_ls-la_command_sample_output-300x300.png 300w\" sizes=\"auto, (max-width: 560px) 85vw, 560px\" \/><figcaption id=\"caption-attachment-86\" class=\"wp-caption-text\">Figure 2-2-8: Listing files with ls -la<\/figcaption><\/figure>\n<p>We now have a output organized in several lines, one for each file, and several columns, that list different properties of the file. In order to be able to administer our Linux machine we need to fully understand this output.<\/p>\n<figure id=\"attachment_87\" aria-describedby=\"caption-attachment-87\" style=\"width: 1091px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-87\" src=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_the_linux_ls-la_output.png\" alt=\"Understanding the ls -la output\" width=\"1091\" height=\"498\" srcset=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_the_linux_ls-la_output.png 1091w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_the_linux_ls-la_output-300x137.png 300w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_the_linux_ls-la_output-768x351.png 768w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_the_linux_ls-la_output-1024x467.png 1024w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption id=\"caption-attachment-87\" class=\"wp-caption-text\">Figure 2-2-9: Understanding the ls -la output<\/figcaption><\/figure>\n<p>The last column contains the file name. Please note, in figure 2-2-9 the first two files: &#8220;.&#8221; and &#8220;..&#8221;. These indicate, with the relative path notation we are now familiar with, the current directory and it&#8217;s parent directory.<\/p>\n<p>We then have a few invisible files listed (because we used the &#8220;a&#8221; option with the &#8220;ls&#8221; command&#8221;) such as .bash_history and .bash_logout. They are invisible because their names start with a dot. This has nothing to do with the dot that indicates the current directory, by the way.<\/p>\n<h3>File types<\/h3>\n<p>We also see a file called &#8220;Desktop&#8221;. This is a directory. Indeed, in Linux a directory is just a particular type of file.<\/p>\n<p><em>Table 2-2-2: Linux file types<\/em><\/p>\n<p><strong>&#8211;<\/strong> Regular file<br \/>\n<strong>d <\/strong>Directory<br \/>\n<strong>l<\/strong> Link<br \/>\n<strong>c<\/strong> Special file<br \/>\n<strong>s<\/strong> Socket<br \/>\n<strong>p<\/strong> Pipe<br \/>\n<strong>b<\/strong> Block device<\/p>\n<p>To know the type of one of the files listed with ls -l we can look at the very first character of each line, see the following two examples:<\/p>\n<p>drwxr-xr-x 6 andrea andrea 4096 2011-03-23 06:23 Desktop<\/p>\n<p>-rw-r&#8211;r&#8211; 1 andrea andrea 3103 2010-10-31 20:06 .bashrc<\/p>\n<p>The first file is a directory, because the first character is a &#8220;d&#8221;. The second file is a regular file, because the first character is a &#8220;-&#8220;. For the purposes of this course, regular files and directories are the only file types we will need to deal with.<\/p>\n<h3>File permissions<\/h3>\n<p>Following the first character, we have other 9 characters that define the file&#8217;s read, write and execute permissions for the owner, the group, everybody else. These &#8220;rwxr-xr-x&#8221; notations might seem complicated at first. The goal of the next paragraph is to explain how this works, in simple terms.<\/p>\n<figure id=\"attachment_88\" aria-describedby=\"caption-attachment-88\" style=\"width: 842px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-88\" src=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_777.png\" alt=\"Understanding Linux files permissions - The 777 permission\" width=\"842\" height=\"455\" srcset=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_777.png 842w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_777-300x162.png 300w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_777-768x415.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption id=\"caption-attachment-88\" class=\"wp-caption-text\">Figure 2-2-10: Understanding Linux files permissions &#8211; The 777 permission<\/figcaption><\/figure>\n<p>As we can see in figure 2-2-10, there are also some numeric notations we need to deal with. We&#8217;ll come to those in a moment. For now, let us concentrate on the first two lines of figure 2-2-10. The orange line shows the nine characters. They are in fact three groups of three characters each. The first group of three characters defines the permissions for the file&#8217;s owner. Let&#8217;s look closely at these three characters, one by one.<\/p>\n<p>&#8211; The first can be either &#8220;r&#8221;, which indicates <strong>read permission<\/strong>, or &#8220;-&#8220;, which indicates no read permission.<br \/>\n&#8211; The second can be &#8220;w&#8221;, which indicates <strong>write permission<\/strong>, or &#8220;-&#8220;, which indicates no write permission<br \/>\n&#8211; The third can be a &#8220;x&#8221;, which indicates <strong>execute permission<\/strong>, or &#8220;-&#8221; which indicates no execute permission<br \/>\nIn the example in figure 2-10, the owner has a &#8220;rwx&#8221; permission, which means he can read, write and execute the file. If he could only read and write, but not execute, this would have been &#8220;rw-&#8220;, as in the example in figure 2-11.<\/p>\n<figure id=\"attachment_89\" aria-describedby=\"caption-attachment-89\" style=\"width: 845px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_644.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-89\" src=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_644.png\" alt=\"Understanding Linux files permissions - The 644 permission\" width=\"845\" height=\"451\" srcset=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_644.png 845w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_644-300x160.png 300w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_644-768x410.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption id=\"caption-attachment-89\" class=\"wp-caption-text\">Figure 2-2-11: Understanding Linux files permissions &#8211; The 644 permission<\/figcaption><\/figure>\n<p>Numeric scores are associated to these read, write and execute permission. Read is worth a 4, write a 2, execute a 1. The final score is a single number, the sum of the three individual scores. Let us make some examples:<\/p>\n<p>r w x = 4 + 2 + 1 = <strong>7<\/strong><\/p>\n<p>r &#8211; x = 4 + 0 + 1 = <strong>5<\/strong><\/p>\n<p>r w &#8211; = 4 + 2 + 0 = <strong>6<\/strong><\/p>\n<p>r &#8211; &#8211; = 4 + 0 + 0 = <strong>4<\/strong><\/p>\n<p>This three characters scheme is repeated for the owner of the file, the group, and everyone else (others), this is why we have 9 characters to define permissions in the output of the ls -l command.<\/p>\n<p>For each group of three, we can summarize the permission with a single number, as just shown. So the final permission for a file becomes a group of three numbers, such as for example &#8220;777&#8221; (figure 2-2-10), &#8220;644&#8221; (figure 2-2-11) or &#8220;755&#8221; (figure 2-2-12).<\/p>\n<figure id=\"attachment_92\" aria-describedby=\"caption-attachment-92\" style=\"width: 844px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_755.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-92\" src=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_755.png\" alt=\"Understanding Linux files permissions - The 755 permission\" width=\"844\" height=\"458\" srcset=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_755.png 844w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_755-300x163.png 300w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/01\/understanding_linux_files_permissions_755-768x417.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption id=\"caption-attachment-92\" class=\"wp-caption-text\">Figure 2-2-12: Understanding Linux files permissions &#8211; The 755 permission<\/figcaption><\/figure>\n<p>Permissions for a file can be changed with the<\/p>\n<p>chmod<\/p>\n<p>command. This will be discussed in the next section <a href=\"\/bioinformatics_web_development\/chapter-2-the-linux-operating-system-setting-up-a-linux-web-server\/basic-linux-shell-commands\/\">Basic Linux Shell Commands<\/a>.<\/p>\n<p>If you want to learn more on Linux file permission, we suggest you visit the excellent <a href=\"http:\/\/www.tuxfiles.org\/linuxhelp\/filepermissions.html\">files permissions page on Tuxfiles<\/a><\/p>\n<p>Moving around in the filesystem is not enough. You need to learn a few commands in order to be able to change things on your computer, such as creating and editing files, renaming files and directories and moving them around, creating and deleting users, changing files permissions and ownerships, installing and updating software and more. Let&#8217;s move on and learn the <a href=\"\/bioinformatics_web_development\/chapter-2-the-linux-operating-system-setting-up-a-linux-web-server\/basic-linux-shell-commands\/\">Basic Linux Shell Commands<\/a>.<\/p>\n<div class=\"google-ad\">\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- bioinfo web dev 2 --><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:inline-block;width:728px;height:90px\"\n     data-ad-client=\"ca-pub-0159360445983090\"\n     data-ad-slot=\"3442176918\"><\/ins><br \/>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n<\/div>\n<h2>Chapter Sections<\/h2>\n<p>[pagelist include=&#8221;63&#8243;]<\/p>\n<p>[siblings]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>On approaching Linux systems for the first time, it is essential to understand how files and directories are organized in a Linux system and how to refer to a particular file or directory in order to perform actions. In order to refer to file or directory we need to know it&#8217;s relative or absolute path &hellip; <a href=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/chapter-2-the-linux-operating-system-setting-up-a-linux-web-server\/the-linux-filesystem\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;2-2: The Linux Filesystem&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":63,"menu_order":2,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-79","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/pages\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/comments?post=79"}],"version-history":[{"count":48,"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/pages\/79\/revisions"}],"predecessor-version":[{"id":2544,"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/pages\/79\/revisions\/2544"}],"up":[{"embeddable":true,"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/pages\/63"}],"wp:attachment":[{"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/media?parent=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}