Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

bash - Unix/Linux display average file size with restriction

how do I display the average file size (rounded down). Use only: cat, echo, ls, wc, here is what I was able to do so far: echo "$(cat * | wc -w; ls -l | wc -l)" I have both of the numbers, I just can't divide them, any help would be appreciated and thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Is it allowed to use the shell for the division?

$ ls -l
total 20
-rw-r--r-- 1 james james  968 Dec 29  2016 bar
-rw-r--r-- 1 james james  900 Dec 29  2016 bar.asc
-rw-r--r-- 1 james james   39 Dec 29  2016 compr.txt
-rw-r--r-- 1 james james 1056 Dec 28  2016 foo
-rw-r--r-- 1 james james  896 Dec 29  2016 foo.asc
$ cat * | wc -c
3859
$ ls | wc -l
5
$ echo $(( $(cat * | wc -c) / $(ls | wc -l) ))      # solution part
771
$ echo 5*771 | bc 
3855

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...