How to calculate the total size of all files from ls- l by using cut, eval, head, tr, tail, ls and echo

 ls -l | tr -s " " | cut -d " " -f5

I tried above code and got following output.

158416 757249 574994 144436 520739 210444 398630 1219080 256965 684782 393445 157957 273642 178980 339245

How to add these numbers. I'm stuck here. Please no use of awk, perl, shell scripting etc.

It's easiest to use du. Somethings like:

du -h -a -c | tail -n1

Will give you the sum total. You can also use the -d argument to specify how deep the traversing should go like:

du -d 1 -h -a -c | tail -n1

You will have to clarify what you mean by "no use of shell scripting" for anyone to come up with a more meaningful answer.

How do I add the file size output together, How to calculate the total size of all files from ls- l by using cut, eval, head, tr, tail, ls and echo - bash. You need to pass the -S or --sort=size option as follows to Linux or Unix command line: $ ls --sort=size -l. $ ls --sort=size *.avi. $ ls -S -l *.avi. Sample outputs: Fig.02: Sort files / folders (directories) by size. You will see largest file first before sorting the operands in lexicographical order. The following command will sort file size

You can try this way but $((...)) is shell scripting

eval echo $(( $(ls -l | tr -s ' ' | cut -d ' ' -f5 | tr '\n' '+')  0 ))

linux - How do I add the file size output together, echo "$(($(LC_ALL=C ls -nq | tr -s ' ' | cut -d ' ' -f5 | tail -n +2 | tr '\n' +)0))" files are devices files for which the ls -l output doesn't have the size in 5th column is in the form: ${parameter//find/replace} , or in our example ${var// /+} . double slashes `//` are for replacing all occurrences of space with `+` sign,  First I have to search the files using FIND command that will show only the files for December 2012 . Secondly I need to see the total size of files searched. I used this command. find /storage/backup/rman/ -mtime +90 -mtime -120 -exec ls -lrth {} \; But it also gave me the files of November which I don't want

Don't parse the output of ls. It's not meant for parsing. Use du as with Martin Gergov's answer. Or du and find, or just du.

But if just adding numbers is the sole focus, (even if the input is iffy), here's the laziest possible method (first install num-utils):

ls -l | tr -s " " | cut -d " " -f5 | numsum

And there's other ways, see also: How can I quickly sum all numbers in a file?

[Solved] Assume you have bunch of 10 to 15 files with text data in it , echo "$(($(LC_ALL=C ls -nq | tr -s ' ' | cut -d ' ' -f5 | tail -n +2 | tr '\n' +)0))" files are devices files for which the ls -l output doesn't have the size in 5th column is in the form: ${parameter//find/replace} , or in our example ${var// /+} . double slashes `//` are for replacing all occurrences of space with `+` sign,  I know I can use du -h to output the total size of a directory. But when it contains other subdirectories, the output would be something like: du -h /root/test . . . . 24K /root/test/1 64K /r

Techne Public Site - Bash Commands, Use only: cat, echo, ls, wc. b) Give a command to calculate the total file size of all the files. Use only: cut, echo, eval, head, ls, tail, tr to display average of the size of files which has a syntax given as: ls -l | gawk ' { sum+= $5;  Short answer: ls -l gives the size of the file (= the amount of data it contains); ls -s --block-size 1 gives the size of the file on the file system; Let's create two files: A sparse file of 128 bytes length (A sparse file is a file containing empty blocks, see Sparse File):

Advanced Bash-Scripting Guide, To debug an entire script, use this at the head of the file: for i in `ls -1` ; do echo ${i#2} ; done (shows 008_01s) ssh -N -L 47408:164.67.183.179:22 login3 one command, and it's a line in a file, you can find the command with tail (or head​, or grep), Split a file into multiple files at every occurrence of the pattern START​:. On Unix-like operating systems, the ls command lists information about files and directories. This document covers the GNU / Linux version of ls. ls lists files and directories, and their associated metadata, such as file size, ownership, and modification time. With no options, ls lists the files contained in the current directory, sorting them

Bash-Oneliner, Backup of all files changed in last day; 4-1. Using eval to select among variables; 15-13. The sha-bang ( #!) [6] at the head of a script tells your system that this bash$ touch .hidden-file bash$ ls -l total 10 -rw-r--r-- 1 bozo 4034 Jul 18 echo ls -l | sh # Passes the output of "echo ls -l" to the shell, #+ with  When I do an ls -l command I can get the size of files, but I can't get the total size of a directory -- i.e. the size of everything below that directory. Your original question did not state that that was all you wanted, and you've been introduced to df and du --- I was simply commenting on the fact that ls -l did not give you the summary

Comments
  • What is the point of restricting yourself to those tools? Is this some kind of puzzle?
  • See: Unix/Linux display average file size with restriction
  • @oguzismail or some kind of homework assignment. See also stackoverflow.com/q/52565341/1255289
  • If you aim to avoid all forms of programming, then this question is off topic for StackOverflow. Try SuperUser or Unix&Linux