Determining file size for a list of files with paths


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Determining file size for a list of files with paths
# 1  
Old 09-14-2011
Determining file size for a list of files with paths

Hello,

I have a flat file with a list of files with the path to the file and I am attempting to calculate the filesize for each one; however xargs isn't playing nicely and I am sure there is probably a better way of doing this.

What I envisioned is this:
Code:
cat filename|xargs -i ls -l {} |awk '{total = total + $5}END{print total}'

but xargs -i and xargs -0 do not seem to work, so is there a way of doing this without xargs? The list of path/to/files has spaces between some of the paths so that is why regular xargs is not an option.

Thanks in advance!

Last edited by vbe; 09-15-2011 at 01:46 PM.. Reason: code tags...
# 2  
Old 09-14-2011
That's a useless use of cat. Use file redirection instead to save CPU time and avoid the unintended side-effects of having an extra pipe in the way.

-0 only works if the file's separated by NULLs. I'm guessing yours is separated by newlines.

Since you have -0 though, you're probably using the GNU utilities, which makes things simpler:

Code:
<filename xargs -d '\n' du -b --apparent-size -c | tail -n 1

# 3  
Old 09-14-2011
Thanks for the help; however there seems to be a \t appended to the output that du is receiving:

du: cannot access 'filename.doc\t': No such file or directory
# 4  
Old 09-14-2011
garbage in, garbage out. The tabs are coming from your data file.

What, exactly, does your datafile look like?
# 5  
Old 09-15-2011
DOH! Yeah that was it; I had run sed earlier to remove the spaces at the end of the lines but it didn't work......but I can fix that

Thanks for the assistance!

---------- Post updated 09-15-11 at 11:38 AM ---------- Previous update was 09-14-11 at 06:58 PM ----------

I determined that the resulting numbers were too small; and after rerunning them through awk to do the calculation it seems that du -c, when used with xargs and large lists will actually end up breaking it out to multiple du processes so the total will only apply for the last du process which was running.


Thanks though as you got me to the right place!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List duplicate files based on Name and size

Hello, I have a huge directory (with millions of files) and need to find out duplicates based on BOTH file name and File size. I know fdupes but it calculates MD5 which is very time-consuming and especially it takes forever as I have millions of files. Can anyone please suggest a script or... (7 Replies)
Discussion started by: prvnrk
7 Replies

2. UNIX for Dummies Questions & Answers

How to list files which have same size?

Hi guys, I need to do 100 files comparison after I sorted the files. There are no specific key for sorting so i plan to arrange the files based on the file size. The command that i used to sort the files by size is as per below:- ls -l | sort +4rn | awk '{print $5, $9}' The problem that i... (3 Replies)
Discussion started by: shahril
3 Replies

3. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

4. UNIX for Dummies Questions & Answers

How to get size of a list of files with specified extension?

Command ls -l *cpp lists all cpp program files in a directory. It shows the size of each file. Using a calculator to work out the total size of the cpp files would be very tedious. Is there a way to get the total size from the command line? (5 Replies)
Discussion started by: resander
5 Replies

5. Linux

Determining L2 cache size

Is there any way to know the L2 cache size from examinging to boot log. Here is my boot logLinux version 2.6.13-jaluna (root@localhost.localdomain) (gcc version 3.2.2) #4 Thu Apr 23 23:16:10 EDT 2009 TMS320DM643X port (C) VirtualLogix and others Designed for the EVMDM6437 board, Spectrum Digital... (3 Replies)
Discussion started by: mourya
3 Replies

6. UNIX for Dummies Questions & Answers

cat a list of directory paths only to a file

Hi! I would like to funnel a series of directories and subdirectories into a text file. This is the output I would like to see from a find command: /mypath/ABC_01/VISIT_01 /mypath/ABC_01/VISIT_02 /mypath/ABC_01/VISIT_03 /mypath/ABC_02/VISIT_01 /mypath/ABC_03/VISIT_01 I've tried: find... (2 Replies)
Discussion started by: goodbenito
2 Replies

7. Shell Programming and Scripting

How to read a list of paths from a file?

Hi everyone! I'm pretty bad at shell scripting and I am trying to create a java launcher. The idea is to store in a configuration file different paths (each for a different java version) and then, run a .sh file that would read the specified java path and execute the .jar file. This is what i have... (7 Replies)
Discussion started by: mostacholoco
7 Replies

8. Shell Programming and Scripting

list the files with size in bytes

hi all plz help in listing the files with size in bytes. thnks -Bali (4 Replies)
Discussion started by: balireddy_77
4 Replies

9. UNIX for Dummies Questions & Answers

Files list which are more than 300 MB size

Hi, I need to find files list which are more than 300 MB size? My script It should search all inner directories too. How can I proceed? Any idea? (2 Replies)
Discussion started by: redlotus72
2 Replies

10. UNIX for Advanced & Expert Users

Command to list Files less than or equal to 2k size

Hi, *.xml files stored on date wise folders. I need to extract *.xml files from all the folders. File size is lessthan or equal to 2K. Please let me know command or some shell program to due this job on linux m/c This is urgent, Thanks in advance - Bache Gowda (3 Replies)
Discussion started by: bache_gowda
3 Replies
Login or Register to Ask a Question