tag:blogger.com,1999:blog-8032022811235182759.post1057372147015949286..comments2024-03-23T08:25:23.254-07:00Comments on Linux Commando: How to count number of files in a directoryPeter Leunghttp://www.blogger.com/profile/05589860210899238688noreply@blogger.comBlogger32125tag:blogger.com,1999:blog-8032022811235182759.post-86923622992417398362016-05-03T11:18:31.270-07:002016-05-03T11:18:31.270-07:00Thank's very usefull articleThank's very usefull articleCatalog81http://www.catalog81.comnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-15955399352493236262016-04-21T07:31:22.202-07:002016-04-21T07:31:22.202-07:00You should never use ls for counting files since i...You should never use ls for counting files since it will take ages if you got a directory with several million files while find will work much much faster for counting.<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-54397528910517617962015-03-28T11:17:47.417-07:002015-03-28T11:17:47.417-07:00Nice post, this prefer to my problemNice post, this prefer to my problemRuaJuraihttp://www.ruajurai.comnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-59771282227321736902014-05-22T08:08:19.105-07:002014-05-22T08:08:19.105-07:00I prefer the stat solutionI prefer the stat solutionAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-26819359640824580702014-02-12T06:32:02.059-08:002014-02-12T06:32:02.059-08:00ls and find require read permission to the directo...ls and find require read permission to the directory contents. "stat -f%l" (BSD unix) does not. I think it's "stat -c%h" on linux.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-49663188697696573352014-01-18T07:01:06.871-08:002014-01-18T07:01:06.871-08:00Nice Post
Here are some More on LinuxNice Post<br />Here are some <a href="http://www.pagelinux.com/p/basic-linux.html" rel="nofollow"><b> More on Linux </b></a>Anonymoushttps://www.blogger.com/profile/09577316706053900875noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-80175639686926340812013-07-20T01:26:39.850-07:002013-07-20T01:26:39.850-07:00Awesome post...Thanks very much..Awesome post...Thanks very much..Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-40959348686436031652013-02-04T13:24:36.851-08:002013-02-04T13:24:36.851-08:00Thanks for the tip.Thanks for the tip.Prasannahttps://www.blogger.com/profile/07602529970107446923noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-28084564245496905662013-01-28T04:13:47.952-08:002013-01-28T04:13:47.952-08:00is there no way without enumerating the directory?...is there no way without enumerating the directory? using some filesystem metadata or somethin.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-53512715872850478672013-01-13T20:38:40.685-08:002013-01-13T20:38:40.685-08:00ls -1 doesn't count hidden files, but when usi...ls -1 doesn't count hidden files, but when using ls -1h instead counts two more: . and ..vladkrashttp://rorang.pronoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-48267967825609860262012-11-14T15:37:19.093-08:002012-11-14T15:37:19.093-08:00Thanks! Thanks! Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-79409689633045937842012-09-14T16:30:52.772-07:002012-09-14T16:30:52.772-07:00To view only regular files, no (dir,symlink,exec):...To view only regular files, no (dir,symlink,exec):<br /><br />ls -F | sed '/[/@*]$/d'<br /><br />iPenguinAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-41779974269792481792012-05-15T08:54:50.921-07:002012-05-15T08:54:50.921-07:00Good post! ThanksGood post! ThanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-21374460876428237462012-04-16T06:59:39.643-07:002012-04-16T06:59:39.643-07:00is there any way by which i can count the number o...is there any way by which i can count the number of files in the current directory without using ls and wc commands ?saumyanoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-33973184086277264452011-12-25T07:09:47.757-08:002011-12-25T07:09:47.757-08:00You don't need the -1.You don't need the -1.Jamiehttps://www.blogger.com/profile/05267476427017660642noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-20600304116614559552011-12-01T00:55:38.458-08:002011-12-01T00:55:38.458-08:00ls -1 | grep -c ""ls -1 | grep -c ""Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-30948596954786228082011-05-29T23:25:43.318-07:002011-05-29T23:25:43.318-07:00ls -l | grep ^- | wc -l
ls -l | grep ^d | wc -l
ls...ls -l | grep ^- | wc -l<br />ls -l | grep ^d | wc -l<br />ls -l | grep ^l | wc -lSakshihttps://www.blogger.com/profile/02931833096568564592noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-34475089625237331132011-03-24T11:00:36.309-07:002011-03-24T11:00:36.309-07:00You do not need to use the long listing with ls to...You do not need to use the long listing with ls to do a count. If you pipe the output of ls it will list the files one line at a time. It is the equivalent of doing ls -1 (thats a number 1)<br /><br />For example, try 'ls | cat'<br /><br />Its probably safer to explicitly use -1, as there may be some obscure versions of ls out there that behave differently.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-84657422794125845982011-02-15T07:05:18.742-08:002011-02-15T07:05:18.742-08:00Or (only count files, shorter):
for i in `ls -1b`...Or (only count files, shorter):<br /><br />for i in `ls -1b`; do c=`find $i -type f |wc -l`; echo "$c $i"; done;JP Deckersnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-72705445965265989482011-02-10T16:56:38.596-08:002011-02-10T16:56:38.596-08:00Both of the for/do loop options fail on directorie...Both of the for/do loop options fail on directories with spaces in them, how would one fix that (other than not using spaces in directories)?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-86161017031674899502011-02-09T05:05:19.607-08:002011-02-09T05:05:19.607-08:00Ohh... I did a mistake. -.- I should buy some glas...Ohh... I did a mistake. -.- I should buy some glasses...... Didn't see the 1 the first time... I thought this is a lower case "L".<br /><br />Sorry for this.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-40334548675557161752011-02-09T05:02:00.157-08:002011-02-09T05:02:00.157-08:00Thx for this post. I didn't remember which pro...Thx for this post. I didn't remember which program counts. :D<br /><br /><br />Ehmmm... But one thing: It's probably more efficient if you use<br />(a 1 (one) instead of a lower case "L" as parameter since it produces less output which might help to improve performance in a directory with very very many files or on a pc which is really slow.)<br />$ ls -1 | wc -lAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-21545374445495818772010-12-16T19:43:54.793-08:002010-12-16T19:43:54.793-08:00Thanks for your help dear.Thanks for your help dear.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-76494683855313181442010-08-11T01:55:42.448-07:002010-08-11T01:55:42.448-07:00Nice, i'm newbie with Linux, this command real...Nice, i'm newbie with Linux, this command really help to count folder at target dir :DBuzzknowhttp://buzzknow.comnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-55565000242955452582010-06-23T16:36:29.281-07:002010-06-23T16:36:29.281-07:00find: warning: you have specified the -maxdepth op...find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.Anonymousnoreply@blogger.com