LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 01-29-2014, 12:56 PM   #1
dotran
LQ Newbie
 
Registered: Apr 2012
Posts: 27
Blog Entries: 2

Rep: Reputation: Disabled
Help with list filename with total size and divide by 555555


Is the way can run one command line get total size and divide by 555555. Thanks

/export/home/mytmp/test1> ls -ltr testing*
-rw-r--r-- 1 ca7prod ftpusers 1179207454 Jan 24 10:18 testing_sftp1_MKT60000_20140108211807_F001.gz
-rw-r--r-- 1 ca7prod ftpusers 1179207454 Jan 27 11:00 testing_sftp2_MKT60000_20140108211807_F001.gz
-rw-r--r-- 1 ca7prod ftpusers 1179207454 Jan 27 11:12 testing_direc1_F001.gz
-rw-r--r-- 1 ca7prod ftpusers 1179207454 Jan 27 11:18 testing_direc2_F001.gz
/export/home/mytmp/test1> find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}'
4716829816
I try many way but not work.
/export/home/mytmp/test1> find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}' /555555 |bc

I like get output:
/export/home/mytmp/test1> echo 4716829816/555555 |bc
8490
 
Old 01-29-2014, 01:26 PM   #2
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
If
Code:
find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}'
spits out 4716829816

Why not try this,
Code:
MyVar=$(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}')
echo (( $MyVar/555555 ))
spits out 8490 here also.

so, to use it at-will, use MyVar in a function:
Code:
GetFilesSizes {
MyVar=$(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total})
}
NOTE: I suspect this may have to be an
Code:
export MyVar=$(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total})
but I'm not certain of that.

then
Code:
echo (( $MyVar/555555 ))
To call it inside a script...
Code:
#!/bin/bash
do stuff
GetFilesSizes
echo (( $MyVar/555555 ))
do more stuff
...
#EOF
Smarter folks than I will have (no doubt) a better method of achieving the same result.

Last edited by Habitual; 01-29-2014 at 01:38 PM.
 
Old 01-29-2014, 01:37 PM   #3
dotran
LQ Newbie
 
Registered: Apr 2012
Posts: 27
Blog Entries: 2

Original Poster
Rep: Reputation: Disabled
No...that' second command line. I want run one command line list filename get total sizie and divide by 5555 and output (xxxx)

This command already work just need add divide by 55555 and I can't make it work.
find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}'
 
Old 01-29-2014, 01:41 PM   #4
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
Quote:
Originally Posted by dotran View Post
No...that' second command line. I want run one command line list filename get total sizie and divide by 5555 and output (xxxx)

This command already work just need add divide by 55555 and I can't make it work.
find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}'
try
Code:
$(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}') / 55555 | bc
Please use [code][/code] tags. See my signature for the 411 on how to do that. - Thanks.

Last edited by Habitual; 01-29-2014 at 01:45 PM.
 
Old 01-29-2014, 01:52 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You can also reduce the output of find using -printf and do the calculation with awk:
Code:
find /export/home/mytmp/test1 -name testing\* -printf "%s\n" | awk '{sum+=$1} END{printf "%d\n", sum/55555}'

Last edited by colucix; 01-29-2014 at 01:57 PM.
 
Old 01-29-2014, 02:16 PM   #6
dotran
LQ Newbie
 
Registered: Apr 2012
Posts: 27
Blog Entries: 2

Original Poster
Rep: Reputation: Disabled
somehow still can't make it work.
#!/bin/ksh
MyVar=$(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total
| awk '{total += $5};END {print total}') /555555 |bc >> count.txt

/export/home/mytmp/test1> ./dd.ksh
./dd.ksh[2]: /555555: not found
 
Old 01-29-2014, 03:47 PM   #7
dotran
LQ Newbie
 
Registered: Apr 2012
Posts: 27
Blog Entries: 2

Original Poster
Rep: Reputation: Disabled
Somehow still can't this code work. Anyone have different syntax? The red part is work. Please help. Thanks

#!/bin/ksh -x
MyVar=`find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total |
awk '{total += $5};END {print total}'`
| echo (( $MyVar/555555 ))

/export/home/mytmp/test1> ./dd.ksh
./dd.ksh[2]: syntax error at line 2 : `((' unexpected
 
Old 01-29-2014, 03:57 PM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
In your command (post #6) the string /555555 is interpreted literally, since the / sign is not inside an arithmetical operator. Moreover you're trying to assign the output of the command to a variable and redirect the output to a file simultaneously. It doesn't make sense.

Take a look at these variants:
Code:
echo $(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}') / 555555 | bc >> count.txt
Code:
MyVar=$(echo $(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}') / 555555 | bc)
Code:
MyVar=$(( $(find /export/home/mytmp/test1 -name "testing*" -exec ls -l {} \; | grep -v total | awk '{total += $5};END {print total}') / 555555 ))
or look at my previous post for a shorter solution.

Last edited by colucix; 01-29-2014 at 03:58 PM.
 
Old 01-29-2014, 04:16 PM   #9
dotran
LQ Newbie
 
Registered: Apr 2012
Posts: 27
Blog Entries: 2

Original Poster
Rep: Reputation: Disabled
Thanks Mr Colucix. It's worked.
 
  


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
robust total size of a list of files patrick295767 Programming 12 05-20-2012 02:57 PM
[SOLVED] [Lubuntu] Files' Size On Disk is ~ 10x Total Size Of Files! Zssfssz Linux - Software 2 02-22-2012 10:16 PM
A way to make (c)fdisk divide a drive into equal size partitions? bluesword1969 Linux - Software 1 02-11-2010 01:35 PM
Total partition size - User partition size is not equals to Free partition size navaneethanj Linux - General 5 06-14-2004 01:55 PM
How to list total file size of a directory phil1076 Linux - General 3 12-18-2003 04:47 PM


All times are GMT -5. The time now is 03:48 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