LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-01-2005, 04:34 AM   #1
alpha21
LQ Newbie
 
Registered: Nov 2004
Posts: 7

Rep: Reputation: 0
equivalent of windows directory properties providing basic stats on contents


hard to find some questions that forget and can be basic, but command equivalent of the properties tab for windows

i'm in more specific looking for information on the dir by:

total size
file count
subdir count

and to add to that maybe a listing of the subdirs on level 1 and the above 3 summaries for each

find command?

and if i could get help on syntax of the 2 different modes (1. simple 3 stats on full thing, 2. more detailed on the subdirs) would really appreciate, thx in advance
 
Old 05-01-2005, 04:55 AM   #2
hussar
Member
 
Registered: Oct 2003
Location: Heidelberg, Germany
Distribution: Slackware 11.0; Kubuntu 6.06; OpenBSD 4.0; OS X 10.4.10
Posts: 345

Rep: Reputation: 30
Check out `man du`.

For example, try `du -sh /home/yourhomedir` to see the total size on disk of your home directory summarized. The command `du -h /home/yourhomedir` will give you this information for all directories and files in /home/yourhomedir.

One time I wanted to find out what my largest directory in my home dir was, so I wrote this little script:

#!/bin/bash
#
# Filename: dirsize.sh
# Version: 0.0.1 Date: 04 December, 2004
#
# Author: hussar
# System: i486-slackware-linux-gnu
#
# Purpose: The purpose of this script is to list the subdirectories
# of a given directory and show their size on disk.
#
# Limitations: None yet known.

for file in `ls -A $1`
do
if ( [ -d $file ] ) ; then
du -sh $file
fi
done
 
Old 05-01-2005, 04:57 AM   #3
alpha21
LQ Newbie
 
Registered: Nov 2004
Posts: 7

Original Poster
Rep: Reputation: 0
yap, knew du however posted here as that just gives me size, i need a file count as well of entire dir and for option 2 subdirs
 
Old 05-01-2005, 05:19 AM   #4
hussar
Member
 
Registered: Oct 2003
Location: Heidelberg, Germany
Distribution: Slackware 11.0; Kubuntu 6.06; OpenBSD 4.0; OS X 10.4.10
Posts: 345

Rep: Reputation: 30
Sorry, I guess I didn't understand the question.

You want size and number of files for a given directory? What is your definition of "file." Should a directory count as a file? A straight count of files for a given directory using ls will count directories as files. You would have to explicitly exclude them from the count, if you were to write a script to do this.

I am not sure I understand what you mean by "and for option 2 subdirs." Do you want to list two subdirs in the command line and then get info for just those two?
 
Old 05-01-2005, 05:40 AM   #5
alpha21
LQ Newbie
 
Registered: Nov 2004
Posts: 7

Original Poster
Rep: Reputation: 0
yap, you got it pretty much summed up there but here, will give an example of what 2 things i am looking for (and was hoping there to be an easier and faster way than a full script but think not)

1. dirs and subdirs not to count as files

2. as stated above the example:

Full Dir Stats: (output to whatever command run)
Code:
/home/myFolder
10 files 5 folders
10 MB
meaning under myFolder there's a total of 10 files and 5 folders be it however or something like:

Code:
/home/myFolder/
 |-- file0.ext
 |-- file1.ext
 |-- file2.ext
 |-- subFolder1/file3.ext
 |-- subFolder1/subFolder2/file4.ext
 |-- subFolder3/file5.ext
 |-- subFolder3/file6.ext
 |-- subFolder3/subFolder4/file7.ext
 |-- subFolder3/subFolder4/file8.ext
 |-- subFolder5/file9.ext
where you see 5 folders and 10 files

something which "find /dir | wc -l" would give me for myFolder as: 15 (added count on both)
and "du -h" would just give a size

now for the second case output to be for the structure above:

Code:
/home/myFolder
10 files 5 folders
10 MB
|-- /subFolder1        2 files in 1 folders  - 2 MB
|-- /subFolder3        4 files in 2 folders  - 4 MB
|-- /subFolder5        1 files in 0 folders  - 1 MB
find does too many things :P and too confusing to list all the parameters to split up the differentiating from files and subfolders

Last edited by alpha21; 05-01-2005 at 05:41 AM.
 
Old 05-01-2005, 05:45 AM   #6
alpha21
LQ Newbie
 
Registered: Nov 2004
Posts: 7

Original Poster
Rep: Reputation: 0
the second case might be a far fetch but there must be a way for the first one to be done easily

can get the size through du /home/myFolder
and a total count through find /home/myFolder | wc -l

considerring I think there's no just 1 command contrary to my hopes, what's the parameters/addon to find line above to get the filecount and not subdirs? (that will give me total count and if one gives me just file count then i can find subdir count through that too)
 
Old 05-01-2005, 05:47 AM   #7
alpha21
LQ Newbie
 
Registered: Nov 2004
Posts: 7

Original Poster
Rep: Reputation: 0
ls -1 | wc -l

this would give me a file count in the current dir?

bash script not too familiar with, possibly just use that to recurssively count?

Last edited by alpha21; 05-01-2005 at 05:50 AM.
 
Old 05-01-2005, 06:25 AM   #8
hussar
Member
 
Registered: Oct 2003
Location: Heidelberg, Germany
Distribution: Slackware 11.0; Kubuntu 6.06; OpenBSD 4.0; OS X 10.4.10
Posts: 345

Rep: Reputation: 30
I believe you will find that `ls -1 | wc -l` is not what you are looking for because it will count directories as files. I think you would have to write some sort of test that would exclude the directories.

Looking at the problem, a modified solution to your second case actually occurred to me first, and I am trying a short script to see if I can work it. You might be able to build on that to get what you want. Bash scripting is not really that hard for this type of thing, and I suggest the Advanced Bash-Scripting Guide at www.tldp.org. Don't let the "Advanced" scare you off. The guide is put together well and uses fairly easy to understand examples.
 
Old 05-01-2005, 07:12 AM   #9
hussar
Member
 
Registered: Oct 2003
Location: Heidelberg, Germany
Distribution: Slackware 11.0; Kubuntu 6.06; OpenBSD 4.0; OS X 10.4.10
Posts: 345

Rep: Reputation: 30
Here is a quick script I threw together that does something sort of like what you wanted in your second case. While I was writing it, I found out that I don't completely understand how `ls` handles recursion, and that is why it only counts the number of files in the current directory and not all subdirectories. Anyway, if I were trying to write a script to do what you want, this would be my starting point.

#!/usr/bin/bash
#
# Filename: alpha21.sh
# Version: 0.0.1 Date: 01 May, 2005
#
# Author: hussar
# System: i486-slackware-linux-gnu
#
# Purpose: The purpose of this script is to list the name of a directory,
# the number of its files, the number of its subdirectories (see limitations),
# and the size of the directory on disk. It will also provide the same informat
ion
# for each of the directories immediate subdirectories (i.e., directories one le
vel
# below the starting or parent directory.
#
# Limitations: This script only provides information for one directory level
# below the parent directory. This script does not perform any error checking
# on its input other than that provided internally by the bash shell. This scri
pt
# performs its operations on the current directory (i.e., you must be in the
# directory in order to get the information for a specific directory).

# print the name of the directory
ls -d `pwd`

# print number of files
let fcount=0
for file in `ls -1R`
do
if [ -f $file ] ; then
let "fcount += 1"
fi
done
echo -n "`pwd` contains $fcount files and "

# print number of subdirectories
let dcount=0
for sdir in `ls -A`
do
if [ -d $sdir ] ; then
let "dcount += 1"
fi
done
echo $dcount subdirectories

# print the size of the directory on disk
du -sh `pwd`


Maybe someone else here will give us some more ideas on how to do this.
 
Old 05-01-2005, 09:09 AM   #10
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
If you're using a GUI then I think Konqueror, Nautilus and Rox can all give you the information you want. I use Rox as my file manager and under "Properties" it has all the stuff you are asking about.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ equivalent for java "Properties" class appas Programming 2 11-24-2004 04:13 AM
Get directory stats when a file has been modified? marri Programming 2 05-13-2004 09:44 PM
Visual Basic.Net Equivalent cucolin@ Programming 3 02-02-2004 08:51 PM
mv the contents of one directory to the parent directory warkrime Linux - Newbie 4 07-14-2003 08:03 PM
Get directory contents vank Programming 6 10-19-2002 11:13 AM


All times are GMT -5. The time now is 12:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration