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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Command for total number of files (and size) across subdirectories?
# 8  
Old 09-01-2011
Quote:
Originally Posted by Corona688
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.
I see...

Quote:
There may be ways around this if we had any idea what your system was -- but we don't.
Does this help?
Code:
Red Hat Enterprise Linux Server release 5.5 (Tikanga)

# 9  
Old 09-01-2011
Yes, it does! Smilie Using Linux means you have the GNU utilities, which support find -print0 and xargs --null, two options that were made for each other.

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

The -print0 tells GNU find to print lines ending in binary 0x00 instead of a newline. --null tells GNU xargs to read those kind of lines.
# 10  
Old 09-01-2011
Quote:
Originally Posted by Corona688
Yes, it does! Smilie Using Linux means you have the GNU utilities, which support find -print0 and xargs --null, two options that were made for each other.

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

The -print0 tells GNU find to print lines ending in binary 0x00 instead of a newline. --null tells GNU xargs to read those kind of lines.
Brilliant Smilie It works. Thanks a lot!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

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
Login or Register to Ask a Question