filesize from a file which has the list of files.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers filesize from a file which has the list of files.
# 1  
Old 04-08-2003
filesize from a file which has the list of files.

i have a file myfile. it has the below entries
/temp/firstfile
/temp/secondfile
and many more..

okay, now, i want to addup all the space occupied by this file

hmmm, but i met with a problem in getting each file out.
i did a silly command like more myfile | grep temp | ls -ltr

and it failed me....

any help. thanks!
yls177
# 2  
Old 04-08-2003
This should work.

files=`cat myfile`
total=0
for i in $files
do
size=`ls -l $i| awk '{print $5}'|sed 's/ //g'`
total=`expr $total + $size`
done
echo $total

I think there is a way with a single ls | awk but can't remember how to do it off the top of my head.
# 3  
Old 04-08-2003
thanks, it works birlliantly...

i am still tryign to learn the power of scripting.. it will makes unix administration easier.. Smilie
yls177
# 4  
Old 04-10-2003
Here's a different way:

l -a `cat myfile` | awk '{total += $5} END {print total}'

If you want to store the total in a variable:

files=`cat myfile`
total=`l -a $files | awk '{total += $5} END {print total}'`
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While loop a file containing list of file names until the files are found?

Hi, I have a control file which will contain all filenames(300) files. Loop through all the file names in the control files and check the existence of this file in another directory(same server). I need to infinitely(2 hrs) run this while loop until all the files are found. Once a file is found,... (5 Replies)
Discussion started by: laknar
5 Replies

2. Programming

Perl - Moving file based upon filesize in folder

Hi I'm trying to look through a series of directories in A folder, lets just call it A: for example: A/1 A/2 A/3 Etc and I wish to move the files in the folder if they are bigger than a certain size into a structure like below: A/TooBig/1 A/TooSmall/1 A/TooBig/2 A/TooSmall/2... (1 Reply)
Discussion started by: PerlNewbRP
1 Replies

3. Shell Programming and Scripting

File that Contains a List of Files

I have a first text file (LoopFiles.txt) that contains another list of text files. I need to run NAWK commands on each of the files that are listed in the first text file. I have proven the existence of the first file with ls -l But I get a message that my first file doesnt exist. cd... (5 Replies)
Discussion started by: he204035
5 Replies

4. Shell Programming and Scripting

Get filesize and checksum of spooled file in a log file ...

Hi All, I have spooled some data in a file (a.dat, b.dat etc..) and after that I want to get the size and checksum of spooled file (a.dat, b.dat etc..) in a log file(file_info.log). By the way I dont want lost the previous output file info(Append data). View of log file that I want to... (5 Replies)
Discussion started by: ce_emre21
5 Replies

5. Shell Programming and Scripting

File name from a List of files

Hi, Greetings!! I'm grepping a string from a series of files, using the below code (how ever the awk is not grepping between 'from' & 'to' time!) awk '$0>=$from&&$0<=$to' from=$START_TIME to=$STOP_TIME $logpath/UL_`date +%Y%m%d`_Scheduler*.log.csv > temp-grep.txt Out of 50 files,... (9 Replies)
Discussion started by: bhargav_k
9 Replies

6. Shell Programming and Scripting

Take a list if strings from a file and search them in a list of files and report them

I have a file 1.txt with the below contents. -----cat 1.txt----- 1234 5678 1256 1234 1247 ------------------- I have 3 more files in a folder -----ls -lrt------- A1.txt A2.txt A3.txt ------------------- The contents of those three files are similar format with different data values... (8 Replies)
Discussion started by: realspirituals
8 Replies

7. Shell Programming and Scripting

Need help in finding filesize , moving file , gzipping file

Hi , Please help with the following questions 1) how can i find size of a file ? i have written du -k $flname > s1 . Is this right ? Any other better suggeastions ? 2) how do I use mv command for moving the file ? I need the syntax with some examples 3) Command for printing the total... (1 Reply)
Discussion started by: Learning!
1 Replies

8. Shell Programming and Scripting

ls > file - Creating file containing the list of all files present in a directory

Hi All, I need to create a file which contains the list of all the files present in that directory. e.g., ls /export/home/user/*.dat > list_file.dat but what i am getting is: $ ls /export/home/user/*.dat > list_file.dat /export/home/user/*.dat: No such file or directory But I have... (1 Reply)
Discussion started by: pranavagarwal
1 Replies

9. Shell Programming and Scripting

Sort top 5 files by FileSize

Hi All, i have one simple question on unix command. I have number files under one directiory and includes sub directories as well. Here, i need to find top 5 files whose sizes are big when compared to other files in ascending or descending order. please note that i need unix command for this... (3 Replies)
Discussion started by: dbsurf
3 Replies

10. Shell Programming and Scripting

Capture output of program to file with limited filesize

I'm working on a script that will perform a backup, save a log of said backup and send the output to me in an email. Everything is working fine so far except that I can't figure out how to specify a maximum file size for the log file. I don't want a runaway log file jamming up the server.... (7 Replies)
Discussion started by: spectre_240sx
7 Replies
Login or Register to Ask a Question