Command for total number of files (and size) across subdirectories?


 
Thread Tools Search this Thread
# 1  
Question Command for total number of files (and size) across subdirectories?

Hi all...

I have a directory called dbrn. This directory contains an unknown number of subdirectories which in turn contain an unknown number of files.


What I want to know is:

How many files with extention .ABC can be found in /dbrn across all subdirecties, and what is the total size for all files with extention .ABC

I know how to do this if all files are in the root folder, but not if the files are scattered across subdirectories.

Anyone any idea on what command (with what parameters) to use to accomplish the above?

Thanx!
# 2  
what you tried so far ?

is it homework ?

read about the find command
# 3  
Quote:
Originally Posted by itkamaraj
what you tried so far ?
This is what I have for the folder where all files are in that very same folder:
Code:
SIZE=`ls -la /path/to/the/files/*.ABC | awk '{sum = sum + $5} END { print sum} '`
RESULTTB=`echo "scale=2;$SIZE/1099511627776"|bc`
echo "Number of ABC-type files: `ls /path/to/the/files/*.ABC | wc -l` (${RESULTTB}TB)"

But if I use this on a folder with subfolders it doesn't work.

Quote:
is it homework ?
Homework? No. Far from it. Smilie
I recently switched jobs, got a crash course Linux/Unix, and am now just putting it to the test Smilie

Quote:
read about the find command
With my n00b status, I do not really see how I can use "find" to accomplish what I want Smilie
# 4  
Code:
find /dbm -name '*.ABC' | wc -l

Code:
find /dbm -name '*.ABC' | xargs ls -l | awk '{total += $5} END {print total}'

# 5  
Quote:
Originally Posted by yazu
Code:
find /dbm -name '*.ABC' | wc -l

This works Smilie

Quote:
Code:
find /dbm -name '*.ABC' | xargs ls -l | awk '{total += $5} END {print total}'

Upon executing this one I get
Code:
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

followed by lines and lines of
Code:
ls: part-of-a-folder-name: No such file or directory

Smilie
# 6  
for the size 'du' command works as well:
under your /dbm:
Code:
du -c --apparent-size **/*.ABC|tail -1

# 7  
Quote:
Originally Posted by Beun
This works Smilie


Upon executing this one I get
Code:
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

followed by lines and lines of
Code:
ls: part-of-a-folder-name: No such file or directory

Smilie
xargs is telling you what's wrong. You have filenames with spaces, ', and other such nasties in them which are confusing it. It splits on spaces by default.

There may be ways around this if we had any idea what your system was -- but we don't.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #921
Difficulty: Medium
Unix Epoch Time cannot be extended backwards from the epoch date.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX - command to count number of files in subdirectories

I have a folder named test/ and under that I have multiple directories and in each of the directory I have multiple log files. I want to know how many files exists under each sub directory. test |--quanrantine |--logfile1 |--logfile2 |--spooling |--logfile1 ... (4 Replies)
Discussion started by: ravikirankethe
4 Replies

2. Shell Programming and Scripting

Search subdirectories and find and print total files

Hi All, I have a folder name lets say path/to/folder/CUSTOMER and under this i have several folders and each of these subfolder have serveral subfolders and so on and at some point i will have a folder name called "FTP_FILES" . I need to search for these folders named "FTP_FILES and then... (10 Replies)
Discussion started by: Kevin Tivoli
10 Replies

3. Solaris

Find the total size of multiple files

If I have a number of files in a directory, for example, test.1 test.2 test.3 abc.1 abc.2 abc.3 and I need to find the total file size of all of the test.* files, I can use du -bc test.* in Linux. However, in Solaris, du does not have the -c option. What can I do in Solaris to get... (11 Replies)
Discussion started by: learnix
11 Replies

4. Solaris

Need command to know the total size

:mad:i need command to know the total size of project in my system by Giga bit i try #du -s /*/projectname but i need total size for this project by G.B can you help me (6 Replies)
Discussion started by: ayman
6 Replies

5. Shell Programming and Scripting

Use Awk and Array to get total size of files

Hello all, I need to do scripts total up the size in selected extension file for example motion.mov and segmentation.avi is in Label Media. For file info.doc and calc.xls in Label Document. I need output will be like this: count 1 Media,,2 GB count 2 Document,,4 GB My problem is,... (16 Replies)
Discussion started by: sheikh76
16 Replies

6. UNIX for Dummies Questions & Answers

get total size of files

as we use du - sh *.frm In This command It will show the list of files and size But I want the Total size that these files in directory with extension .frm How can we do This (6 Replies)
Discussion started by: kaushik02018
6 Replies

7. Shell Programming and Scripting

Getting the total file size for certain files per directory

Hi, I am trying to get the total file size for certain files per directory. I am using find /DirectoryPath -name '*.dta' -exec ls -l {} \; | awk '{ print $NF ": " $5 }' > /users/cergun/My\ Documents/dtafiles.txt but this lists all the files in the directories. I need the total... (9 Replies)
Discussion started by: cergun
9 Replies

8. UNIX for Dummies Questions & Answers

Find total size for some files?

Hi, I'm newbie to Unix. I'd like to count the total size of those files in my directory by date. For example, files on this period 05/01/08 - 05/31/08. If possible can we count by byte instead of kb. if I use $ du - ks , it will add up all files in the dir. thanks, Helen (5 Replies)
Discussion started by: helen008
5 Replies

9. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies

10. UNIX for Dummies Questions & Answers

Count number of files in subdirectories

Hello, I am new to unix and would like to have a count of all the files in the current directory as well as all the files in a subdirectory. The command I used was ls -R | wc -l but the number returned wasn't correct. Can someone please help? Thanks (2 Replies)
Discussion started by: cbeverly
2 Replies

Featured Tech Videos