{"id":10822,"date":"2024-12-12T07:14:22","date_gmt":"2024-12-12T07:14:22","guid":{"rendered":"https:\/\/blog.trustedhosting.in\/?p=10822"},"modified":"2024-12-12T07:14:22","modified_gmt":"2024-12-12T07:14:22","slug":"navigating-around-a-linux-system","status":"publish","type":"post","link":"https:\/\/www.webystrata.com\/blog\/navigating-around-a-linux-system\/","title":{"rendered":"Navigating around a Linux system"},"content":{"rendered":"<h1><a href=\"https:\/\/www.trustedhosting.in\/reseller-hosting.html\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-10824 size-full\" title=\"Navigating around a Linux system\" src=\"https:\/\/blog.trustedhosting.in\/wp-content\/uploads\/2024\/12\/99363.jpg\" alt=\"Navigating around a Linux system\" width=\"1500\" height=\"1000\" srcset=\"https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/99363.jpg 1500w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/99363-300x200.jpg 300w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/99363-1024x683.jpg 1024w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/99363-768x512.jpg 768w\" sizes=\"auto, (max-width: 1500px) 100vw, 1500px\" \/><\/a><\/h1>\n<h1>Navigating around a Linux system<\/h1>\n<p>Navigating a Linux <a href=\"https:\/\/www.trustedhosting.in\/reseller-hosting.html\" target=\"_blank\" rel=\"noopener\">server<\/a> using SSH for the first time can be a very daunting experience for those coming from a predominantly Windows \/ GUI background. The principal difference from having a user interface is that you will not have a desktop, both in the visual sense and in that there is no common area to launch programs from in the way that you may be used to.<\/p>\n<p>Linux is primarily interacted with using the Bash shell. On logging in you will be in your user\u2019s home folder, for example if logging in as the user\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">graphiterack<\/span><\/code>\u00a0you will be in\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">\/home\/graphiterack<\/span><\/code>. The exception to this is the\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">root<\/span><\/code>\u00a0user,\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">root<\/span><\/code>\u00a0is akin to the administrator user in other operating systems and has permission to change anything on the system and always logs in to\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">\/root<\/span><\/code>.<\/p>\n<p>You can always find your current location using the\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">pwd<\/span><\/code>\u00a0command like so:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[centos@arthas centos]# <\/span><span class=\"nb\">pwd<\/span>\r\n<span class=\"go\">\/home\/centos<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<section id=\"getting-around\">\n<h2>Getting around<\/h2>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">cd<\/span><\/code>\u00a0will be your primary method of traversing the system. As you may have guessed,\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">cd<\/span><\/code>\u00a0stands for change directory. This command is used in conjunction with a file path to change to that directory, for example:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">cd \/home\/graphiterack\/<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">cd<\/span><\/code>\u00a0can also be used to go up a folder in the system when used with two dots<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"go\">cd ..<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>Once you are in a directory you can view it\u2019s contents using the command\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">ls<\/span><\/code>.<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[cloud-user@arthas ~]$ <\/span>ls\r\n<span class=\"go\">python  sampleFile.txt  test<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>Extra details can be seen with the command\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">ls<\/span>\u00a0<span class=\"pre\">-l<\/span><\/code>\u00a0which is commonly aliased to\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">ll<\/span><\/code>\u00a0in RHEL \/ CentOS based systems.<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[cloud-user@arthas ~]$ <\/span>ls -l\r\n<span class=\"go\">total 12<\/span>\r\n<span class=\"go\">drwxr-xr-x. 3 cloud-user cloud-user 4096 Jan 15 12:55 python<\/span>\r\n<span class=\"go\">-rw-rw-r--. 1 cloud-user cloud-user  101 Apr  6 05:59 sampleFile.txt<\/span>\r\n<span class=\"go\">drwxrwxr-x. 2 cloud-user cloud-user 4096 Apr  6 07:19 test<\/span>\r\n<span class=\"gp\">[cloud-user@arthas ~]$ <\/span>ll\r\n<span class=\"go\">total 12<\/span>\r\n<span class=\"go\">drwxr-xr-x. 3 cloud-user cloud-user 4096 Jan 15 12:55 python<\/span>\r\n<span class=\"go\">-rw-rw-r--. 1 cloud-user cloud-user  101 Apr  6 05:59 sampleFile.txt<\/span>\r\n<span class=\"go\">drwxrwxr-x. 2 cloud-user cloud-user 4096 Apr  6 07:19 test<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>As you can see here, both outputs are the same as it is a CentOS server.<\/p>\n<\/section>\n<section id=\"viewing-files\">\n<h2>Viewing files<\/h2>\n<p>There are many way to view files in Linux, here we will cover the two most common ways that are found on the majority of Linux systems.<\/p>\n<section id=\"cat\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">cat<\/span><\/code><\/h3>\n<p>The\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">cat<\/span><\/code>\u00a0utility can be used for a variety of operations, however in this article we will be using it in the most simple form\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">cat<\/span>\u00a0<span class=\"pre\">{filename}<\/span><\/code>. This will simply print he contents of the file to the console window as so:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[cloud-user@arthas ~]$ <\/span>cat sampleFile.txt\r\n<span class=\"go\">This is an example file<\/span>\r\n<span class=\"go\">There are many like it but this one is mine<\/span>\r\n<span class=\"go\">It has several lines<\/span>\r\n<span class=\"go\">and bacon.<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">cat<\/span><\/code>\u00a0is useful for quickly viewing small files that do not need to be edited.<\/p>\n<\/section>\n<section id=\"less\">\n<h3>less<\/h3>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">less<\/span><\/code>\u00a0is another common utility used to view the contents of files.\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">less<\/span><\/code>\u00a0is useful for viewing files that are potentially very large and as such would not be easily viewed with\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">cat<\/span><\/code>. Unlike\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">cat<\/span><\/code>\u00a0which simply prints to standard output\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">less<\/span><\/code>\u00a0is an interactive file viewer that will open the file for viewing in a new screen. It can be opened with the command\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">less<\/span>\u00a0<span class=\"pre\">{filename}<\/span><\/code>.<\/p>\n<p>When viewing a file in\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">less<\/span><\/code>\u00a0it will be broken up into pages if the length of the file exceeds the size of your console window. These pages can be navigated with\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">Page<\/span>\u00a0<span class=\"pre\">Up<\/span><\/code>\u00a0and\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">Page<\/span>\u00a0<span class=\"pre\">Down<\/span><\/code>. The file can also be searched with\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">\/<\/span><\/code>\u00a0and\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">?<\/span><\/code>\u00a0to search up and down the pages respectively.<\/p>\n<\/section>\n<\/section>\n<section id=\"creating-files\">\n<h2>Creating files<\/h2>\n<p>The easiest way to create a file in any Linux directory is to use the\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">touch<\/span><\/code>\u00a0command as follows:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[cloud-user@arthas test]$ <\/span>touch exampleFile.txt\r\n<span class=\"gp\">[cloud-user@arthas test]$ <\/span>ls\r\n<span class=\"go\">exampleFile.txt<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>This will create a blank file owned by the user that you are logged into the system with, these can then be edited with the text editor of your choice.<\/p>\n<\/section>\n<section id=\"editing-files\">\n<h2>Editing files<\/h2>\n<p>Linux has many text editors available for use, the most common two being\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">nano<\/span><\/code>\u00a0and\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">vi<\/span><\/code>, each editor is worthy of an entire article to themselves however we will touch upon the basics of each here.<\/p>\n<section id=\"nano\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">nano<\/span><\/code><\/h3>\n<p>To open a file in\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">nano<\/span><\/code>\u00a0you simply need to type\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">nano<\/span><\/code>\u00a0followed by the name of the file you wish to edit. In the following example I have used\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">nano<\/span>\u00a0<span class=\"pre\">sampleFile.txt<\/span><\/code>.<\/p>\n<p><a href=\"https:\/\/www.trustedhosting.in\/reseller-hosting.html\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-10823 size-full\" title=\"Navigating around a Linux system\" src=\"https:\/\/blog.trustedhosting.in\/wp-content\/uploads\/2024\/12\/nano1.png\" alt=\"Navigating around a Linux system\" width=\"693\" height=\"384\" srcset=\"https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/nano1.png 693w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/nano1-300x166.png 300w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/a><\/p>\n<section id=\"nano\">You can interact with\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">nano<\/span><\/code>\u00a0in the same was as any regular text editor, instructions for operations are outlined at the bottom of the window. These can be performed by holding\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">Ctrl<\/span><\/code>\u00a0and pressing the specified letter.<\/p>\n<\/section>\n<section id=\"vi-vim\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">vi<\/span><\/code>\/<code class=\"docutils literal notranslate\"><span class=\"pre\">vim<\/span><\/code><\/h3>\n<p>To open a file in\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">vi<\/span><\/code>\u00a0is the same as\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">nano<\/span><\/code>\u00a0simply type\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">vi<\/span>\u00a0<span class=\"pre\">{filename}<\/span><\/code>, however this is where the similarities end.<\/p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">vi<\/span><\/code>\u00a0operates in two modes, command and input. The program will launch in command mode, to edit the file you will need to enter input mode. This can be done by pressing\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">i<\/span><\/code>. Once in input mode you can edit text as you need to, to return to command mode hit\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">esc<\/span><\/code>. In command mode you can issue\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">:wq<\/span><\/code>\u00a0to save your edits and exit the file.<\/p>\n<\/section>\n<\/section>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Navigating around a Linux system Navigating a Linux server using SSH for the first time can be a very daunting&hellip;<\/p>\n","protected":false},"author":1,"featured_media":10824,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-10822","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/posts\/10822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/comments?post=10822"}],"version-history":[{"count":3,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/posts\/10822\/revisions"}],"predecessor-version":[{"id":10827,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/posts\/10822\/revisions\/10827"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/media\/10824"}],"wp:attachment":[{"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/media?parent=10822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/categories?post=10822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/tags?post=10822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}