Power of ls command
Tags: linux, ls, ubuntu, beginners
Published: 2021-01-05 19:08:50

#what is a command?
The simplest answer is that a command is a software program that, when executed on the CLI, performs any action.
some commands take additional input to run correctly, This input is known as <code>*options*</code> and <code>*arguments*</code>

<code> command [options] [arguments] </code>

<ul>
  <li>Options are used to modify the behavior of command.</li>
  <li>Arguments are used to provide additional information.</li>
</ul>

Today we'll discuss the fundamentals of <code>ls</code> command and try to cover some basic parameters. we use this command daily basic and frequently even though we never aware of all the available options.

<code>ls</code>: By itself, the ls command lists files and directories contained in the current working directory.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/o7jrnrfeqtoaz6cyk73v.png)

####Arguments
The <code>ls</code> command takes the argument as a name of the directory, it lists the contents of the directory, In the following example, the */etc/dpkg* directory is used as an argument.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zxdil8m6ttsx62tpc7b4.png)
The <code>ls</code> command also accepts multiple arguments. To list the contents of both the */etc/ppp* and */etc/ssh* directories
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/t39j6m49vqfe2ub74vfy.png)

####Options
options used with commands to expend or modify the way a command behaves.
<code>**-a** :</code> The <code>ls</code> command omits hidden files by default. A hidden file is any file(or directory) that begins with a dot <code>.</code> character. with the used of <code>-a</code> option we can display all filed including hidden files.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ssfo3d1gjx58rolhxuoh.png)

<code>**-l** :</code> With this option we get results in a long listing, providing additional information about the files that are listed, such as the permission, size, creation date, and other information. *(I will try to cover permission in the next post. this is a very important and fundamental part of Linux file system)*
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2e5owdjutygpzkb0a9dc.png)

<code>**-h** :</code> If the <code>-h</code> option added with <code>-l</code> the file sizes will be displayed in human readable order (or you can write full word form; *--human-readable*)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/dfmgixc2op3rvf445ttu.png)
*note: The order of the combined options isn't important. The output of all of these examples would be the same:* 
<code>ls -l -h
ls -hl
ls -lh </code>

<code>**-r** :</code> By default ls print the results in ascending alphabetical order, with the help of <code>-r</code> option we print the result in reverse order.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/i3rzm7ebsirs25oxf2bc.png)

<code>**-s** :</code> To see the file (or directory) size. very use full with flag <code>-h</code>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/4cbilidtuaq7kg9yyp4t.png)

<code>**-S** :</code> To sort files by size. it is most useful when used with the <code>-l</code> option so the file sizes are visible and <code>-h</code> option to display human-readable file sizes.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7j6trgd653gmra57rg92.png)

<code>**-R** :</code> With the help of this flag we can display all of the files in a directory as well as all of the files in all subdirectories under that directory. This is called a *recursive listing*.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cqc2b5b7udi0ztaupmv7.png)

<code>**-t**</code> Sorted by modified time or created time
<code>**-m**</code> List all the files and directories separated with comma

I hope this article will help you to learn a few options of <code>ls</code> commands in Linux. Please refer to the manual pages by using the <code> man ls </code> command to explore in-depth



Thanks! happy coding :))