Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
01-27-2003, 11:31 PM
|
#1
|
LQ Newbie
Registered: Jan 2003
Posts: 6
Rep:
|
Command to list total number of files.
Hi all,
I'm looking for a command with a certain output. I've searched high and low for two days. Maybe you can help me.
I would like to list the total number of files including subdirectories and total amount of space the files are taking up. To be specific as in /var/ftp/pub/mp3. As in windows when you right-click on the folder and click properties. Or for command line, a command in Linux equal to Windows' "dir/w/s". I would like that info. Any ideas would be great. Thanks...
-WillieB
CCNA/CCAI, CCNP
Cable ISP Admin
|
|
|
01-27-2003, 11:58 PM
|
#2
|
Senior Member
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,848
|
Re: Command to list total number of files.
Quote:
Originally posted by WillieB_72
[snip]
I would like to list the total number of files including subdirectories and total amount of space the files are taking up. To be specific as in /var/ftp/pub/mp3. As in windows when you right-click on the folder and click properties. Or for command line, a command in Linux equal to Windows' "dir/w/s". I would like that info. Any ideas would be great.
[snip]
|
What about :
find . | wc -l ; du -sk .
which: finds all the files under the current directory (.) and pipes the output to wc which counts the number of lines (files). The subsequent du command gives a summary, in 1K blocks, of all the space in use under the current directory. Wrapping this in a bit of shell script would give it a prettier output:
#!/bin/bash
FILES=`find $1 2>/dev/null | wc -l`
BLOCKS=`du -sk $1 2>/dev/null | awk '{ print $1 }'`
echo "$1 : ${FILES} files in ${BLOCKS}"
Or something like that. If there's a way to do it in either the Gnome or KDE GUIs, I haven't stumbled across it yet.
Hope this helps...
|
|
|
01-28-2003, 11:44 AM
|
#3
|
LQ Newbie
Registered: Jan 2003
Posts: 6
Original Poster
Rep:
|
Command to list total number of files.
Thanks a lot for the reply. I have been playing with that command and it's really close to what I want but I can't seem to get the output the same as dir/w/s. See below and maybe that will help.
*******************************
On Windows Box:
C:\Server\mp3s>dir/w/s
Volume in drive C has no label.
Volume Serial Number is 1094-4F2B
Directory of C:\Server\mp3s
**Output Omitted**
Total Files Listed:
146 File(s) 530,461,824 bytes
32 Dir(s) 4,025,344,000 bytes free
C:\Server\mp3s>
This shows that I have 146 mp3s in 32 Folders which is 1 full cd each. So I know that I have 146 mp3s in 32 CD's.
Here's the output from the Red Hat Box for the exact same data underneath the current folder.
[root@server01 mp3s]# find . | wc -l ; du -sk .
157
519316 .
[root@server01 mp3s]#
*******************************
Any idea on how I could get the same data on Linux as in Windows above? The most important info to me is the # of files and directories, preferably seperate. Thanks again for your reply..:-)
-WillieB
CCNA/CCAI, CCNP
Cable ISP Admin
Last edited by WillieB_72; 01-28-2003 at 01:22 PM.
|
|
|
01-29-2003, 10:25 PM
|
#4
|
Senior Member
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,848
|
Re: Command to list total number of files.
Quote:
Originally posted by WillieB_72
Directory of C:\Server\mp3s
**Output Omitted**
Total Files Listed:
146 File(s) 530,461,824 bytes
32 Dir(s) 4,025,344,000 bytes free
This shows that I have 146 mp3s in 32 Folders which is 1 full cd each. So I know that I have 146 mp3s in 32 CD's.
Here's the output from the Red Hat Box for the exact same data underneath the current folder.
[root@server01 mp3s]# find . | wc -l ; du -sk .
157
519316 .
|
The only thing I can think of right now to account for the difference in the number of reported directories is that the `find' command may be counting some hidden files and/or directories that DOS isn't. The difference in the number of bytes (519316 * 1024 = 531779584) is undoubtedly due to du counting whole blocks whereas DIR is returning only the actual number of bytes in the files. Remember that you can ``fill'' up a disk with a relatively small number of 1-byte files since the filesystem allocates 4096 or 8192 (or whatever the cluster size is) bytes to a file at a time. Try:
echo "a" > a.file
ls -l a.file
du -sk a.file
du -sb a.file
Anyway, so how about :
#!/bin/bash
FILES=`find $1 -type f 2>/dev/null | wc -l | awk '{ print $1 }'`
DIRS=`find $1 -type d 2>/dev/null | wc -l | awk '{ print $1 }'`
BYTES=`du -sb $1 2>/dev/null | awk '{ print $1 }'`
echo "$1 : ${FILES} files in ${DIRS} directories using ${BYTES} bytes."
And if you want commas in the output... the only way I know how to pull that one off is using Perl.
Have fun...
|
|
|
All times are GMT -5. The time now is 12:54 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|