{"id":150,"date":"2024-01-10T06:18:38","date_gmt":"2024-01-10T06:18:38","guid":{"rendered":"https:\/\/chennaihosting.co.in\/kb\/?p=150"},"modified":"2024-01-24T01:19:16","modified_gmt":"2024-01-24T01:19:16","slug":"how-to-create-new-directory-in-linux","status":"publish","type":"post","link":"https:\/\/chennaihosting.co.in\/kb\/how-to-create-new-directory-in-linux\/","title":{"rendered":"How to Create New Directory in Linux"},"content":{"rendered":"\n<p>In Linux, <code>dir<\/code> is a command used to list the contents of a directory. However, it&#8217;s not as commonly used as <code>ls<\/code>, which is the more prevalent command to list directory contents.<\/p>\n\n\n\n<p>In the context of a Linux <a href=\"https:\/\/chennaihosting.co.in\/\" data-type=\"link\" data-id=\"https:\/\/chennaihosting.co.in\/\">hosting company <\/a>or web hosting environment, <code>dir<\/code> refers to the command used within the command-line interface (CLI) or terminal to list the contents of directories. It serves the same purpose as in a standard Linux system, allowing users to view files and folders within a directory on the hosting server.<\/p>\n\n\n\n<p>The <code>dir<\/code> command is similar to <code>ls<\/code>, but its output might vary slightly depending on the system configuration or any specific options used with it. By default, <code>dir<\/code> provides a more concise listing compared to <code>ls<\/code>, showing basic information about files and directories within a specified directory.<\/p>\n\n\n\n<p>For instance, if you want to list the contents of the current directory using <code>dir<\/code>, you&#8217;d simply type <code>dir<\/code> in the terminal and press Enter.<\/p>\n\n\n\n<p>It will display a list of files and directories in a more compact format compared to the more detailed output of <code>ls<\/code>.<\/p>\n\n\n\n<p>However, it&#8217;s worth noting that <code>ls<\/code> is more widely used and offers more flexibility and customization options through various command-line switches and options.<\/p>\n\n\n\n<p>To see the contents of a directory in a more detailed and comprehensive manner, you can use <code>ls<\/code> with different options to suit your needs. For instance:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ls -l<\/code> provides a long listing format with detailed information.<\/li>\n\n\n\n<li><code>ls -a<\/code> shows all files, including hidden files (those starting with a dot <code>.<\/code>).<\/li>\n\n\n\n<li><code>ls -lh<\/code> provides a long listing with file sizes displayed in human-readable format.<\/li>\n<\/ul>\n\n\n\n<p>These are just a few examples of how <code>ls<\/code> can be used with different options to get detailed information about the contents of directories in Linux.<\/p>\n\n\n\n<p>The general syntax of the&nbsp;<strong>dir<\/strong>&nbsp;command is as follows.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dir<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#dir-command-usage-with-examples\">dir Command Usage with Examples<\/a><\/li><li><a href=\"#files-and-directories-listing-in-a-particular-path\">Files and Directories listing in a Particular Path<\/a><\/li><li><a href=\"#hidden-files-and-directories-listing\">Hidden Files and Directories listing<\/a><\/li><li><a href=\"#directory-entries-listing\">Directory Entries listing<\/a><\/li><li><a href=\"#index-number-of-files-listing\">Index Number of Files listing<\/a><\/li><li><a href=\"#listing-files-according-to-size-time\">Listing Files According to size &amp; time<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"dir-command-usage-with-examples\">dir Command Usage with Examples<\/h2>\n\n\n\n<p>The most common usage of the&nbsp;<strong>dir command<\/strong>&nbsp;is to display the contents of a directory in ascending order alphabetically.<\/p>\n\n\n\n<p>If you run the&nbsp;<strong>dir command<\/strong>&nbsp;without any options or location of the directory it will display all files and directories in your current working directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dir<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"files-and-directories-listing-in-a-particular-path\">Files and Directories listing in a Particular Path<\/h2>\n\n\n\n<p>If you want to list all the files and directories of a particular path, then append the path of your directory as shown. Here, we will list files and directories under the&nbsp;<code>\/etc<\/code>&nbsp;directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dir \/etc<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"627\" src=\"https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/1-2-1024x627.png\" alt=\"\" class=\"wp-image-151\" srcset=\"https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/1-2-1024x627.png 1024w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/1-2-300x184.png 300w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/1-2-768x470.png 768w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/1-2.png 1325w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>To list one file per line use&nbsp;<code>-1<\/code>&nbsp;option as follows.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dir -1 \/etc<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"699\" src=\"https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/2-1-1024x699.png\" alt=\"\" class=\"wp-image-152\" srcset=\"https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/2-1-1024x699.png 1024w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/2-1-300x205.png 300w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/2-1-768x524.png 768w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/2-1.png 1320w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"hidden-files-and-directories-listing\">Hidden Files and Directories listing<\/h2>\n\n\n\n<p>To list all files in a directory including&nbsp;<code>.<\/code>&nbsp;(hidden) files, use the&nbsp;<code>-a<\/code>&nbsp;option. You can include the&nbsp;<code>-l<\/code>&nbsp;option to format output as a list (detailed information).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dir -a\ndir -al<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"48\" src=\"https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/3-1-1024x48.png\" alt=\"\" class=\"wp-image-153\" srcset=\"https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/3-1-1024x48.png 1024w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/3-1-300x14.png 300w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/3-1-768x36.png 768w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/3-1.png 1316w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"directory-entries-listing\">Directory Entries listing<\/h2>\n\n\n\n<p>When you need to list only directory entries instead of directory content, you can use the&nbsp;<code>-d<\/code>&nbsp;option. In the output below, the option&nbsp;<code>-d<\/code>&nbsp;lists entries for the&nbsp;<strong>\/etc<\/strong>&nbsp;directory.<\/p>\n\n\n\n<p>When you use&nbsp;<code>-dl<\/code>, it shows a long listing of the directory including the owner, group owner, and permissions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dir -d \/etc\ndir -dl \/etc<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"51\" src=\"https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/4-1-1024x51.png\" alt=\"\" class=\"wp-image-154\" srcset=\"https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/4-1-1024x51.png 1024w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/4-1-300x15.png 300w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/4-1-768x38.png 768w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/4-1.png 1325w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"index-number-of-files-listing\">Index Number of Files listing<\/h2>\n\n\n\n<p>In case you want to view the index number of each file, use the option&nbsp;<code>-i<\/code>. From the output below, you can see that the first column shows numbers. These numbers are called&nbsp;<strong>inodes<\/strong>&nbsp;which are sometimes referred to as index nodes or index numbers.<\/p>\n\n\n\n<p>An&nbsp;<strong>inode<\/strong>&nbsp;in Linux systems is a data storage on a filesystem that stores information about a file except for the&nbsp;<strong>filename<\/strong>&nbsp;and its actual data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dir -il<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"listing-files-according-to-size-time\">Listing Files According to size &amp; time<\/h2>\n\n\n\n<p>The output below shows a sorted list of files according to their sizes by using the&nbsp;<code>-S<\/code>&nbsp;option.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dir -ashlS \/home\/<a href=\"https:\/\/chennaihosting.co.in\/\" data-type=\"link\" data-id=\"https:\/\/chennaihosting.co.in\/\">chennaihosting<\/a><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"83\" src=\"https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/5-1-1024x83.png\" alt=\"\" class=\"wp-image-155\" srcset=\"https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/5-1-1024x83.png 1024w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/5-1-300x24.png 300w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/5-1-768x62.png 768w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/5-1.png 1324w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>You can also&nbsp;sort files by modification time, with the file that has recently been modified appearing first on the list. This can be done using the&nbsp;<code>-t<\/code>&nbsp;option.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dir -ashlt \/home\/chennaihosting<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"84\" src=\"https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/6-1-1024x84.png\" alt=\"\" class=\"wp-image-156\" srcset=\"https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/6-1-1024x84.png 1024w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/6-1-300x25.png 300w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/6-1-768x63.png 768w, https:\/\/chennaihosting.co.in\/kb\/wp-content\/uploads\/2024\/01\/6-1.png 1325w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>To find help in using the dir command use &#8211;help flag and to view version details of dir use &#8211;version<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dir --help\ndir --version<\/code><\/pre>\n\n\n\n<p>Remember that in Linux, you might need appropriate permissions to create directories in certain locations (especially system directories). Using <code>sudo<\/code> before the command might be necessary in some cases to execute commands with elevated privileges.<\/p>\n\n\n\n<p>Always be cautious while working with system directories or when using commands with elevated permissions (<code>sudo<\/code>), as they can affect the system&#8217;s stability and security.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Linux, dir is a command used to list the [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":160,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[12,11],"class_list":["post-150","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-dir","tag-directory"],"_links":{"self":[{"href":"https:\/\/chennaihosting.co.in\/kb\/wp-json\/wp\/v2\/posts\/150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chennaihosting.co.in\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chennaihosting.co.in\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chennaihosting.co.in\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/chennaihosting.co.in\/kb\/wp-json\/wp\/v2\/comments?post=150"}],"version-history":[{"count":8,"href":"https:\/\/chennaihosting.co.in\/kb\/wp-json\/wp\/v2\/posts\/150\/revisions"}],"predecessor-version":[{"id":193,"href":"https:\/\/chennaihosting.co.in\/kb\/wp-json\/wp\/v2\/posts\/150\/revisions\/193"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chennaihosting.co.in\/kb\/wp-json\/wp\/v2\/media\/160"}],"wp:attachment":[{"href":"https:\/\/chennaihosting.co.in\/kb\/wp-json\/wp\/v2\/media?parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chennaihosting.co.in\/kb\/wp-json\/wp\/v2\/categories?post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chennaihosting.co.in\/kb\/wp-json\/wp\/v2\/tags?post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}