{"id":13552,"date":"2019-04-03T10:28:26","date_gmt":"2019-04-03T10:28:26","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13552"},"modified":"2019-04-03T10:28:26","modified_gmt":"2019-04-03T10:28:26","slug":"15-basic-ls-command-examples-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/15-basic-ls-command-examples-in-linux\/","title":{"rendered":"15 Basic \u2018ls\u2019 Command Examples in Linux"},"content":{"rendered":"<p><a href=\"https:\/\/www.tecmint.com\/tag\/linux-ls-command\/\" target=\"_blank\" rel=\"noopener\">ls command<\/a>\u00a0is one of the most frequently used command in Linux. I believe\u00a0<strong>ls<\/strong>\u00a0command is the first command you may use when you get into the command prompt of Linux Box.<\/p>\n<p>We use\u00a0<strong>ls<\/strong>\u00a0command daily basis and frequently even though we may not aware and never use all the\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-ls-command-tricks\/\" target=\"_blank\" rel=\"noopener\">ls option available<\/a>. In this article, we\u2019ll be discussing basic\u00a0<strong>ls<\/strong>\u00a0command where we have tried to cover as much parameters as possible.<\/p>\n<div id=\"attachment_865\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/08\/Linux-ls-Commands.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-865\" title=\"Linux ls Command\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/08\/Linux-ls-Commands-300x194.png\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/08\/Linux-ls-Commands-300x194.png 300w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/08\/Linux-ls-Commands.png 425w\" alt=\"Linux ls Command\" width=\"300\" height=\"194\" aria-describedby=\"caption-attachment-865\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-865\" class=\"wp-caption-text\">Linux ls Command<\/p>\n<\/div>\n<h4>1. List Files using ls with no option<\/h4>\n<p><strong>ls<\/strong>\u00a0with no option list files and directories in bare format where we won\u2019t be able to view details like file types, size, modified date and time, permission and links etc.<\/p>\n<pre><strong># ls<\/strong>\r\n\r\n0001.pcap        Desktop    Downloads         index.html   install.log.syslog  Pictures  Templates\r\nanaconda-ks.cfg  Documents  fbcmd_update.php  install.log  Music               Public    Videos<\/pre>\n<h4>2 List Files With option \u2013l<\/h4>\n<p>Here,\u00a0<strong>ls -l<\/strong>\u00a0(<strong>-l<\/strong>\u00a0is character not one) shows file or directory, size, modified date and time, file or folder name and owner of file and its permission.<\/p>\n<pre><strong># ls -l<\/strong>\r\n\r\ntotal 176\r\n-rw-r--r--. 1 root root   683 Aug 19 09:59 0001.pcap\r\n-rw-------. 1 root root  1586 Jul 31 02:17 anaconda-ks.cfg\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Desktop\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Documents\r\ndrwxr-xr-x. 4 root root  4096 Aug 16 02:55 Downloads\r\n-rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php\r\n-rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html\r\n-rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log\r\n-rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Music\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Pictures\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Public\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Templates\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Videos<\/pre>\n<h4>3. View Hidden Files<\/h4>\n<p>List all files including hidden file starting with \u2018<strong>.<\/strong>\u2018.<\/p>\n<pre><strong># ls -a<\/strong>\r\n\r\n.                .bashrc  Documents         .gconfd          install.log         .nautilus     .pulse-cookie\r\n..               .cache   Downloads         .gnome2          install.log.syslog  .netstat.swp  .recently-used.xbel\r\n0001.pcap        .config  .elinks           .gnome2_private  .kde                .opera        .spice-vdagent\r\nanaconda-ks.cfg  .cshrc   .esd_auth         .gtk-bookmarks   .libreoffice        Pictures      .tcshrc\r\n.bash_history    .dbus    .fbcmd            .gvfs            .local              .pki          Templates\r\n.bash_logout     Desktop  fbcmd_update.php  .ICEauthority    .mozilla            Public        Videos\r\n.bash_profile    .digrc   .gconf            index.html       Music               .pulse        .wireshark<\/pre>\n<h4>4. List Files with Human Readable Format with option -lh<\/h4>\n<p>With combination of\u00a0<strong>-lh<\/strong>\u00a0option, shows sizes in human readable format.<\/p>\n<pre><strong># ls -lh<\/strong>\r\n\r\ntotal 176K\r\n-rw-r--r--. 1 root root  683 Aug 19 09:59 0001.pcap\r\n-rw-------. 1 root root 1.6K Jul 31 02:17 anaconda-ks.cfg\r\ndrwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Desktop\r\ndrwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Documents\r\ndrwxr-xr-x. 4 root root 4.0K Aug 16 02:55 Downloads\r\n-rw-r--r--. 1 root root  21K Aug 12 12:42 fbcmd_update.php\r\n-rw-r--r--. 1 root root  46K Jul 31 09:58 index.html\r\n-rw-r--r--. 1 root root  48K Jul 31 02:17 install.log\r\n-rw-r--r--. 1 root root  12K Jul 31 02:13 install.log.syslog\r\ndrwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Music\r\ndrwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Pictures\r\ndrwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Public\r\ndrwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Templates\r\ndrwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Videos<\/pre>\n<h4>5. List Files and Directories with \u2018\/\u2019 Character at the end<\/h4>\n<p>Using\u00a0<strong>-F<\/strong>\u00a0option with\u00a0<strong>ls<\/strong>\u00a0command, will add the\u00a0<strong>\u2018\/\u2019<\/strong>\u00a0Character at the end each directory.<\/p>\n<pre><strong># ls -F<\/strong>\r\n\r\n0001.pcap        Desktop\/    Downloads\/        index.html   install.log.syslog  Pictures\/  Templates\/\r\nanaconda-ks.cfg  Documents\/  fbcmd_update.php  install.log  Music\/              Public\/    Videos\/<\/pre>\n<h4>6. List Files in Reverse Order<\/h4>\n<p>The following command with\u00a0<strong>ls -r<\/strong>\u00a0option display files and directories in reverse order.<\/p>\n<pre><strong># ls -r<\/strong>\r\n\r\nVideos     Public    Music               install.log  fbcmd_update.php  Documents  anaconda-ks.cfg\r\nTemplates  Pictures  install.log.syslog  index.html   Downloads         Desktop    0001.pcap<\/pre>\n<h4>7. Recursively list Sub-Directories<\/h4>\n<p><strong>ls -R<\/strong>\u00a0option will list very long listing directory trees. See an example of output of the command.<\/p>\n<pre><strong># ls -R<\/strong>\r\n\r\ntotal 1384\r\n-rw-------. 1 root     root      33408 Aug  8 17:25 anaconda.log\r\n-rw-------. 1 root     root      30508 Aug  8 17:25 anaconda.program.log\r\n\r\n.\/httpd:\r\ntotal 132\r\n-rw-r--r--  1 root root     0 Aug 19 03:14 access_log\r\n-rw-r--r--. 1 root root 61916 Aug 10 17:55 access_log-20120812\r\n\r\n.\/lighttpd:\r\ntotal 68\r\n-rw-r--r--  1 lighttpd lighttpd  7858 Aug 21 15:26 access.log\r\n-rw-r--r--. 1 lighttpd lighttpd 37531 Aug 17 18:21 access.log-20120819\r\n\r\n.\/nginx:\r\ntotal 12\r\n-rw-r--r--. 1 root root    0 Aug 12 03:17 access.log\r\n-rw-r--r--. 1 root root  390 Aug 12 03:17 access.log-20120812.gz<\/pre>\n<h4>8. Reverse Output Order<\/h4>\n<p>With combination of\u00a0<strong>-ltr<\/strong>\u00a0will shows latest modification file or directory date as last.<\/p>\n<pre><strong># ls -ltr<\/strong>\r\n\r\ntotal 176\r\n-rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog\r\n-rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log\r\n-rw-------. 1 root root  1586 Jul 31 02:17 anaconda-ks.cfg\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Desktop\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Videos\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Templates\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Public\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Pictures\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Music\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Documents\r\n-rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html\r\n-rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php\r\ndrwxr-xr-x. 4 root root  4096 Aug 16 02:55 Downloads\r\n-rw-r--r--. 1 root root   683 Aug 19 09:59 0001.pcap<\/pre>\n<h4>9. Sort Files by File Size<\/h4>\n<p>With combination of\u00a0<strong>-lS<\/strong>\u00a0displays file size in order, will display big in size first.<\/p>\n<pre><strong># ls -lS<\/strong>\r\n\r\ntotal 176\r\n-rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log\r\n-rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html\r\n-rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php\r\n-rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Desktop\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Documents\r\ndrwxr-xr-x. 4 root root  4096 Aug 16 02:55 Downloads\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Music\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Pictures\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Public\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Templates\r\ndrwxr-xr-x. 2 root root  4096 Jul 31 02:48 Videos\r\n-rw-------. 1 root root  1586 Jul 31 02:17 anaconda-ks.cfg\r\n-rw-r--r--. 1 root root   683 Aug 19 09:59 0001.pcap<\/pre>\n<h4>10. Display Inode number of File or Directory<\/h4>\n<p>We can see some number printed before file\u00a0<strong>\/<\/strong>\u00a0directory name. With\u00a0<strong>-i<\/strong>\u00a0options list file\u00a0<strong>\/<\/strong>\u00a0directory with inode number.<\/p>\n<pre><strong># ls -i<\/strong>\r\n\r\n20112 0001.pcap        23610 Documents         23793 index.html          23611 Music     23597 Templates\r\n23564 anaconda-ks.cfg  23595 Downloads            22 install.log         23612 Pictures  23613 Videos\r\n23594 Desktop          23585 fbcmd_update.php     35 install.log.syslog  23601 Public<\/pre>\n<h4>11. Shows version of ls command<\/h4>\n<p>Check version of ls command.<\/p>\n<pre><strong># ls --version<\/strong>\r\n\r\nls (GNU coreutils) 8.4\r\nCopyright (C) 2010 Free Software Foundation, Inc.\r\nLicense GPLv3+: GNU GPL version 3 or later &lt;http:\/\/gnu.org\/licenses\/gpl.html&gt;.\r\nThis is free software: you are free to change and redistribute it.\r\nThere is NO WARRANTY, to the extent permitted by law.\r\nWritten by Richard M. Stallman and David MacKenzie.<\/pre>\n<h4>12. Show Help Page<\/h4>\n<p>List help page of ls command with their option.<\/p>\n<pre><strong># ls --help<\/strong>\r\n\r\nUsage: ls [OPTION]... [FILE]...<\/pre>\n<h4>13. List Directory Information<\/h4>\n<p>With\u00a0<strong>ls -l<\/strong>\u00a0command list files under directory\u00a0<strong>\/tmp<\/strong>. Wherein with\u00a0<strong>-ld<\/strong>\u00a0parameters displays information of\u00a0<strong>\/tmp<\/strong>directory.<\/p>\n<pre><strong># ls -l \/tmp<\/strong>\r\ntotal 408\r\ndrwx------. 2 narad narad   4096 Aug  2 02:00 CRX_75DAF8CB7768\r\n-r--------. 1 root  root  384683 Aug  4 12:28 htop-1.0.1.tar.gz\r\ndrwx------. 2 root  root    4096 Aug  4 11:20 keyring-6Mfjnk\r\ndrwx------. 2 root  root    4096 Aug 16 01:33 keyring-pioZJr\r\ndrwx------. 2 gdm   gdm     4096 Aug 21 11:26 orbit-gdm\r\ndrwx------. 2 root  root    4096 Aug 19 08:41 pulse-gl6o4ZdxQVrX\r\ndrwx------. 2 narad narad   4096 Aug  4 08:16 pulse-UDH76ExwUVoU\r\ndrwx------. 2 gdm   gdm     4096 Aug 21 11:26 pulse-wJtcweUCtvhn\r\n-rw-------. 1 root  root     300 Aug 16 03:34 yum_save_tx-2012-08-16-03-34LJTAa1.yumtx<\/pre>\n<pre><strong># ls -ld \/tmp\/<\/strong>\r\n\r\ndrwxrwxrwt. 13 root root 4096 Aug 21 12:48 \/tmp\/<\/pre>\n<h4>14. Display UID and GID of Files<\/h4>\n<p>To display\u00a0<strong>UID<\/strong>\u00a0and\u00a0<strong>GID<\/strong>\u00a0of files and directories. use option\u00a0<strong>-n<\/strong>\u00a0with ls command.<\/p>\n<pre><strong># ls -n<\/strong>\r\n\r\ntotal 36\r\ndrwxr-xr-x. 2 500 500 4096 Aug  2 01:52 Downloads\r\ndrwxr-xr-x. 2 500 500 4096 Aug  2 01:52 Music\r\ndrwxr-xr-x. 2 500 500 4096 Aug  2 01:52 Pictures\r\n-rw-rw-r--. 1 500 500   12 Aug 21 13:06 tmp.txt\r\ndrwxr-xr-x. 2 500 500 4096 Aug  2 01:52 Videos<\/pre>\n<h4>15. ls command and its Aliases<\/h4>\n<p>We have made alias for\u00a0<strong>ls<\/strong>\u00a0command, when we execute ls command it\u2019ll take\u00a0<strong>-l<\/strong>\u00a0option by default and display long listing as mentioned earlier.<\/p>\n<pre><strong># alias ls=\"ls -l\"<\/strong><\/pre>\n<p><strong>Note<\/strong>: We can see number of alias available in your system with below alias command and same can be unalias as shown below example.<\/p>\n<pre><strong># alias<\/strong>\r\n\r\nalias cp='cp -i'\r\nalias l.='ls -d .* --color=auto'\r\nalias ll='ls -l --color=auto'\r\nalias ls='ls --color=auto'\r\nalias mv='mv -i'\r\nalias rm='rm -i'\r\nalias which='alias | \/usr\/bin\/which --tty-only --read-alias --show-dot --show-tilde'<\/pre>\n<p>To remove an alias previously defined, just use the unalias command.<\/p>\n<pre><strong># unalias ls<\/strong><\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/15-basic-ls-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ls command\u00a0is one of the most frequently used command in Linux. I believe\u00a0ls\u00a0command is the first command you may use when you get into the command prompt of Linux Box. We use\u00a0ls\u00a0command daily basis and frequently even though we may not aware and never use all the\u00a0ls option available. In this article, we\u2019ll be discussing &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/15-basic-ls-command-examples-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;15 Basic \u2018ls\u2019 Command Examples in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13552","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13552"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13552\/revisions"}],"predecessor-version":[{"id":13553,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13552\/revisions\/13553"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}