Author Topic: List Number Of Files In A Directory?  (Read 2031 times)

Jon_J

  • Hero Member
  • *****
  • Posts: 1853
    • View Profile
    • http://
List Number Of Files In A Directory?
« on: February 09, 2007, 05:56:09 pm »
I'm copying some data files for a game to a directory on my /hdc1
There are supposed to be 158 files in this directory. I accidentally left 4 files out, but when comparing them on windows, I had one too many files after copying the 4 files.
So I found the file and removed it.
When I tried to look at this directory on my Zaurus, I couldn't find the command switch for ls to list the number of files in this directory.
I used emelFM, but it didn't have the option to show the number of files in a directory, so I hi-lited all the files and clicked the "File info" button. That didn't work either.
Needless to say, after clicking that "File info" button, I had to manually close 158 dialog boxes...whew!  
After I closed emelFM, I restarted X, just in case I buggered something up.
In Linux, how do you do a file count inside a directory?
I don't want to install another filemanager at this point.
Isn't there a console command that does this? like "dir" in DOS
Thank you

Jon
C3100 Multiboot-->Angstrom 2007.12-r18 | Cacko 1.23 | ArchLinuxARM
C3200 pdaxii13v2-5.5-alpha4 Akita on NAND

Ambicom WL1100C-CF Wifi - Ambicom CF modem - Ambicom CF GPS - Belkin-F5D5050 USB LAN
Socket CF Bluetooth rev K - Iogear 4 port USB micro hub - pocket CF card reader
Targus mini USB optical mouse - 2 Targus SD card readers

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
List Number Of Files In A Directory?
« Reply #1 on: February 09, 2007, 06:02:34 pm »
Quote
I'm copying some data files for a game to a directory on my /hdc1
There are supposed to be 158 files in this directory. I accidentally left 4 files out, but when comparing them on windows, I had one too many files after copying the 4 files.
So I found the file and removed it.
When I tried to look at this directory on my Zaurus, I couldn't find the command switch for ls to list the number of files in this directory.
I used emelFM, but it didn't have the option to show the number of files in a directory, so I hi-lited all the files and clicked the "File info" button. That didn't work either.
Needless to say, after clicking that "File info" button, I had to manually close 158 dialog boxes...whew!   
After I closed emelFM, I restarted X, just in case I buggered something up.
In Linux, how do you do a file count inside a directory?
I don't want to install another filemanager at this point.
Isn't there a console command that does this? like "dir" in DOS
Thank you

Jon
[div align=\"right\"][a href=\"index.php?act=findpost&pid=153663\"][{POST_SNAPBACK}][/a][/div]

ls /somedir/ |wc -l
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

Jon_J

  • Hero Member
  • *****
  • Posts: 1853
    • View Profile
    • http://
List Number Of Files In A Directory?
« Reply #2 on: February 09, 2007, 06:06:41 pm »
That worked. I was already in the directory, so I did ls |wc -l (I put this shortcut on a button in emelFM)

That's not shown in ls --help ( this is a copy/paste from ls --help in Cacko)
Code: [Select]
BusyBox v0.60.4 (2003.04.15-01:23+0000) multi-call binary

Usage: ls [-1AacCdeFilnpLRrSsTtuvwxXhk] [filenames...]

List directory contents

Options:
        -1      list files in a single column
        -A      do not list implied . and ..
        -a      do not hide entries starting with .
        -C      list entries by columns
        -c      with -l: show ctime
        -d      list directory entries instead of contents
        -e      list both full date and full time
        -F      append indicator (one of */=@|) to entries
        -i      list the i-node for each file
        -l      use a long listing format
        -n      list numeric UIDs and GIDs instead of names
        -p      append indicator (one of /=@|) to entries
        -L      list entries pointed to by symbolic links
        -R      list subdirectories recursively
        -r      sort the listing in reverse order
        -S      sort the listing by file size
        -s      list the size of each file, in blocks
        -T NUM  assume Tabstop every NUM columns
        -t      with -l: show modification time
        -u      with -l: show access time
        -v      sort the listing by version
        -w NUM  assume the terminal is NUM columns wide
        -x      list entries by lines instead of by columns
        -X      sort the listing by extension
        -h      print sizes in human readable format (e.g., 1K 243M 2G )
        -k      print sizes in kilobytes(default)
« Last Edit: February 09, 2007, 06:11:14 pm by Jon_J »
C3100 Multiboot-->Angstrom 2007.12-r18 | Cacko 1.23 | ArchLinuxARM
C3200 pdaxii13v2-5.5-alpha4 Akita on NAND

Ambicom WL1100C-CF Wifi - Ambicom CF modem - Ambicom CF GPS - Belkin-F5D5050 USB LAN
Socket CF Bluetooth rev K - Iogear 4 port USB micro hub - pocket CF card reader
Targus mini USB optical mouse - 2 Targus SD card readers

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
List Number Of Files In A Directory?
« Reply #3 on: February 09, 2007, 06:11:16 pm »
Quote
That worked. I was already in the directory, so I did ls |wc -l

That's not shown in ls --help ( this is a copy/paste from ls --help in Cacko)
Code: [Select]
BusyBox v0.60.4 (2003.04.15-01:23+0000) multi-call binary

Usage: ls [-1AacCdeFilnpLRrSsTtuvwxXhk] [filenames...]

List directory contents

Options:
        -1      list files in a single column
        -A      do not list implied . and ..
        -a      do not hide entries starting with .
        -C      list entries by columns
        -c      with -l: show ctime
        -d      list directory entries instead of contents
        -e      list both full date and full time
        -F      append indicator (one of */=@|) to entries
        -i      list the i-node for each file
        -l      use a long listing format
        -n      list numeric UIDs and GIDs instead of names
        -p      append indicator (one of /=@|) to entries
        -L      list entries pointed to by symbolic links
        -R      list subdirectories recursively
        -r      sort the listing in reverse order
        -S      sort the listing by file size
        -s      list the size of each file, in blocks
        -T NUM  assume Tabstop every NUM columns
        -t      with -l: show modification time
        -u      with -l: show access time
        -v      sort the listing by version
        -w NUM  assume the terminal is NUM columns wide
        -x      list entries by lines instead of by columns
        -X      sort the listing by extension
        -h      print sizes in human readable format (e.g., 1K 243M 2G )
        -k      print sizes in kilobytes(default)
[div align=\"right\"][a href=\"index.php?act=findpost&pid=153665\"][{POST_SNAPBACK}][/a][/div]

cause there is no ls option to do summaries, especially busybox ls. the command here is:  wc
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

Jon_J

  • Hero Member
  • *****
  • Posts: 1853
    • View Profile
    • http://
List Number Of Files In A Directory?
« Reply #4 on: February 09, 2007, 06:22:44 pm »
Thank you again, it will take me awhile to learn the quirks of Linux. Things have just been so easy in windows for so many years.
BTW, I was able to make that command into a button in emelFM
C3100 Multiboot-->Angstrom 2007.12-r18 | Cacko 1.23 | ArchLinuxARM
C3200 pdaxii13v2-5.5-alpha4 Akita on NAND

Ambicom WL1100C-CF Wifi - Ambicom CF modem - Ambicom CF GPS - Belkin-F5D5050 USB LAN
Socket CF Bluetooth rev K - Iogear 4 port USB micro hub - pocket CF card reader
Targus mini USB optical mouse - 2 Targus SD card readers

Antikx

  • Hero Member
  • *****
  • Posts: 1147
    • View Profile
    • http://tyrannozaurus.com
List Number Of Files In A Directory?
« Reply #5 on: February 10, 2007, 03:17:50 am »
Quote
Thank you again, it will take me awhile to learn the quirks of Linux. Things have just been so easy in windows for so many years.
[div align=\"right\"][a href=\"index.php?act=findpost&pid=153667\"][{POST_SNAPBACK}][/a][/div]
I find that is the most frustrating AND fun part of Linux. The learning curve is long but it's a heck of a ride. P
Kanpai,
-Antikx (Twitter, Mugshot and PodNova)
C1000 - pdaXrom R198 (Celestial Environment)
tyrannozaurus.com
[img]http://www.tyrannozaurus.com/files/category_pictures/general_1.png\" border=\"0\" class=\"linked-sig-image\" /]
Zaurus news/blogs feed from Zaurus users
Free Windows, Linux, or Web RSS readers.
Featured pages at tyrannozaurus:
Sharp Petition, ScummVM, Cacko, pdaXii13, and Celestial Environment

speculatrix

  • Administrator
  • Hero Member
  • *****
  • Posts: 3707
    • View Profile
List Number Of Files In A Directory?
« Reply #6 on: February 10, 2007, 03:29:42 pm »
to count all files in a multi-dir hierarchy:
find . -type f -ls | wc -l

to count dirs
find . -type d -ls | wc -l

to "reset" protection on files and dirs:
find . -type f -exec chmod u=rw,o=r,g=r {} \;
find . -type d -exec chmod u=rwx,o=rx,g=rx {} \;


find-exec is your friend, but a powerful & dangerous one :-)
« Last Edit: February 10, 2007, 03:29:49 pm by speculatrix »
Gemini 4G/Wi-Fi owner, formerly zaurus C3100 and 860 owner; also owner of an HTC Doubleshot, a Zaurus-like phone.