{"id":17611,"date":"2023-09-15T13:11:41","date_gmt":"2023-09-15T11:11:41","guid":{"rendered":"https:\/\/contabo.com\/blog\/?p=17611"},"modified":"2023-09-15T13:11:45","modified_gmt":"2023-09-15T11:11:45","slug":"linux-navigation-and-file-management","status":"publish","type":"post","link":"https:\/\/contabo.com\/blog\/linux-navigation-and-file-management\/","title":{"rendered":"Linux Navigation and File Management"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/blog-head_linux-navigation-and-file-management.jpg\" alt=\"Linux Navigation and File Management\u00a0 (head image)\" class=\"wp-image-17612\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/blog-head_linux-navigation-and-file-management.jpg 1200w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/blog-head_linux-navigation-and-file-management-600x315.jpg 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/blog-head_linux-navigation-and-file-management-768x403.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>If you are new to Linux, finding your way around and organizing files is very high on the to do list. Linux is different from Windows or macOS in that it often does not rely on graphical user interfaces (GUIs), making command-line skills essential for a smooth experience.&nbsp;<\/p>\n\n\n\n<p>In Linux, you do many tasks through the command line. This includes keeping your files organized, <a href=\"https:\/\/contabo.com\/blog\/the-importance-of-patching-and-patching-best-practices-linux-windows\/\" target=\"_blank\" rel=\"noreferrer noopener\">updating software<\/a>, and troubleshooting issues. So, mastering file management through text commands is the key to becoming a Linux-Pro.&nbsp;<\/p>\n\n\n\n<p>However, Linux is incredibly versatile. While it typically does not have a graphical interface like Windows or macOS, you have the option to run a desktop environment on a Linux system. If you are interested in learning how to set up a GUI on Linux, including Ubuntu and CentOS, we have a dedicated article on &#8220;<a href=\"https:\/\/contabo.com\/blog\/how-to-install-a-gui-and-xrdp-on-ubuntu-and-centos\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Install a GUI and XRDP on Ubuntu and CentOS<\/a>&#8220;. This can help you bridge the gap between the GUI-centric world of Windows and macOS and the command-line-focused environment of Linux. But now, let us focus on managing Linux through the command-line:&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-getting-started-introduction-to-the-linux-terminal\">Getting Started: Introduction to the Linux Terminal<\/h2>\n\n\n\n<p>Welcome to the world of Linux! As you start your journey to master Linux navigation and file management, one tool will become your trusty companion: the Linux terminal.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-the-linux-terminal-your-command-center-nbsp\">The Linux Terminal: Your Command Center&nbsp;<\/h3>\n\n\n\n<p>The Linux terminal, often referred to as the command line, is where the real magic happens in the Linux universe. Unlike the familiar graphical interfaces of Windows or macOS, the terminal operates entirely through text commands. It is a powerful tool that gives you direct control over your Linux system, allowing you to perform a wide range of tasks, including file management, system configuration, and software installations.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-establishing-an-ssh-connection-nbsp\">Establishing an SSH Connection&nbsp;<\/h3>\n\n\n\n<p>Before we can start using the terminal, let us address a crucial step when working with a Linux server: establishing an SSH (Secure Shell) connection. This step is essential because it is how you connect to your Linux server securely.&nbsp;<\/p>\n\n\n\n<p>For step by step guidance on establishing an SSH connection, we have a dedicated article titled \u201c<a href=\"https:\/\/contabo.com\/blog\/establishing-connection-server-ssh\/\" target=\"_blank\" rel=\"noreferrer noopener\">Establishing a Connection to Your Server via SSH<\/a>&#8220;.&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>To connect to your server via SSH, you have several options:&nbsp;<\/p>\n\n\n\n<p>1. <strong>Built-In Tools:<\/strong> On Windows, you can use Windows PowerShell, while on macOS and Linux desktops, you can use the built-in terminal. These are convenient options for connecting to your server securely.&nbsp;<\/p>\n\n\n\n<p>Use the following command-structure to connect to your server via SSH using the build-in tools:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh &#91;username]@&#91;server_ip_address]<\/code><\/pre>\n\n\n\n<p><em>Of course, replace [username] with your username and [server_ip_address] with the IP address or hostname of the remote server&nbsp;<\/em>&nbsp;<\/p>\n\n\n\n<p>2. <strong>Third-Party Software:<\/strong> If you prefer third-party software, <a href=\"https:\/\/www.putty.org\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">PuTTY<\/a> is a popular choice for Windows users. It provides a user-friendly interface for SSH connections and is widely used in the Linux community.&nbsp;<\/p>\n\n\n\n<p>With your SSH connection established, you will be ready to dive into the Linux terminal and start your exploration of file management and navigation. Let us get started!&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-basic-linux-commands\">Basic Linux Commands<\/h2>\n\n\n\n<p>Now that you are familiar with how to establish an SSH connection, let\u2019s look at some essential Linux commands. These will serve as your foundation for navigating and managing files and directories in Linux. This chapter will give you basic information on the most important commands when it comes to managing your server. We will discuss all the commands and their syntax in later chapters.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-pwd-print-working-directory\">1. pwd (Print Working Directory)<\/h3>\n\n\n\n<p>The pwd command is your GPS in the Linux file system. It shows you the path to your current directory, helping you understand where you are in the directory tree.&nbsp;<\/p>\n\n\n\n<p>Usage:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pwd<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2-ls-list-files-and-directories-nbsp\">2. ls (List Files and Directories)&nbsp;<\/h3>\n\n\n\n<p>The ls command is used to list the files and directories in the current directory. It provides an overview of what is inside a folder.&nbsp;&nbsp;<\/p>\n\n\n\n<p>Usage:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-cd-change-directory-nbsp\">3. cd (Change Directory)&nbsp;<\/h3>\n\n\n\n<p>The cd command is your ticket to move around the file system. It lets you change your current directory to another location.&nbsp;&nbsp;<\/p>\n\n\n\n<p><strong>Usage (Moving to a directory):&nbsp;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/path\/to\/directory&nbsp;<\/code><\/pre>\n\n\n\n<p><strong>Usage (Moving up one directory):&nbsp;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ..&nbsp;<\/code><\/pre>\n\n\n\n<p><strong>Usage (Moving to your home directory):&nbsp;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ~&nbsp;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-4-mkdir-make-directory-nbsp\">4. mkdir (Make Directory)&nbsp;<\/h3>\n\n\n\n<p>Need to create a new directory? The mkdir command is here to help. It allows you to make a new folder in the current directory.&nbsp;<\/p>\n\n\n\n<p>Usage:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir &#91;name]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-5-touch-create-empty-file-nbsp\">5. touch (Create Empty File)&nbsp;<\/h3>\n\n\n\n<p>When you need to create a new, empty file, use the touch command. It is a quick way to generate files for various purposes.&nbsp;<\/p>\n\n\n\n<p>Usage:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch &#91;name]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-6-rm-remove-files-and-directories-nbsp\">6. rm (Remove Files and Directories)&nbsp;<\/h3>\n\n\n\n<p>The rm command is for deleting files and directories. Be cautious when using it, as it permanently removes files, and deleted data cannot be easily recovered.&nbsp;<\/p>\n\n\n\n<p>Usage (Removing a file):&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm file_name&nbsp;<\/code><\/pre>\n\n\n\n<p>Usage (Removing a directory and its contents):&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm -r directory_name&nbsp;<\/code><\/pre>\n\n\n\n<p>These are fundamental Linux commands that will help you navigate, organize, and manage files and directories effectively. As you become more comfortable with these basics, you will be well-prepared to explore more advanced Linux file management techniques.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-navigating-the-linux-file-system\">Navigating the Linux File System<\/h2>\n\n\n\n<p>To become skilled in Linux navigation and file management, it is important to understand the Linux file system&#8217;s structure. In this chapter, we will explore the fundamentals of the Linux file structure and show the significance of the root directory (&#8220;\/&#8221;).&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-understanding-the-linux-file-structure-nbsp\">Understanding the Linux File Structure&nbsp;<\/h3>\n\n\n\n<p>Linux follows a hierarchical file system, which means it organizes files and directories in a tree-like structure. At the top of this hierarchy is the root directory (&#8220;\/&#8221;), and everything in the system stems from it. Here is a simplified breakdown:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Root Directory (&#8220;\/&#8221;):<\/strong> The top-level directory in the Linux file system. It is represented by a single forward slash (&#8220;\/&#8221;) and serves as the starting point for all paths in the system.&nbsp;<\/li>\n\n\n\n<li><strong>Subdirectories:<\/strong> Under the root directory, you will find various subdirectories, each serving a specific purpose. For example, &#8220;\/home&#8221; typically contains user directories, while &#8220;\/etc&#8221; holds system configuration files.&nbsp;<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Files: <\/strong>Files reside within directories and can include documents, programs, scripts, and more.&nbsp;<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-the-importance-of-the-root-directory\">The Importance of the Root Directory (&#8220;\/&#8221;)<\/h3>\n\n\n\n<p>The root directory (&#8220;\/&#8221;) is the heart of the Linux file system, and its significance cannot be&nbsp;overlooked. Here is why it matters:&nbsp;<\/p>\n\n\n\n<p>1. <strong>Absolute Path Reference:<\/strong> The root directory is the reference point for all absolute paths in Linux. An absolute path specifies the complete directory structure from the root directory to a specific file or directory. For example, &#8220;\/home\/user\/documents&#8221; is an absolute path, with &#8220;\/&#8221; denoting the root.&nbsp;<\/p>\n\n\n\n<p>2. <strong>System Integrity:<\/strong> Critical system files and directories, such as configuration files and essential binaries, are stored within the root directory. This separation helps maintain the system&#8217;s integrity by ensuring that essential components are easily accessible and protected from accidental deletion.&nbsp;<\/p>\n\n\n\n<p>3. <strong>User Directories:<\/strong> User home directories, where individual users store their files and configurations, are typically found as subdirectories of the root. For example, &#8220;\/home\/user1&#8221; and &#8220;\/home\/user2&#8221; represent the home directories for two different users.&nbsp;<\/p>\n\n\n\n<p>4. <strong>Resource Organization:<\/strong> The root directory helps categorize resources. For instance, system-wide configurations reside in &#8220;\/etc,&#8221; executable files in &#8220;\/bin,&#8221; and libraries in &#8220;\/lib.&#8221;&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-important-folders-in-the-linux-file-system\">Important Folders in the Linux File System<\/h2>\n\n\n\n<p>In the Linux filesystem, there are some special folders that play vital roles in keeping the system running smoothly. These folders help organize important stuff, and knowing what they are can be a real asset when you are using Linux. Let us break down these essential directories and what is inside them:&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-bin-essential-system-binaries-nbsp-nbsp\">1. \/bin &#8211; Essential System Binaries&nbsp;&nbsp;<\/h3>\n\n\n\n<p>The \/bin directory houses essential system binaries, including fundamental commands like ls, cp, and mv. These binaries are required for the system to function correctly, and they are available to all users, making it possible to perform essential tasks even in single-user mode.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2-etc-configuration-files-nbsp\">2. \/etc &#8211; Configuration Files&nbsp;<\/h3>\n\n\n\n<p>Configuration files for the system and installed software are stored in \/etc. These files control various aspects of the system&#8217;s behavior, such as network settings, user permissions, and software configurations. It is a crucial directory for system administrators.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-home-user-home-directories-nbsp\">3. \/home &#8211; User Home Directories&nbsp;<\/h3>\n\n\n\n<p>Each user on a Linux system has their own directory under \/home. For example, the home directory for the user &#8220;john&#8221; would be \/home\/john. Users store their personal files, documents, and configuration files in their respective home directories.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-4-var-variable-data-nbsp\">4. \/var &#8211; Variable Data&nbsp;<\/h3>\n\n\n\n<p>The \/var directory contains variable data that may change frequently during system operation. This includes log files, databases, and spool directories for print jobs and mail.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-5-tmp-temporary-files-nbsp-nbsp\">5. \/tmp &#8211; Temporary Files&nbsp;&nbsp;<\/h3>\n\n\n\n<p>As the name suggests, \/tmp is where temporary files are stored. These files are typically short-lived and are automatically deleted when the system reboots. It is a handy location for applications to store data temporarily.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-6-usr-user-system-resources-nbsp\">6. \/usr &#8211; User System Resources&nbsp;<\/h3>\n\n\n\n<p>The \/usr directory holds user-related system resources, including user binaries, libraries, and documentation. It is often mounted as a separate file system, allowing system administrators to keep it consistent across multiple machines.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-7-sbin-system-binaries-superuser-nbsp\">7. \/sbin &#8211; System Binaries (Superuser)&nbsp;<\/h3>\n\n\n\n<p>Like \/bin, the \/sbin directory contains essential binaries. However, the binaries here are typically intended for system administration tasks and require superuser (root) privileges to execute.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-8-lib-shared-libraries-nbsp\">8. \/lib &#8211; Shared Libraries&nbsp;<\/h3>\n\n\n\n<p>Shared libraries required for running programs are stored in the \/lib directory. These libraries are essential for the proper functioning of various software on the system.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-9-opt-optional-software-nbsp\">9. \/opt &#8211; Optional Software&nbsp;<\/h3>\n\n\n\n<p>The \/opt directory is where optional or add-on software packages are typically installed. It provides a standardized location for third-party software that is not part of the core system.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-listing-files-and-directories\">Listing Files and Directories<\/h2>\n\n\n\n<p>Now that we have covered the basics of important directories in the Linux file system, let us explore how to list files and directories using the ls command. ls is a handy tool for getting an overview of what is in your current directory or any other directory you specify. We will look at different options you can use with ls and provide code examples to illustrate their usage.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-ls-with-various-options\">Using ls with Various Options<\/h3>\n\n\n\n<p>ls has various options that allow you to customize the way it displays information. Here are some commonly used options:&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Option&nbsp;<\/td><td>Description&nbsp;<\/td><\/tr><tr><td>-l&nbsp;<\/td><td>Lists files and directories in long format, providing detailed information (permissions, owner, size, modification date).&nbsp;<\/td><\/tr><tr><td>-a&nbsp;<\/td><td>Includes hidden files and directories in the listing (those starting with a dot).&nbsp;<\/td><\/tr><tr><td>-h&nbsp;<\/td><td>Displays file sizes in a human-readable format (kilobytes, megabytes, gigabytes).&nbsp;<\/td><\/tr><tr><td>-t&nbsp;<\/td><td>Displays file sizes in a human-readable format (kilobytes, megabytes, gigabytes).&nbsp;<\/td><\/tr><tr><td>-r&nbsp;<\/td><td>Reverses the order of the listing, displaying items in reverse alphabetical or chronological order.&nbsp;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Now, let us see some code examples for different ls options:&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-1-basic-listing-nbsp\">Example 1: Basic Listing&nbsp;<\/h3>\n\n\n\n<p>To list files and directories in your current directory, simply run:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"855\" height=\"129\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-24.png\" alt=\"Linux Navigation and File Management\u00a0 (ls command)\" class=\"wp-image-17614\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-24.png 855w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-24-600x91.png 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-24-768x116.png 768w\" sizes=\"auto, (max-width: 855px) 100vw, 855px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-2-long-format-listing-nbsp\">Example 2: Long Format Listing&nbsp;<\/h3>\n\n\n\n<p>To list files and directories with detailed information, use the -l option:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -l<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"460\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-26.png\" alt=\"\" class=\"wp-image-17618\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-26.png 859w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-26-600x321.png 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-26-768x411.png 768w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-3-listing-hidden-files-nbsp\">Example 3: Listing Hidden Files&nbsp;<\/h3>\n\n\n\n<p>To list hidden files and directories (those starting with a dot), use the -a option:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -a<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"854\" height=\"111\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-25.png\" alt=\"Linux Navigation and File Management\u00a0 ( ls -a)\" class=\"wp-image-17616\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-25.png 854w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-25-600x78.png 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-25-768x100.png 768w\" sizes=\"auto, (max-width: 854px) 100vw, 854px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-4-human-readable-file-sizes-nbsp\">Example 4: Human-Readable File Sizes&nbsp;<\/h3>\n\n\n\n<p>To list file sizes in a human-readable format, combining the -l and -h options:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -lh&nbsp;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"860\" height=\"442\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-27.png\" alt=\"\" class=\"wp-image-17620\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-27.png 860w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-27-600x308.png 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-27-768x395.png 768w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-5-sorting-by-modification-time-nbsp\">Example 5: Sorting by Modification Time&nbsp;<\/h3>\n\n\n\n<p>To list files and directories sorted by modification time, use the -t option:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -lt<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"857\" height=\"452\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-28.png\" alt=\"Linux Navigation and File Management\u00a0 (ls -lt)\" class=\"wp-image-17622\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-28.png 857w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-28-600x316.png 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/image-28-768x405.png 768w\" sizes=\"auto, (max-width: 857px) 100vw, 857px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-6-reverse-order-listing-nbsp\">Example 6: Reverse Order Listing&nbsp;<\/h3>\n\n\n\n<p>To reverse the order of the listing (e.g., to see the oldest files first), add the -r option:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -ltr&nbsp;<\/code><\/pre>\n\n\n\n<p>These examples highlight some of the most used options with the ls command. Experimenting with these options will help you tailor your file listings to suit your specific needs, whether you are looking for specific files, checking file sizes, or monitoring changes in directories.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-changing-directories\">Changing Directories<\/h2>\n\n\n\n<p>To effectively navigate the Linux file system, you will need to know how to change directories using the cd command. The cd command allows you to move from one directory to another, enabling you to explore and access various parts of the file system. In this chapter, we will talk about how to use the cd command and provide examples of both relative and absolute paths.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-cd-command-nbsp\">Using the cd Command&nbsp;<\/h3>\n\n\n\n<p>The cd command stands for &#8220;change directory.&#8221; It allows you to switch your current working directory to another location in the file system. Here is how you can use it:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd &#91;directory_path]&nbsp;<\/code><\/pre>\n\n\n\n<p><em>Replace [directory_path] with the path to the directory you want to move to.<\/em>&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-examples-of-relative-and-absolute-paths-nbsp\">Examples of Relative and Absolute Paths&nbsp;<\/h3>\n\n\n\n<p>Understanding both relative and absolute paths is crucial when using the cd command.&nbsp;<\/p>\n\n\n\n<p><strong>&#8211; Relative Path:<\/strong> A relative path specifies the location of a directory or file in relation to your current directory. For example, if you are in the \/home\/user directory and want to move to the \/home\/user\/documents directory, you can use a relative path like this:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd documents<\/code><\/pre>\n\n\n\n<p>You do not need to specify the entire path; just the portion relative to your current location.&nbsp;<\/p>\n\n\n\n<p>&#8211; <strong>Absolute Path:<\/strong> An absolute path specifies the complete directory structure from the root directory (&#8220;\/&#8221;) to the target directory or file. For example, if you are in the same \/home\/user directory but want to move to \/var\/log, you would use an absolute path like this:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/var\/log&nbsp;<\/code><\/pre>\n\n\n\n<p>You provide the full path, starting from the root directory, to reach your destination.&nbsp;<\/p>\n\n\n\n<p>Understanding when to use relative or absolute paths depends on your current location and where you want to go within the file system. Relative paths are handy when you are moving within the same branch of the directory tree, while absolute paths are useful when you need to jump to a completely different part of the file system.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-creating-and-managing-files-and-directories\">Creating and Managing Files and Directories<\/h2>\n\n\n\n<p>Creating and managing files and directories is an essential skill. This chapter will cover various commands that allow you to perform these tasks effectively, including creating directories with mkdir, creating files with touch, renaming and moving files and directories with mv, copying files with cp, and removing files and directories with rm.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-creating-directories-with-mkdir\">Creating Directories with mkdir<\/h3>\n\n\n\n<p>The mkdir command stands for &#8220;make directory,&#8221; and as the name suggests, it is used to create new directories. Here is how you can use it:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir &#91;directory_name]&nbsp;<\/code><\/pre>\n\n\n\n<p><em>Replace [directory_name] with the name of the directory you want to create.<\/em>&nbsp;<\/p>\n\n\n\n<p>For example, to create a directory called &#8220;documents,&#8221; you would run:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp;mkdir documents&nbsp;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-creating-files-with-touch\">Creating Files with touch<\/h3>\n\n\n\n<p>The touch command is used to create new, empty files. It is a quick way to generate files for various purposes. Here is the basic syntax:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch &#91;file_name]&nbsp;<\/code><\/pre>\n\n\n\n<p><em>Replace [file_name] with the name of the file you want to create.<\/em>&nbsp;<\/p>\n\n\n\n<p>For instance, to create an empty file named &#8220;notes.txt,&#8221; you would use:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch notes.txt&nbsp;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-renaming-and-moving-files-and-directories-with-mv\">Renaming and Moving Files and Directories with mv<\/h3>\n\n\n\n<p>The mv command is a versatile tool that allows you to both rename and move files and directories. Here is how to use it:&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-mv-for-moving-files-and-directories-nbsp\">Using mv for Moving Files and Directories&nbsp;<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>mv &#91;source] &#91;destination]&nbsp;<\/code><\/pre>\n\n\n\n<p><em>Replace [source] with the current name or path of the file or directory.<\/em>&nbsp;<\/p>\n\n\n\n<p><em>Replace [destination] with the new name or path you want to assign to the file or directory.<\/em>&nbsp;<\/p>\n\n\n\n<p>For example, to rename a file from &#8220;old_file.txt&#8221; to &#8220;new_file.txt,&#8221; you would run:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mv old_file.txt new_file.txt&nbsp;<\/code><\/pre>\n\n\n\n<p>To move a file or directory from one location to another, use the mv command with the source and destination paths. For instance:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp;mv \/path\/to\/source \/path\/to\/destination&nbsp;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-cp-for-copying-files-and-directories-nbsp\">Using cp for Copying Files and Directories&nbsp;<\/h3>\n\n\n\n<p>The cp command is used to copy files and directories from one location to another. Here is the basic syntax for copying files:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cp &#91;source] &#91;destination]&nbsp;<\/code><\/pre>\n\n\n\n<p><em>Replace [source] with the name or path of the file or directory you want to copy.<\/em>&nbsp;<\/p>\n\n\n\n<p><em>Of course replace [destination] with the location where you want to copy the file or directory.<\/em>&nbsp;<\/p>\n\n\n\n<p>For example, to copy a file named &#8220;document.txt&#8221; from your current directory to a folder called &#8220;backup,&#8221; you would use:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cp document.txt backup\/&nbsp;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-copying-directories-and-their-contents\">Copying Directories and Their Contents<\/h3>\n\n\n\n<p>To copy an entire directory and its contents, use the -r (recursive) option with cp:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cp -r &#91;source_directory] &#91;destination_directory]&nbsp;<\/code><\/pre>\n\n\n\n<p>For instance, to copy a directory named &#8220;my_folder&#8221; and everything inside it to another location, you would run:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cp -r my_folder \/path\/to\/destination\/&nbsp;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-removing-files-and-directories-with-rm\">Removing Files and Directories with rm<\/h3>\n\n\n\n<p>The rm command is used for removing files and directories. Be cautious when using it, as it permanently deletes data, and deleted files cannot be easily recovered. Here is how to use it:&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-removing-files-nbsp\">Removing Files&nbsp;<\/h3>\n\n\n\n<p>To remove a file, use the following command:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp;rm &#91;file_name]&nbsp;<\/code><\/pre>\n\n\n\n<p><em>Replace [file_name] with the name of the file you want to delete.<\/em>&nbsp;<\/p>\n\n\n\n<p>For example, to delete a file named &#8220;unwanted.txt,&#8221; you would run:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm unwanted.txt&nbsp;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-removing-directories-nbsp\">Removing Directories&nbsp;<\/h3>\n\n\n\n<p>To remove a directory and its contents, you can use the -r (recursive) option with rm. This option deletes all files and subdirectories within the specified directory. Use this command with extreme caution, as it cannot be undone.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm -r &#91;directory_name]&nbsp;&nbsp;<\/code><\/pre>\n\n\n\n<p><em>Replace [directory_name] with the name of the directory you want to remove.<\/em>&nbsp;<\/p>\n\n\n\n<p>For instance, to delete a directory named &#8220;old_directory,&#8221; including all its contents, you would use:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm -r old_directory&nbsp;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-working-with-hidden-files-and-directories-nbsp\">Working with Hidden Files and Directories&nbsp;<\/h2>\n\n\n\n<p>Hidden files and directories play a crucial role in organizing and storing configuration and application-specific data. Names that start with a dot (e.g., .config) typically identify these files and directories. This chapter will introduce you to hidden files, explain their significance, and show you how to reveal them using the ls command.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-introduction-to-hidden-files-nbsp\">Introduction to Hidden Files&nbsp;<\/h3>\n\n\n\n<p>Hidden files and directories in Linux serve several purposes:&nbsp;<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>Configuration Files:<\/strong> Many applications and system components store their configuration settings in hidden files. The settings are often specific to the user and application, and they are stored away from regular user files to avoid clutter.<\/li>\n<\/ol>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>Application Data:<\/strong> Hidden directories can contain application-specific data or cache files. These files help improve the performance and functionality of applications by storing data that does not need to be visible to the user.&nbsp;<\/li>\n<\/ol>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li><strong>System Files:<\/strong> To prevent accidental modification or deletion by users, the system hides some system-related files and directories<\/li>\n\n\n\n<li> These files often play a critical role in the functioning of the Linux system.&nbsp;<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-how-to-show-hidden-files-nbsp-nbsp\">How to Show Hidden Files&nbsp;&nbsp;<\/h3>\n\n\n\n<p>By default, when you use the ls command, it does not display hidden files and directories. To reveal hidden items, you can use the -a option with ls. Here is how it works:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -a&nbsp;<\/code><\/pre>\n\n\n\n<p>The -a option tells ls to show all files and directories, including hidden ones, in the current directory. When you run this command, you will see a list that includes regular files, directories, and hidden files and directories, all marked with names beginning with a dot.&nbsp;<\/p>\n\n\n\n<p>For example, running ls -a might display a list like this:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.&nbsp; ..&nbsp; .config&nbsp; .bashrc&nbsp; documents&nbsp; photos&nbsp;<\/code><\/pre>\n\n\n\n<p>In this listing, the hidden files and directories (.config and .bashrc) are now visible alongside the regular items.&nbsp;<\/p>\n\n\n\n<p>Understanding hidden files and how to reveal them using ls -a is important, especially when you need to access or configure various application settings and system files in Linux. These hidden items are integral to the proper functioning and customization of your Linux system.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion-nbsp\">Conclusion&nbsp;<\/h2>\n\n\n\n<p>In this beginner-friendly guide to Linux navigation and file management, we have covered essential concepts and commands that will help you become proficient in working with the Linux file system. Let us summarize the key takeaways from this article:&nbsp;<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>Importance of Linux Navigation and File Management:<\/strong> Linux navigation and file management skills are fundamental for effectively using a Linux system. They enable you to organize, access, and manipulate files and directories efficiently.&nbsp;<\/li>\n<\/ol>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>Linux File Structure:<\/strong> Linux follows a hierarchical file structure with the root directory (&#8220;\/&#8221;) at the top. Understanding the structure and significance of key directories, such as &#8220;\/home&#8221; and &#8220;\/etc,&#8221; is essential for effective file management.&nbsp;<\/li>\n<\/ol>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li><strong>Terminal Usage:<\/strong> Linux often relies on the terminal or command line interface for file management tasks. Learning how to use the terminal is crucial for working with Linux servers, VPS, and other command-line-based systems.&nbsp;<\/li>\n<\/ol>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\">\n<li><strong>Copying and Moving:<\/strong> Commands like cp and mv allow you to copy, move, rename, and organize files and directories. These commands provide flexibility and control over your data.&nbsp;<\/li>\n<\/ol>\n\n\n\n<ol class=\"wp-block-list\" start=\"5\">\n<li><strong>Creating and Managing:<\/strong> Use mkdir to create directories and touch to create empty files. Learn how to manage files and directories with rm to remove them safely.&nbsp;<\/li>\n<\/ol>\n\n\n\n<ol class=\"wp-block-list\" start=\"6\">\n<li><strong>Hidden Files and Directories:<\/strong> Files and directories designated by names starting with a dot often serve as repositories for configuration and application-specific data. Use ls -a to reveal hidden items when listing directory contents.&nbsp;<\/li>\n<\/ol>\n\n\n\n<p>Mastering these concepts and commands will equip you with the confidence to navigate, manage, and customize your Linux system effectively. Whether you are a beginner or looking to expand your Linux skills, this knowledge is valuable for a smooth and efficient Linux experience.\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Discover the essentials of Linux Navigation and File Management in this beginner-friendly guide. Learn key commands, directory structures &#038; more.<\/p>\n","protected":false},"author":50,"featured_media":17612,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[],"ppma_author":[1491],"class_list":["post-17611","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"uagb_featured_image_src":{"full":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/blog-head_linux-navigation-and-file-management.jpg",1200,630,false],"thumbnail":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/blog-head_linux-navigation-and-file-management-150x150.jpg",150,150,true],"medium":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/blog-head_linux-navigation-and-file-management-600x315.jpg",600,315,true],"medium_large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/blog-head_linux-navigation-and-file-management-768x403.jpg",768,403,true],"large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/blog-head_linux-navigation-and-file-management.jpg",1200,630,false],"1536x1536":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/blog-head_linux-navigation-and-file-management.jpg",1200,630,false],"2048x2048":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2023\/09\/blog-head_linux-navigation-and-file-management.jpg",1200,630,false]},"uagb_author_info":{"display_name":"Tobias Mildenberger","author_link":"https:\/\/contabo.com\/blog\/author\/tobias\/"},"uagb_comment_info":0,"uagb_excerpt":"Discover the essentials of Linux Navigation and File Management in this beginner-friendly guide. Learn key commands, directory structures & more.","authors":[{"term_id":1491,"user_id":50,"is_guest":0,"slug":"tobias","display_name":"Tobias Mildenberger","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/077178d5dce6c3d4c0c0396857a7e544bfdf8adf04145fff5160b33a22e28b1f?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/17611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/users\/50"}],"replies":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/comments?post=17611"}],"version-history":[{"count":5,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/17611\/revisions"}],"predecessor-version":[{"id":17635,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/17611\/revisions\/17635"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media\/17612"}],"wp:attachment":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media?parent=17611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/categories?post=17611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/tags?post=17611"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=17611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}