

{"id":109427,"date":"2022-05-19T09:00:16","date_gmt":"2022-05-19T03:30:16","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=109427"},"modified":"2022-05-19T11:29:41","modified_gmt":"2022-05-19T05:59:41","slug":"ls-command-in-linux","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/","title":{"rendered":"LS Command in Linux"},"content":{"rendered":"<p>In this article, you will all there is to the ls command in Linux. We will be going through what the ls command is, and what are its uses. We will also be going through the different options that are available with the ls command. In the end, we will be looking into some really helpful practical examples of how to use the ls command in the Linux terminal.<\/p>\n<h3>What is the ls command?<\/h3>\n<p>The ls command is a command-line-based tool in Linux-based operating systems that shows the full list of content in your present working directory. Ls id the abbreviation for List.<\/p>\n<p>The ls command is one of the most loved and frequently used commands. It is so commonly used that the average Linux user, will use it at least once every day! In fact, it is one of the commands that is entered when you first enter the terminal.<\/p>\n<h3>What is ls command used for in Linux?<\/h3>\n<p>As I mentioned earlier, the ls command shows the full list of content in your present working directory. In slightly more intimidating words, the ls command displays or lists the files and directories within the file system.<\/p>\n<p>The ls command is a part of the GNU core utility package which is installed on all Linux distributions. That\u2019s right, there is no hassle in installing the ls tool onto your system as it comes preinstalled in all the Linux distros.<\/p>\n<p>Just like you navigate in your file explores using the GUI, the ls command allows you to do the same via the command line.<\/p>\n<h3>Syntax of Linux ls command<\/h3>\n<p>The syntax of the ls command is pretty simple. In fact, you can even run just the ls common with no additional information:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/syntax-of-the-ls-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109431\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/syntax-of-the-ls-command.webp\" alt=\"syntax of the ls command\" width=\"917\" height=\"216\" \/><\/a><\/p>\n<p>In the above output, the ls command listed all the content in my present working directory (\/home\/gopikiran)<\/p>\n<p>I can also list the files of any other directory by simply going into the desired directory using the cs command and then using the ls command.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/syntax-of-ls-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109432\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/syntax-of-ls-command.webp\" alt=\"syntax of ls command\" width=\"1323\" height=\"300\" \/><\/a><\/p>\n<p>If observe the outputs closely, you will find that the sub-directories are blue text, whereas the files are in plain white text.<\/p>\n<p>If at all you want more specific and desired outputs, we follow the below given general syntax:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ls &lt;options&gt; &lt;directory&gt;<\/pre>\n<h3>Options used with the ls command<\/h3>\n<p>In the syntax of the ls command, there is a field where ls can take on options or flags which are used to give additional information to the ls command so it changes how files and directories are listed in your terminal.<\/p>\n<p>In other words, the options alternate how the ls command works. Let us look at the available command that we use with the ls command.<\/p>\n<h4>1. -a<\/h4>\n<p>This option enlists the entire list of the current directory including the hidden files.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/a.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109433\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/a.webp\" alt=\"-a\" width=\"1079\" height=\"138\" \/><\/a><\/p>\n<h4>2. ~<\/h4>\n<p>This option lists the contents of the home directory, irrespective of your present working directory.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/unnamed-file.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109434\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/unnamed-file.webp\" alt=\"~\" width=\"1260\" height=\"192\" \/><\/a><\/p>\n<h4>3. -lh<\/h4>\n<p>This option will show you the file sizes in a human-readable format. By default the ls command will show the size of files in bytes, which is very hard to understand, Hence we use the option \u201c-h\u201d to print the sizes in Megabytes.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/lh.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109435\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/lh.webp\" alt=\"-lh\" width=\"995\" height=\"432\" \/><\/a><\/p>\n<h4>4. -lhS<\/h4>\n<p>This option displays the file in descending order of their size.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/lhS.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109436\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/lhS.webp\" alt=\"-lhS\" width=\"922\" height=\"401\" \/><\/a><\/p>\n<h4>5. -l &#8211; -block- size=&lt;size&gt;<\/h4>\n<p>This option displays the files in a specific size format.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/block-size.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109437\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/block-size.webp\" alt=\"block size\" width=\"780\" height=\"350\" \/><\/a><\/p>\n<h4>6. -d*\/<\/h4>\n<p>This option displays only the subdirectories and not the regular files.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/d.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109438\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/d.webp\" alt=\"-d\" width=\"801\" height=\"127\" \/><\/a><\/p>\n<h4>7. -m<\/h4>\n<p>This option prints out the directories and files separated by a comma.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/m.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109439\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/m.webp\" alt=\"-m\" width=\"1184\" height=\"149\" \/><\/a><\/p>\n<h4>8. -n<\/h4>\n<p>This option prints the group ID and owner ID instead of their names.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/n.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109440\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/n.webp\" alt=\"-n\" width=\"852\" height=\"419\" \/><\/a><\/p>\n<h4>9. &#8211;color &lt;value&gt;<\/h4>\n<p>This option prints the list as colored or discolored<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/color.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109441\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/color.webp\" alt=\"color\" width=\"1281\" height=\"266\" \/><\/a><\/p>\n<h4>10. -p<\/h4>\n<p>This option identifies the directories easily by marking the directories with a slash sign.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/p.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109443\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/p.webp\" alt=\"-p\" width=\"1259\" height=\"148\" \/><\/a><\/p>\n<h4>11. -li<\/h4>\n<p>This option prints the index number if the file system is the file is displayed in the first column.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/li.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109444\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/li.webp\" alt=\"-li\" width=\"780\" height=\"307\" \/><\/a><\/p>\n<h4>12. -r<\/h4>\n<p>This option prints the list in reverse order.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/r.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109445\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/r.webp\" alt=\"-r\" width=\"1184\" height=\"151\" \/><\/a><\/p>\n<h4>13. -R<\/h4>\n<p>This option displays the content of the sub-directories also.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/r-1.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109446\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/r-1.webp\" alt=\"R\" width=\"972\" height=\"308\" \/><\/a><\/p>\n<h4>14. -lX<\/h4>\n<p>This option groups the files with the same extensions together in the list.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/lx.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109447\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/lx.webp\" alt=\"-lx\" width=\"865\" height=\"379\" \/><\/a><\/p>\n<h4>15. -Q<\/h4>\n<p>This option adds quotation marks to all directories and files.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/q.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109448\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/q.webp\" alt=\"-q\" width=\"1261\" height=\"144\" \/><\/a><\/p>\n<h4>16. -l<\/h4>\n<p>This option shows the list in a long list format<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/l.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109449\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/l.webp\" alt=\"-l\" width=\"780\" height=\"338\" \/><\/a><\/p>\n<p>Before preceding to other options, let us look at what each field means in the above output:<\/p>\n<p>Column-1: This field consists of the permission of the files and directories.<\/p>\n<p>Column -2: This field shows the number of links for that file or directory.<\/p>\n<p>Column -3: This field shows the owner of the file or directory.<\/p>\n<p>Column -4: This field shows the group of the file or directory.<\/p>\n<p>Column -5: This field shows the size of the file or directory in bytes.<\/p>\n<p>Column -6: This field shows the last modified date and time of the file.<\/p>\n<p>Column -7: This field shows the name of the file or directory.<\/p>\n<h4>17. ..\/<\/h4>\n<p>This option lists the contents of the parent directory<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/content-of-parent-directory.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109450\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/content-of-parent-directory.webp\" alt=\"content of parent directory\" width=\"1177\" height=\"268\" \/><\/a><\/p>\n<p>In the above output, even though I moved to the directory \u201cDataFlair\u201d, using the command \u201cls ..\/\u201d printed the content of the \u201cDesktop\u201d directory, which is the parent directory of the \u201cDataFlair\u201d directory.<\/p>\n<h4>18. &#8211;version<\/h4>\n<p>This option prints information about the version of ls you are using.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/version.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109451\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/version.webp\" alt=\"version\" width=\"1042\" height=\"242\" \/><\/a><\/p>\n<h4>19. &#8211;help<\/h4>\n<p>This option prints out all of the commands and information regarding them<\/p>\n<h4>20. -g<\/h4>\n<p>This option displays the files excluding the column of information regarding the group and user.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/g.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109452\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/g.webp\" alt=\"-g\" width=\"980\" height=\"481\" \/><\/a><\/p>\n<h4>21. -lt<\/h4>\n<p>This option sorts the list by displaying the recently modified field at the top.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/lt.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109453\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/lt.webp\" alt=\"-lt\" width=\"1010\" height=\"434\" \/><\/a><\/p>\n<h4>22. \/<\/h4>\n<p>This option lists the files in the root directory<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/files-in-root-directory.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109454\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/files-in-root-directory.webp\" alt=\"files in root directory\" width=\"1091\" height=\"106\" \/><\/a><\/p>\n<h4>23. *<\/h4>\n<p>This option lists the contents of the directory along with its subdirectories. It is exactly the same as the option \u201c-R\u201d<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/directory-with-subdirectories.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109455\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/directory-with-subdirectories.webp\" alt=\"directory with subdirectories\" width=\"1018\" height=\"279\" \/><\/a><\/p>\n<h4>24. -l &lt;d&gt;<\/h4>\n<p>This option lists the content of the directory you specify in long format.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/long-format.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109456\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/long-format.webp\" alt=\"long format\" width=\"978\" height=\"183\" \/><\/a><\/p>\n<h4>25. -ltr<\/h4>\n<p>This option sorts the list by displaying the recently modified field at the bottom.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/ltr.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109457\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/ltr.webp\" alt=\"-ltr\" width=\"958\" height=\"522\" \/><\/a><\/p>\n<h4>26. -q<\/h4>\n<p>This option hides control characters.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/q-1.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109458\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/q-1.webp\" alt=\"-q\" width=\"1261\" height=\"144\" \/><\/a><\/p>\n<h4>27. -n ~\/kv<\/h4>\n<p>This option displays the UID and GIDs of a file or directory. This option prints very similar to the option \u2018-l\u2019 but shows the UID and GID in numeric format instead of names.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/uid.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109459\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/uid.webp\" alt=\"uid\" width=\"912\" height=\"199\" \/><\/a><\/p>\n<h4>28. -F<\/h4>\n<p>This option classifies the files with special characters that have different meanings, let us look at what each character means:<\/p>\n<p>1. \/ &#8211; directory<\/p>\n<p>2. @ &#8211; link file<\/p>\n<p>3. * &#8211; executable file<\/p>\n<p>4. Nothing &#8211; regular file<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/f.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109460\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/f.webp\" alt=\"-f\" width=\"1302\" height=\"182\" \/><\/a><\/p>\n<h3>LS Additional commands<\/h3>\n<h4>1. Opening the last edited file<\/h4>\n<p>You can open the last edited file using the command \u201cls -t\u201d. The option \u201c-t\u201d sorts out the file and you can pipe it with the \u201chead 1\u201d command to select the first file.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/opening-the-last-edited-file.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109461\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/opening-the-last-edited-file.webp\" alt=\"opening the last edited file\" width=\"765\" height=\"107\" \/><\/a><\/p>\n<h4>2. Displaying only 1 file per line<\/h4>\n<p>We can display only file per line using the command \u201cls -1\u201d<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/displaying-only-1-file-per-line.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109462\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/displaying-only-1-file-per-line.webp\" alt=\"displaying only 1 file per line\" width=\"426\" height=\"348\" \/><\/a><\/p>\n<h4>3. Creating an alias for the ls command<\/h4>\n<p>We can create an alias command for the ls command such that we can include the desired function. Say I want the command \u201cls -l\u201d to be created as an alias, then I use the following command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">alias ls=\"ls -l\"<\/pre>\n<p>If you want to see the aliases in your computer, simply type \u201calias\u201d in the terminal.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/creating-alias-for-ls-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109463\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/creating-alias-for-ls-command.webp\" alt=\"creating alias for ls command\" width=\"957\" height=\"295\" \/><\/a><\/p>\n<p>If you want to remove a previously defined alias, you can do so by using the following command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">unalias ls<\/pre>\n<h4>4. Displaying files under the \/tmp directory<\/h4>\n<p>To access the files under the \/tmp directory use the command \u201cls -l \/tmp\u201d<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/displaying-files-under-the-tmp-directory.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109464\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/displaying-files-under-the-tmp-directory.webp\" alt=\"displaying files under the tmp directory\" width=\"1508\" height=\"386\" \/><\/a><\/p>\n<h4>5. Listing files and storing the output in a file<\/h4>\n<p>If you want to store the output of a particular ls command in a specific file. You can do so by using the \u201c&gt;\u201d operator. The \u201c&gt;\u201d operator will store the output of the previously used ls command into the file you specify. Let us understand this with an example.<\/p>\n<p>Let\u2019s say that initially I listed the files of the directory \u201cdesktop\u201d and in the next command I copy the output of the last command into the txt file \u201clist\u201d.<\/p>\n<p>Let us take a closer look at this example using screenshots from the terminal :<\/p>\n<p>First, I listed the contents of the Desktop directory:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/listing-files-and-storing-the-output-in-a-file.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109466\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/listing-files-and-storing-the-output-in-a-file.webp\" alt=\"listing files and storing the output in a file\" width=\"1225\" height=\"177\" \/><\/a><\/p>\n<p>Then I used the \u201c&gt;\u201d operator in the command \u201cls &gt; list.txt\u201d to write the output of the previous ls command into the file \u201clist.txt\u2018<\/p>\n<p>Now, to confirm, that the output has been successfully logged into the file, you can use the cat command as follows:<\/p>\n<p>&nbsp;<\/p>\n<h3>Summary<\/h3>\n<p>As you have seen, the ls command is a very simple yet efficient tool that helps in listing the contents of a directory. Using the many options available, you can also change how the ls command works. Now you know what the ls command is all about, as we have seen its uses, syntax, options, and practical commands in the terminal.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, you will all there is to the ls command in Linux. We will be going through what the ls command is, and what are its uses. We will also be going&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":109429,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[26893,26892,26891],"class_list":["post-109427","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-linux-ls","tag-ls-command","tag-ls-command-in-linux"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>LS Command in Linux - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn about ls command in linux. See its uses and different options that are available with the ls command with their syntax and examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LS Command in Linux - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn about ls command in linux. See its uses and different options that are available with the ls command with their syntax and examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-19T03:30:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-05-19T05:59:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/ls-command-in-linux.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"LS Command in Linux - DataFlair","description":"Learn about ls command in linux. See its uses and different options that are available with the ls command with their syntax and examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/","og_locale":"en_US","og_type":"article","og_title":"LS Command in Linux - DataFlair","og_description":"Learn about ls command in linux. See its uses and different options that are available with the ls command with their syntax and examples.","og_url":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2022-05-19T03:30:16+00:00","article_modified_time":"2022-05-19T05:59:41+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/ls-command-in-linux.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/b49855299264df5e27e3ec6c2cd9fde9"},"headline":"LS Command in Linux","datePublished":"2022-05-19T03:30:16+00:00","dateModified":"2022-05-19T05:59:41+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/"},"wordCount":1418,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/ls-command-in-linux.webp","keywords":["linux ls","LS Command","LS Command in Linux"],"articleSection":["Linux Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/","url":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/","name":"LS Command in Linux - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/ls-command-in-linux.webp","datePublished":"2022-05-19T03:30:16+00:00","dateModified":"2022-05-19T05:59:41+00:00","description":"Learn about ls command in linux. See its uses and different options that are available with the ls command with their syntax and examples.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/ls-command-in-linux.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/ls-command-in-linux.webp","width":1200,"height":628,"caption":"ls command in linux"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/ls-command-in-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Linux Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/linux\/"},{"@type":"ListItem","position":3,"name":"LS Command in Linux"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/b49855299264df5e27e3ec6c2cd9fde9","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team is a group of passionate educators and industry experts dedicated to providing high-quality online learning resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With years of experience in the field, the team aims to simplify complex topics and help learners advance their careers. At DataFlair, we believe in empowering students and professionals with the knowledge and skills needed to thrive in today\u2019s fast-paced tech industry. Follow us for Free courses, expert insights, tutorials, and practical tips to boost your learning journey.","url":"https:\/\/data-flair.training\/blogs\/author\/datafbdad\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/109427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=109427"}],"version-history":[{"count":6,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/109427\/revisions"}],"predecessor-version":[{"id":109469,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/109427\/revisions\/109469"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/109429"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=109427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=109427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=109427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}