<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: AJ</title>
    <description>The latest articles on Forem by AJ (@ajseven).</description>
    <link>https://forem.com/ajseven</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F978203%2F7d1e88c0-336c-4582-8be7-b53995d0c446.jpg</url>
      <title>Forem: AJ</title>
      <link>https://forem.com/ajseven</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ajseven"/>
    <language>en</language>
    <item>
      <title>Top 17 ls command options</title>
      <dc:creator>AJ</dc:creator>
      <pubDate>Thu, 29 Aug 2024 05:19:23 +0000</pubDate>
      <link>https://forem.com/ajseven/top-17-ls-command-options-4fde</link>
      <guid>https://forem.com/ajseven/top-17-ls-command-options-4fde</guid>
      <description>&lt;p&gt;We are going to learn about Linux command called &lt;code&gt;ls&lt;/code&gt;. It is regular usage command in any distro of Linux to list out the directories and files in the current directory.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To list out the directories and files in the working directory simply use the command
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1) Classification of Files
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-F&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Here we have to note the indicator patterns at the end of the directories and files to determine the type.

&lt;ul&gt;
&lt;li&gt;Regular file: No indicator&lt;/li&gt;
&lt;li&gt;Directory: /&lt;/li&gt;
&lt;li&gt;Executable file: *&lt;/li&gt;
&lt;li&gt;Symbolic link: @&lt;/li&gt;
&lt;li&gt;Unix domain socket: =&lt;/li&gt;
&lt;li&gt;Named pipe (FIFO): |&lt;/li&gt;
&lt;li&gt;Socket: =&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  2) Long Listing of Files
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Displays detailed information about each file, including permissions, number of links, owner, group, size, and time of last modification.&lt;/li&gt;
&lt;li&gt;It's a daily driver command, alias could be
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;ll&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ls -l"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3) List the files with human readable
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lh&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;When used with &lt;code&gt;-l&lt;/code&gt;, this option shows file sizes in human-readable format (e.g., KB, MB) instead of bytes, mostly for the files present in the current directory.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4) List all Files
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;List all the files and directories including hidden ones those starting with &lt;code&gt;.&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5) Recursive
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Lists all files in the current directory and all sub-directories recursively.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6) Sort by time
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Sorts the files by the time of last modification, with the most recently modified files appearing first.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  7) Sort by Size
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Sorts files by size, with the largest files appearing first.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  8) One file per line
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Lists one file per line. Mostly useful when there are many files in the current Directory.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  9) Directories only
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Lists directories themselves, not their contents.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  10) Inode Number
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-li&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Displays the inode number of each file, which is a unique identifier for the file on the filesystem.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  11) Sort by Extension
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lX&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Sort the files or directories alphabetically.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  12) Natural Sort by order
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lv&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Sorts files by natural version number order, which is useful when filenames contain numbers &lt;code&gt;(e.g., file1, file2, file10)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  13) Group the Directories
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;--group-directories-first&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Lists directories first, then files, rather than mixing them together.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  14) Color the output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;--color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;auto
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Forces the output to be colorized or not &lt;code&gt;(never, always, or auto)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  15) Time style on long listing
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; &lt;span class="nt"&gt;--time-style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;long-iso
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Customizes the format of the time stamps. Common styles include &lt;code&gt;full-iso&lt;/code&gt;, &lt;code&gt;long-iso&lt;/code&gt;, and &lt;code&gt;iso&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  16) Access Time Sorting
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lu&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Sorts files by their last access time instead of modification time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  17) Ignore pattern
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;--ignore-pattern&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;*&lt;/span&gt;.tmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Excludes files matching the specified pattern &lt;code&gt;(e.g., *.tmp)&lt;/code&gt; from the output, very useful if there is lot of files with same extension&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mastering the &lt;code&gt;ls&lt;/code&gt; command enhances your efficiency by customizing directory listings. I hope you found this content helpful and learned something new.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>command</category>
      <category>learning</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
