{"id":2569,"date":"2023-11-08T00:24:37","date_gmt":"2023-11-07T23:24:37","guid":{"rendered":"https:\/\/bornoe.org\/blog\/?p=2569"},"modified":"2023-11-30T02:24:12","modified_gmt":"2023-11-30T01:24:12","slug":"the-ls-command-cheat-sheet","status":"publish","type":"post","link":"https:\/\/bornoe.org\/blog\/2023\/11\/the-ls-command-cheat-sheet\/","title":{"rendered":"The ls command cheat sheet"},"content":{"rendered":"\n<p>The &#8216;ls&#8217; command in GNU\/Linux &amp; Unix is a fundamental tool for listing the contents of directories. It provides valuable insights into file and directory information, including names, sizes, permissions, and modification times. This cheat sheet serves as a quick reference guide for utilizing the various options of the &#8216;ls&#8217; command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p><code>ls [options] [file(s) or directory(s)]<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Usage<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ls<\/code>: List the contents of the current directory<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ls \/path\/to\/directory<\/code>: List the contents of a specific directory<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Common Options<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ls -a<\/code>: List all files, including hidden files. Hidden files are the files whose name starts with a dot (.)<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ls -l<\/code>: Long listing format. Provides detailed information about each file or directory, including permissions, number of links, owner, group, size, and modification time.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls<\/code> -lh<\/code>: Long listing format and displaying file sizes in human-readable format (e.g., 1K, 2M, 3G) for better readability.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-S<\/code>: Sort files by size, displaying the largest ones first.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-t<\/code>: Sort files by modification time, showing the most recently modified files first.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-r<\/code>: Reverse the order of the sort, displaying files in reverse order.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-R<\/code>: Recursively list subdirectories encountered. Lists the contents of subdirectories as well.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-1<\/code>: List one file per line. Prints each file on a new line, making the output easier to read.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-d<\/code>: List directories themselves, not their contents. Useful when you want to only list directories.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-G<\/code>: Enable colorized output. Differentiates file types and provides color highlighting for better visualization.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-i<\/code>: Print the index number of each file. Displays the inode number for each file or directory.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-F<\/code>: Append indicator characters to entries. Appends a character to indicate the type of each entry (e.g., a slash for directories, an asterisk for executable files).<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-m<\/code>: Fill width with a comma-separated list of entries. Prints the file names as a comma-separated list with the specified width.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-q<\/code>: Display all non-printable characters as &#8216;?&#8217;. Replaces any non-printable characters in the file names with question marks.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-g<\/code>: Like <code>-l<\/code>, but do not list owner. Similar to the <code>-l<\/code> option, but does not display the owner&#8217;s name.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-o<\/code>: Like <code>-l<\/code>, but do not list group information. Similar to the <code>-l<\/code> option, but does not display the group information.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-s<\/code>: Print the allocated size of each file, in blocks. Displays the size of each file in blocks.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-u<\/code>: Use time of file creation, instead of last modification. Displays the creation time of each file or directory.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-c<\/code>: Use time of last status change, instead of last modification. Displays the time of the last status change of each file.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-L<\/code>: Follow symbolic links like normal files. Lists the information of the target file or directory that the symbolic link points to.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><code>ls <\/code>-p<\/code>: Append a slash (&#8216;\/&#8217;) to directories. Appends a slash to the end of each directory name for easier identification.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The &#8216;ls&#8217; command in GNU\/Linux &amp; Unix is a fundamental tool for listing the contents of directories. It provides valuable insights into file and directory information, including names, sizes, permissions, and modification times. This cheat sheet serves as a quick reference guide for utilizing the various options of the &#8216;ls&#8217; command. Syntax ls [options] [file(s) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,17],"tags":[],"class_list":["post-2569","post","type-post","status-publish","format-standard","hentry","category-gnu-linux","category-linux"],"_links":{"self":[{"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/posts\/2569","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/comments?post=2569"}],"version-history":[{"count":7,"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/posts\/2569\/revisions"}],"predecessor-version":[{"id":2596,"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/posts\/2569\/revisions\/2596"}],"wp:attachment":[{"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/media?parent=2569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/categories?post=2569"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bornoe.org\/blog\/wp-json\/wp\/v2\/tags?post=2569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}