{"id":13587,"date":"2019-04-03T11:14:05","date_gmt":"2019-04-03T11:14:05","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13587"},"modified":"2019-04-03T11:14:05","modified_gmt":"2019-04-03T11:14:05","slug":"how-to-count-number-of-files-and-subdirectories-inside-a-given-directory","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/how-to-count-number-of-files-and-subdirectories-inside-a-given-directory\/","title":{"rendered":"How to Count Number of Files and Subdirectories inside a Given Directory"},"content":{"rendered":"<p>The easiest way to count number of files and subdirectories in a directory using a\u00a0<code>tree<\/code>\u00a0command, which is best known for displaying files and directories in tree-like form.<\/p>\n<p>Although you can always enable quotas to restrict disk space and inode usage to avoid user abuse, this command may be useful anyway. By default, the current working directory is assumed if no arguments are given:<\/p>\n<pre>$ tree -iLf 1\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>.\r\n.\/10-Top-Linux-Distributions-of-2015.png\r\n.\/adobe-flash-player-alternative.jpg\r\n.\/CentOS-7-Security-Hardening-Guide.png\r\n.\/coding.png\r\n.\/d-logo-sketch.png\r\n.\/Experts-Share-Thoughts-on-25th-Anniversary-of-the-World-Wide-Web-431806-2.jpg\r\n.\/Get-Default-OS-Logo.png\r\n.\/InstallCinnamonDesktoponUbuntuandFedora720x345.png\r\n.\/Install-Nagios-in-CentOS.jpg\r\n.\/Install-Vmware-Workstation-12-in-Linux.png\r\n.\/Install-WordPress-on-CentOS-Fedora.png\r\n.\/Linux-Essentials-Bundle-Course.png\r\n.\/Linux-Online-Training-Courses.png\r\n.\/Linux-PDF-Readers-Viewers-Tools.png\r\n.\/linux-play-game.jpg\r\n.\/logo.png\r\n.\/nrpe-3.0.tar.gz\r\n.\/Python-and-Linux-Administration-Course.png\r\n.\/Ravi\r\n.\/teamviewer 11 0 57095 i386\r\n.\/Telegram\r\n.\/tsetup.0.10.1.tar.xz\r\n.\/VBoxGuestAdditions_5.0.0.iso\r\n.\/Vivaldi-About.png\r\n.\/VMware-Workstation-Full-12.1.1-3770994.x86_64.bundle\r\n\r\n<strong>3 directories, 22 files<\/strong>\r\n<\/pre>\n<p>If you want to view the same information for\u00a0<code>\/var\/log<\/code>, do:<\/p>\n<pre>$ tree -iLf 1 \/var\/log\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>\/var\/log\r\n\/var\/log\/alternatives.log\r\n\/var\/log\/apt\r\n\/var\/log\/aptitude\r\n\/var\/log\/auth.log\r\n\/var\/log\/boot.log\r\n\/var\/log\/bootstrap.log\r\n\/var\/log\/btmp\r\n\/var\/log\/btmp.1\r\n\/var\/log\/ConsoleKit\r\n\/var\/log\/cups\r\n\/var\/log\/dmesg\r\n\/var\/log\/dpkg.log\r\n\/var\/log\/faillog\r\n\/var\/log\/fontconfig.log\r\n\/var\/log\/fsck\r\n\/var\/log\/gpu-manager.log\r\n\/var\/log\/hp\r\n\/var\/log\/installer\r\n\/var\/log\/kern.log\r\n\/var\/log\/lastlog\r\n\/var\/log\/mdm\r\n\/var\/log\/mintsystem.log\r\n\/var\/log\/mintsystem.timestamps\r\n\/var\/log\/ntpstats\r\n\/var\/log\/samba\r\n\/var\/log\/speech-dispatcher\r\n\/var\/log\/syslog\r\n\/var\/log\/syslog.1\r\n\/var\/log\/teamviewer11\r\n\/var\/log\/unattended-upgrades\r\n\/var\/log\/upstart\r\n\/var\/log\/vbox-install.log\r\n\/var\/log\/wtmp\r\n\/var\/log\/wtmp.1\r\n\/var\/log\/Xorg.0.log\r\n\/var\/log\/Xorg.0.log.old\r\n\r\n<strong>13 directories, 23 files<\/strong>\r\n<\/pre>\n<p>Type the command below to view information about files and subdirectories in the directory\u00a0<code>ISOs<\/code>.<\/p>\n<pre>$ tree -iLf 1 ISOs \r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>ISOs\r\nISOs\/CentOS-6.5-x86_64-minimal.iso\r\nISOs\/CentOS-7.0-1406-x86_64-Minimal.iso\r\nISOs\/CentOS-7-x86_64-DVD-1503-01\r\nISOs\/ces-standard-3.3-x86_64.iso\r\nISOs\/debian-8.1.0-amd64-CD-1.iso\r\nISOs\/kali-linux-2.0-i386\r\nISOs\/openSUSE-13.2-DVD-x86_64.iso\r\nISOs\/rhel-server-7.0-x86_64-dvd.iso\r\nISOs\/ubuntu-14.04.2-desktop-amd64.iso\r\nISOs\/ubuntu-14.04.3-server-amd64.iso\r\nISOs\/VL-7.1-STD-FINAL.iso\r\nISOs\/Win10_1511_1_English_x32.iso\r\nISOs\/Win10_1511_1_Spanish_64.iso\r\n\r\n<strong>2 directories, 11 files<\/strong>\r\n<\/pre>\n<div id=\"attachment_22645\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/09\/Count-Files-Directories-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-22645\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/09\/Count-Files-Directories-in-Linux.png\" alt=\"Count Files and Subdirectories in a Directory\" width=\"499\" height=\"307\" aria-describedby=\"caption-attachment-22645\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-22645\" class=\"wp-caption-text\">Count Files and Subdirectories in a Directory<\/p>\n<\/div>\n<p>Explaining\u00a0<code>tree<\/code>\u00a0options used in the command above:<\/p>\n<ol>\n<li><code>-i<\/code>\u00a0\u2013 its a graphical option that enables tree to print out indentation lines<\/li>\n<li><code>-L<\/code>\u00a0\u2013 specifies the level of depth of the directory tree to be displayed, which in the case above is\u00a0<strong>1<\/strong><\/li>\n<li><code>-f<\/code>\u00a0\u2013 makes tree print the full path prefix for every file<\/li>\n<\/ol>\n<p>As you can view from the image above, after listing all the files and subdirectories,\u00a0<code>tree<\/code>\u00a0shows you the total number of directories and files in the directory you specified.<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/encrypt-decrypt-files-tar-openssl-linux\/\" target=\"_blank\" rel=\"noopener\">Encrypt and Decrypt Files and Directories Using Tar and OpenSSL<\/a><\/p>\n<p>You can refer to the\u00a0<strong>tree man page<\/strong>\u00a0to discover more useful options, some configuration files and environment variables to better understand how it works.<\/p>\n<h3>Conclusion<\/h3>\n<p>Here, we covered an important tip that can help you use the\u00a0<code>tree<\/code>\u00a0utility in a different way as compared to its traditional use, for displaying files and directories in a tree-like form.<\/p>\n<p>You can can build new tips by using the numerous\u00a0<strong>tree<\/strong>\u00a0options from the man page. Do you have any useful tip concerning the use of tree? Then share it with millions of Linux users around the world through the feedback form below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/count-files-and-directories-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The easiest way to count number of files and subdirectories in a directory using a\u00a0tree\u00a0command, which is best known for displaying files and directories in tree-like form. Although you can always enable quotas to restrict disk space and inode usage to avoid user abuse, this command may be useful anyway. By default, the current working &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/how-to-count-number-of-files-and-subdirectories-inside-a-given-directory\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Count Number of Files and Subdirectories inside a Given Directory&#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-13587","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\/13587","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=13587"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13587\/revisions"}],"predecessor-version":[{"id":13588,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13587\/revisions\/13588"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}