{"id":121583,"date":"2025-01-20T15:39:22","date_gmt":"2025-01-20T15:39:22","guid":{"rendered":"\/tutorials\/?p=121583"},"modified":"2025-12-22T12:46:05","modified_gmt":"2025-12-22T12:46:05","slug":"ls-command","status":"publish","type":"post","link":"\/tutorials\/ls-command","title":{"rendered":"How to use the Linux ls command"},"content":{"rendered":"<p>The <strong>ls<\/strong> command lists files and directories in Linux and Unix-like operating systems. It is an essential tool for navigating and managing files which lets you view, sort, and organize file information in your current working directory or other specified locations.<\/p><p>This command-line utility works well for beginners by providing simple outputs with just a few keystrokes. Meanwhile, advanced users benefit from its ability to deliver detailed insights by appending additional options.<\/p><p>In this article, we&rsquo;ll explore the <strong>ls<\/strong> command&rsquo;s syntax, common options, and practical examples. By the end of this guide, you&rsquo;ll be able to use this command to simplify file management and navigate your Linux system efficiently.<\/p><p>\n\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-syntax-of-the-ls-command\">Syntax of the ls command<\/h2><p>The <strong>ls<\/strong> command&rsquo;s basic syntax is:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls [options] [file\/directory]<\/pre><ul class=\"wp-block-list\">\n<li><strong>[options]<\/strong> &ndash; modifies how the command behaves or formats the output. For example, <strong>-l <\/strong>displays a detailed list, while <strong>-a<\/strong> includes hidden files.<\/li>\n\n\n\n<li><strong>[file\/directory]<\/strong> &ndash; specifies the path of a file or directory to list its contents. For instance, <strong>ls \/home\/user\/Documents<\/strong> displays the contents of the <strong>Documents<\/strong> folder.<\/li>\n<\/ul><p>By default, running <strong>ls<\/strong> without arguments or options lists the files and directories in the currently active location in a compact format.<\/p><h2 class=\"wp-block-heading\" id=\"h-commonly-used-ls-command-options\">Commonly used ls command options<\/h2><p>Like other <a href=\"\/tutorials\/linux-commands\">Linux commands<\/a> such as <strong>cp<\/strong> or <strong>mv<\/strong>, you can combine <strong>ls<\/strong> with various options to modify its behavior or format the output. Below are the most commonly used options:<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Option<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td><strong>-l<\/strong><\/td><td>Displays a detailed list of file attributes, including permissions, size, and modification time.<\/td><\/tr><tr><td><strong>-a<\/strong><\/td><td>Includes hidden files, which start with a dot (<strong>.<\/strong>).<\/td><\/tr><tr><td><strong>-h<\/strong><\/td><td>Formats file sizes in a human-readable format, such as <strong>KB<\/strong> or <strong>MB<\/strong>.<\/td><\/tr><tr><td><strong>-R<\/strong><\/td><td>Lists the contents of directories recursively, including subdirectories.<\/td><\/tr><tr><td><strong>-t<\/strong><\/td><td>Sorts files by modification time, showing the most recently modified first.<\/td><\/tr><tr><td><strong>-S<\/strong><\/td><td>Sorts files by size, from largest to smallest.<\/td><\/tr><tr><td><strong>-r<\/strong><\/td><td>Reverses the sorting order of any other option.<\/td><\/tr><tr><td><strong>-F<\/strong><\/td><td>Appends symbols to file names to indicate file types, such as <strong>\/<\/strong> for directories or <strong>@<\/strong> for symbolic links.<\/td><\/tr><tr><td><strong>&ndash;color<\/strong><\/td><td>Adds color to distinguish file types and permissions; it&rsquo;s enabled by default on many systems.<\/td><\/tr><tr><td><strong>-d<\/strong><\/td><td>Lists only directory names without showing their contents.<\/td><\/tr><tr><td><strong>-i<\/strong><\/td><td>Displays each file&rsquo;s inode number.<\/td><\/tr><\/tbody><\/table><\/figure><p>You can also combine options to produce more detailed or customized outputs. For example:<\/p><ul class=\"wp-block-list\">\n<li><strong>ls -lah<\/strong> &ndash; lists all files, including hidden ones, in a detailed view with human-readable sizes.<\/li>\n\n\n\n<li><strong>ls -lR<\/strong> &ndash; displays a detailed view of files and directories, including all subdirectories.<\/li>\n\n\n\n<li><strong>ls -ltSr<\/strong> &ndash; sorts files by size, showing the smallest files first, and displays them in a detailed view.<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-examples-of-using-the-ls-command\">Examples of using the ls command<\/h2><p>Before running <strong>ls<\/strong> commands, open a terminal window on your Linux machine. For local computers, use the built-in terminal software.<\/p><p>If you&rsquo;re on a virtual private server (VPS), access the server remotely via SSH. Open your terminal and log in to the server with the following command, replacing <strong>your_vps_ip<\/strong> with your actual credentials:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ssh root@your_vps_ip<\/pre><p><a href=\"\/vps-hosting\">Hostinger VPS<\/a> customers can find their SSH credentials in hPanel by navigating to <strong>VPS &rarr; Manage &rarr; Overview &rarr; VPS details<\/strong>.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df80215bfa9\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2025\/02\/hpanel-vps-overview-ssh-username-ipv4-highlighted-1024x329.png\" alt=\"The SSH username and IPv4 information in the VPS Overview page of hPanel\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Hostinger users can also use our <strong>Browser terminal<\/strong> feature to run commands directly from a browser tab, eliminating the need for a separate terminal application. Hit the corresponding button in the top-right corner of your VPS dashboard, and you&rsquo;re good to go.<\/p><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/public\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h3 class=\"wp-block-heading\" id=\"h-listing-files-in-the-current-directory\">Listing files in the current directory<\/h3><p>Start by running the <strong>ls<\/strong> command without any options. This basic usage is perfect for directory navigation when you only need to see the visible contents of the current folder:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls<\/pre><p>The output displays the names of files and directories in alphabetical order, excluding additional details like file size or modification time:<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df80215f673\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"974\" height=\"128\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-output.png\/public\" alt=\"The ls command's output in the terminal\" class=\"wp-image-121588\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-output.png\/w=974,fit=scale-down 974w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-output.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-output.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-output.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 974px) 100vw, 974px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>\n\n<div class=\"protip\">\n                    <h4 class=\"title\">&#128161; Pro tip<\/h4>\n                    <p>Hostinger VPS customers can use <strong>Kodee<\/strong>, our AI Assistant, to list files on their server. Simply ask, \"Can you list all files in the <strong>root<\/strong> directory of my VPS?\" and Kodee will respond accordingly.<\/p>\n                <\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-listing-files-in-a-specific-directory\">Listing files in a specific directory<\/h3><p>Besides listing files in the current directory, the <strong>ls<\/strong> command lets you specify a location to view its contents. This eliminates the need to navigate to the folder first, which helps manage complex directory structures.<\/p><p>You can use an <strong>absolute path<\/strong>, which starts from the root (<strong>\/<\/strong>) directory, like the following example:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls \/home\/user\/Documents<\/pre><p>When executed, the command lists the contents of the <strong>Documents<\/strong> folder in <strong>\/home\/user<\/strong>, regardless of your current working directory.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df80216068c\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"2152\" height=\"128\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-home-user-documents-output.png\/public\" alt=\"The ls \/home\/user\/Documents command's output in the terminal\" class=\"wp-image-121590\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-home-user-documents-output.png\/w=2152,fit=scale-down 2152w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-home-user-documents-output.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-home-user-documents-output.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-home-user-documents-output.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-home-user-documents-output.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-home-user-documents-output.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-home-user-documents-output.png\/w=2048,fit=scale-down 2048w\" sizes=\"(max-width: 2152px) 100vw, 2152px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Alternatively, a <strong>relative path<\/strong> specifies the location relative to your current directory. For instance:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls .\/Projects<\/pre><p>This shows the contents of the <strong>Projects<\/strong> folder located in your current working directory.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df802161697\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1272\" height=\"130\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-projects-output.png\/public\" alt=\"The ls .\/Projects command's output in the terminal\" class=\"wp-image-121592\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-projects-output.png\/w=1272,fit=scale-down 1272w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-projects-output.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-projects-output.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-projects-output.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-projects-output.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1272px) 100vw, 1272px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Pro tip<\/h4>\n                    <p>Single dot (<strong>.<\/strong>) refers to the current directory. For example, <strong>ls .\/<\/strong> explicitly lists the current directory's contents. Meanwhile, double dots (<strong>..<\/strong>) refer to the parent directory (one level up). For instance, <strong>ls ..\/<\/strong> shows the contents of the parent folder.<\/p>\n                <\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-using-ls-for-a-detailed-view-of-file-attributes\">Using ls for a detailed view of file attributes<\/h3><p>The <strong>ls<\/strong> command provides more than just file names; you can use it to view detailed information about files and directories by adding the <strong>-l<\/strong> option:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls -l<\/pre><p>The long format includes the following file attributes:<\/p><ul class=\"wp-block-list\">\n<li><strong>File permissions<\/strong> &ndash; indicates &ldquo;read,&rdquo; &ldquo;write,&rdquo; and &ldquo;execute&rdquo; permissions for the file owner or group, shown in a format like <strong>-rw-r&ndash;r&ndash;<\/strong>.<\/li>\n\n\n\n<li><strong>Number of links<\/strong> &ndash; shows the number of hard links to the file or directory.<\/li>\n\n\n\n<li><strong>Owner<\/strong> &ndash; displays the username of the file&rsquo;s owner.<\/li>\n\n\n\n<li><strong>Group<\/strong> &ndash; displays the group to which the file belongs.<\/li>\n\n\n\n<li><strong>File size<\/strong> &ndash; shows the file size in <strong>bytes<\/strong>.<\/li>\n\n\n\n<li><strong>Modification date<\/strong> &ndash; indicates the last time the file was modified.<\/li>\n\n\n\n<li><strong>File name<\/strong> &ndash; lists the name of the file or directory.<\/li>\n<\/ul><p>Here&rsquo;s what the command might display:<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df80216296e\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1822\" height=\"190\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-l-output-1.png\/public\" alt=\"The ls -l command's output in the terminal\" class=\"wp-image-121596\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-l-output-1.png\/w=1822,fit=scale-down 1822w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-l-output-1.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-l-output-1.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-l-output-1.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-l-output-1.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-l-output-1.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 1822px) 100vw, 1822px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>This output shows that<strong> example.txt<\/strong> is owned by the <strong>root <\/strong>user, belongs to the <strong>developers <\/strong>group, is <strong>2635 bytes <\/strong>in size, and was last modified on January 15 at 00:46.<\/p><h3 class=\"wp-block-heading\" id=\"h-listing-hidden-files\">Listing hidden files<\/h3><p>To display hidden files in Linux, run the <strong>ls -a<\/strong> command. This reveals all files and directories, including hidden ones. It&rsquo;s convenient when working with configuration files or troubleshooting hidden system files.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls -a<\/pre><p>When executed, the command lists all files and directories, including special entries like <strong>.<\/strong> (current directory) and <strong>..<\/strong> (parent directory).<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df802163f70\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1908\" height=\"196\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-output.png\/public\" alt=\"The ls -a command's output in the terminal\" class=\"wp-image-121597\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-output.png\/w=1908,fit=scale-down 1908w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-output.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-output.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-output.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-output.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-output.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 1908px) 100vw, 1908px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>If you want to exclude these special entries while still viewing other hidden files, append the <strong>-A<\/strong> option instead:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls -A<\/pre><p>This makes the output cleaner, as shown below:<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df802164ebe\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1774\" height=\"192\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-capitalized-output.png\/public\" alt=\"The ls -A command's output in the terminal\" class=\"wp-image-121598\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-capitalized-output.png\/w=1774,fit=scale-down 1774w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-capitalized-output.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-capitalized-output.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-capitalized-output.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-capitalized-output.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-a-capitalized-output.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 1774px) 100vw, 1774px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-sorting-files-by-size-or-time\">Sorting files by size or time<\/h3><p>Sorting files helps you quickly identify the largest or most recently modified files. Use <strong>ls<\/strong> with the <strong>-S<\/strong> option to sort files by size, displaying the largest files first:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls -S<\/pre><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df802165d50\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1480\" height=\"130\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-s-output.png\/public\" alt=\"The ls -S command's output in the terminal\" class=\"wp-image-121599\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-s-output.png\/w=1480,fit=scale-down 1480w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-s-output.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-s-output.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-s-output.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-s-output.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1480px) 100vw, 1480px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Meanwhile, the <strong>-t<\/strong> option sorts files by modification time, showing the most recently modified files first:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls -t<\/pre><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df802166aed\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large is-resized wp-lightbox-container\"><img decoding=\"async\" width=\"1480\" height=\"126\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-t-output.png\/public\" alt=\"The ls -t command's output in the terminal\" class=\"wp-image-121600\" style=\"width:640px;height:auto\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-t-output.png\/w=1480,fit=scale-down 1480w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-t-output.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-t-output.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-t-output.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-t-output.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1480px) 100vw, 1480px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Pro tip<\/h4>\n                    <p>To display additional details like file permissions and size while sorting, combine these options with <strong>-l<\/strong>. For example, use <strong>ls -lS<\/strong> to sort by size or <strong>ls -lt<\/strong> to sort by modification time.<\/p>\n                <\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-combining-options\">Combining options<\/h3><p>The <strong>ls<\/strong> command becomes even more powerful when you combine multiple options. This approach saves time and provides more detailed or focused results. Here are some examples:<\/p><ul class=\"wp-block-list\">\n<li><strong>ls -lAh<\/strong> &ndash; lists all files, including hidden ones, in a long format with file sizes displayed in <strong>KB<\/strong>, <strong>MB<\/strong>, or <strong>GB<\/strong>:<\/li>\n<\/ul><figure data-wp-context='{\"imageId\":\"69df802167a4b\"}' data-wp-interactive=\"core\/image\" class=\"wp-block-image aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1690\" height=\"886\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-lah-output.png\/public\" alt=\"The ls -lAh command's output in the terminal\n\" class=\"wp-image-121601\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-lah-output.png\/w=1690,fit=scale-down 1690w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-lah-output.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-lah-output.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-lah-output.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-lah-output.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-lah-output.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 1690px) 100vw, 1690px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><ul class=\"wp-block-list\">\n<li><strong>ls -ltSr<\/strong> &ndash; displays a detailed view of files sorted by size (smallest to largest) and then by modification time:<\/li>\n<\/ul><figure data-wp-context='{\"imageId\":\"69df8021689f7\"}' data-wp-interactive=\"core\/image\" class=\"wp-block-image aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1598\" height=\"506\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-ltsr-output.png\/public\" alt=\"The ls -ltSr command's output in the terminal\n\" class=\"wp-image-121603\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-ltsr-output.png\/w=1598,fit=scale-down 1598w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-ltsr-output.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-ltsr-output.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-ltsr-output.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-ltsr-output.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-ltsr-output.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 1598px) 100vw, 1598px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><ul class=\"wp-block-list\">\n<li><strong>ls -Rla<\/strong> &ndash; shows all files, including hidden ones, recursively through subdirectories, displaying the folder hierarchy in a detailed format:<\/li>\n<\/ul><figure data-wp-context='{\"imageId\":\"69df80216983f\"}' data-wp-interactive=\"core\/image\" class=\"wp-block-image aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1182\" height=\"1426\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-rla-output-1.png\/public\" alt=\"The ls -Rla command's output in the terminal\n\" class=\"wp-image-121604\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-rla-output-1.png\/w=1182,fit=scale-down 1182w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-rla-output-1.png\/w=249,fit=scale-down 249w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-rla-output-1.png\/w=849,fit=scale-down 849w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-rla-output-1.png\/w=124,fit=scale-down 124w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-rla-output-1.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1182px) 100vw, 1182px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><h3 class=\"wp-block-heading\" id=\"h-using-ls-in-scripts-for-automation\">Using ls in scripts for automation<\/h3><p>Combining the <strong>ls<\/strong> command with shell scripting techniques lets you automate repetitive tasks like batch file processing, system monitoring, or generating reports.<\/p><p>Here&rsquo;s a simple bash script to find and list files larger than <strong>1 MB<\/strong> in a directory, sorted by size:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\n# Directory to scan\n\ndirectory=\"\/path\/to\/directory\"\n\n# List files larger than 1 MB in long format, sorted by size\n\necho \"Files larger than 1 MB in $directory:\"\n\nls -lS \"$directory\" | awk '$5 &gt; 1048576 {print $0}'<\/pre><ul class=\"wp-block-list\">\n<li><strong>awk &lsquo;$5 &gt; 1048576 {print $0}&rsquo; <\/strong>&ndash; filters files larger than <strong>1 MB<\/strong> (<strong>1 MB<\/strong> = <strong>1048576<\/strong> <strong>bytes<\/strong>) and prints their details.<\/li>\n\n\n\n<li><strong>directory=&rdquo;\/path\/to\/directory&rdquo;<\/strong> &ndash; Specifies the directory to scan; in this example, it&rsquo;s<strong>\/path\/to\/directory<\/strong>.<\/li>\n<\/ul><p>Another example generates a text file report of all hidden files in a directory:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\n# Directory to scan\n\ndirectory=\"\/path\/to\/directory\"\n\n# Output file\n\noutput_file=\"hidden_files_report.txt\"\n\n# Generate a report of hidden files\n\necho \"Generating hidden files report for $directory...\"\n\nls -la \"$directory\" | grep \"^\\.\" &gt; \"$output_file\"\n\necho \"Report saved to $output_file.\"<\/pre><figure data-wp-context='{\"imageId\":\"69df80216a822\"}' data-wp-interactive=\"core\/image\" class=\"wp-block-image aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1994\" height=\"746\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-nano-myscript-sh.png\/public\" alt=\"The myscript.sh bash script in the terminal\n\" class=\"wp-image-121606\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-nano-myscript-sh.png\/w=1994,fit=scale-down 1994w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-nano-myscript-sh.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-nano-myscript-sh.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-nano-myscript-sh.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-nano-myscript-sh.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-nano-myscript-sh.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 1994px) 100vw, 1994px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><ul class=\"wp-block-list\">\n<li><strong>grep &ldquo;^\\.&rdquo;<\/strong> &ndash; filters entries that start with a dot (<strong>.<\/strong>), indicating hidden files.<\/li>\n\n\n\n<li><strong>output_file= &ldquo;hidden_files_report.txt&rdquo;<\/strong> &ndash; saves the output to <strong>hidden_files_report.txt<\/strong>.<\/li>\n<\/ul><p>\n\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Suggested reading<\/h4>\n                    <p>Learn simple <a href=\"\/tutorials\/bash-script-example\">bash script examples<\/a> to get started with automating file management tasks.<\/p>\n                <\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-viewing-symbolic-links-and-file-types\">Viewing symbolic links and file types<\/h3><p>The <strong>ls<\/strong> command can also help distinguish <a href=\"\/tutorials\/how-to-create-symbolic-links-in-linux\">symbolic links<\/a> and various file types. Use the <strong>-F<\/strong> option to append symbols to file names, indicating their type:<\/p><ul class=\"wp-block-list\">\n<li><strong>\/<\/strong> &ndash; directory.<\/li>\n\n\n\n<li><strong>@<\/strong> &ndash; symbolic link.<\/li>\n\n\n\n<li><strong>*<\/strong> &ndash; executable file.<\/li>\n\n\n\n<li><strong>=<\/strong> &ndash; socket.<\/li>\n\n\n\n<li><strong>|<\/strong> &ndash; FIFO (named pipe).<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls -F<\/pre><p>The output will look like this:<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df80216baa3\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"2178\" height=\"222\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-f-output.png\/public\" alt=\"The ls -F command's output in the terminal\" class=\"wp-image-121607\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-f-output.png\/w=2178,fit=scale-down 2178w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-f-output.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-f-output.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-f-output.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-f-output.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-f-output.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-f-output.png\/w=2048,fit=scale-down 2048w\" sizes=\"(max-width: 2178px) 100vw, 2178px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-sorting-files-by-extension-or-name\">Sorting files by extension or name<\/h3><p>Sorting files by extension or name is a practical way to organize and locate specific file types within a directory.<\/p><p>Use the <strong>&ndash;sort=extension<\/strong> option to group files by their extensions. This is handy for directories containing a mix of file formats, such as <strong>TXT<\/strong> or <strong>JPG<\/strong>. For example:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls --sort=extension<\/pre><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df80216ccbc\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"2750\" height=\"224\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-output.png\/public\" alt=\"The ls --sort=extension command's output in the terminal\" class=\"wp-image-121609\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-output.png\/w=2750,fit=scale-down 2750w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-output.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-output.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-output.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-output.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-output.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-output.png\/w=2048,fit=scale-down 2048w\" sizes=\"(max-width: 2750px) 100vw, 2750px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>By default, <strong>ls<\/strong> sorts files alphabetically by their names. To reverse the sorting, add the -r option:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls -r<\/pre><p>You can also combine <strong>&ndash;sort=extension <\/strong>with <strong>-r<\/strong> to list files by extension in reverse order:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls --sort=extension -r<\/pre><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df80216dccc\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"2646\" height=\"220\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-r-output.png\/public\" alt=\"The ls --sort=extension -r command's output in the terminal\" class=\"wp-image-121610\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-r-output.png\/w=2646,fit=scale-down 2646w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-r-output.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-r-output.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-r-output.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-r-output.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-r-output.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-sort-extension-r-output.png\/w=2048,fit=scale-down 2048w\" sizes=\"(max-width: 2646px) 100vw, 2646px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-using-ls-with-wildcards\">Using ls with wildcards<\/h3><p>The <strong>ls<\/strong> command supports wildcards, so you can list files and directories that match specific naming patterns or file types. This helps you quickly locate the files you need in a directory.<\/p><p>Here are some common wildcards and their examples:<\/p><ul class=\"wp-block-list\">\n<li><strong>Asterisk (*)<\/strong> &ndash; matches zero or more characters in a file name.<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls *.txt<\/pre><ul class=\"wp-block-list\">\n<li><strong>Question mark (?)<\/strong> &ndash; matches exactly one character in a file name.<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls file?.jpg<\/pre><ul class=\"wp-block-list\">\n<li><strong>Square brackets ([ ])<\/strong> &ndash; match any single character inside the brackets. You can also specify a range of characters.<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls file[1-3].txt\n\nls file[a-c].txt<\/pre><p>You can combine wildcards for more complex patterns. For instance, to list all image files in a directory:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls *.jpg *.png<\/pre><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df80216f162\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"1094\" height=\"150\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-jpg-png-output2.png\/public\" alt=\"The ls *.jpg *.png command's output in the terminal\" class=\"wp-image-121613\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-jpg-png-output2.png\/w=1094,fit=scale-down 1094w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-jpg-png-output2.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-jpg-png-output2.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-jpg-png-output2.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-jpg-png-output2.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1094px) 100vw, 1094px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Or, to list files with two-character names followed by any extension:<\/p><p>ls ??.*<\/p><figure data-wp-context='{\"imageId\":\"69df80216ffe5\"}' data-wp-interactive=\"core\/image\" class=\"wp-block-image aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"844\" height=\"152\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-jpg-png-output-2.png\/public\" alt=\"The ls ??.* command's output in the terminal\n\" class=\"wp-image-121614\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-jpg-png-output-2.png\/w=844,fit=scale-down 844w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-jpg-png-output-2.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-jpg-png-output-2.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-jpg-png-output-2.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 844px) 100vw, 844px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><h3 class=\"wp-block-heading\" id=\"h-displaying-inode-numbers\">Displaying inode numbers<\/h3><p>Every file and directory in Linux has a unique identifier called an inode number, which stores metadata such as the file&rsquo;s size, permissions, owner, and location on disk.<\/p><p>To view inode numbers alongside file names, execute the <strong>ls<\/strong> command with the <strong>-i <\/strong>option:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ls -i<\/pre><p>You should see something like this:<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69df8021710ab\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"2190\" height=\"434\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-i-output-2.png\/public\" alt=\"The ls -i command's output in the terminal\" class=\"wp-image-121615\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-i-output-2.png\/w=2190,fit=scale-down 2190w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-i-output-2.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-i-output-2.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-i-output-2.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-i-output-2.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-i-output-2.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/01\/terminal-ls-i-output-2.png\/w=2048,fit=scale-down 2048w\" sizes=\"(max-width: 2190px) 100vw, 2190px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Here, <strong>12884901889<\/strong> and <strong>12884901890<\/strong> are the inode numbers for <strong>file1.txt<\/strong> and <strong>file2.txt<\/strong>, respectively.<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>The <strong>ls<\/strong> command is an essential tool for showing files and folders in Linux. In this article, we&rsquo;ve explored its syntax, commonly used options, and illustrative examples, such as sorting files, displaying hidden files, and identifying symbolic links or inode numbers.<\/p><p>You can also experiment with multiple options to create customized outputs, combine <strong>ls <\/strong>with wildcards to filter specific file types or use bash scripts to automate tasks.<\/p><p>By mastering these techniques, you can unlock the <strong>ls<\/strong> command&rsquo;s full potential to handle file management tasks in your Linux system. If you have any questions about the <strong>ls <\/strong>command, feel free to ask in the comment section below!<\/p><h2 class=\"wp-block-heading\" id=\"h-ls-command-faq\">ls command FAQ<\/h2><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1737387340301\"><h3 class=\"schema-faq-question\">What does the ls command do in Linux?<\/h3> <p class=\"schema-faq-answer\">The <strong>ls<\/strong> command lists files and directories in the current working directory or a specified location. By adding options, it can also sort or filter contents and display detailed file attributes, such as permissions, size, and modification dates.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1737387345916\"><h3 class=\"schema-faq-question\">How do I list hidden files with ls?<\/h3> <p class=\"schema-faq-answer\">To list hidden files in Linux, use the <strong>ls -a<\/strong> command. It displays all files, including hidden ones or those starting with a dot (<strong>.<\/strong>). For a cleaner view, that excludes <strong>.<\/strong> (current directory) and <strong>..<\/strong> (parent directory) entries, use the <strong>-A<\/strong> option instead.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1737387353427\"><h3 class=\"schema-faq-question\">Can I list files in reverse order using ls?<\/h3> <p class=\"schema-faq-answer\">Yes, you can list files in reverse order with the <strong>-r<\/strong> option. Combine it with other options, like <strong>-t<\/strong> to reverse time-based sorting or <strong>&ndash;sort=extension<\/strong> to reverse extension-based sorting, for more tailored results.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>The ls command lists files and directories in Linux and Unix-like operating systems. It is an essential tool for navigating [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/tutorials\/ls-command\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":411,"featured_media":121619,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to use the ls command in Linux?","rank_math_description":"The Linux ls command lets you list files and directories in various formats. Learn its syntax, options, and practical uses in this guide.","rank_math_focus_keyword":"ls command","footnotes":""},"categories":[22648,22644],"tags":[],"class_list":["post-121583","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-managing-monitoring-and-security","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/ls-command","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/ls-command","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/sell-vintage-clothing-online-18","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/ls-command","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/ls-command","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/ls-command","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/ls-command","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/ls-command","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/121583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/users\/411"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/comments?post=121583"}],"version-history":[{"count":11,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/121583\/revisions"}],"predecessor-version":[{"id":138098,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/121583\/revisions\/138098"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media\/121619"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media?parent=121583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/categories?post=121583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/tags?post=121583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}