ArticleslgStudy

computer science

Sum (Unix)

Sum (Unix) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Sum (Unix) rather than just read about it. In short: sum is a legacy utility available on some Unix and Unix-like operating systems. This utility outputs a 16-bit checksum of each argument file, as well as the number of 1 KiB blocks, rounded up, that they occupy on the disk.

Key takeaways

  • Sum (Unix) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Sum (Unix) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Sum (Unix) from memory before moving on to harder problems.

Reference excerpt

sum is a legacy utility available on some Unix and Unix-like operating systems. This utility outputs a 16-bit checksum of each argument file, as well as the number of 1 KiB blocks, rounded up, that they occupy on the disk. Two different checksum algorithms are in use. POSIX abandoned sum in favor of cksum.

Overview The sum program is generally only useful for historical interest. It is not part of POSIX. Two algorithms are typically available: a BSD checksum and a SYSV checksum. Both are weaker than the already weak 32-bit CRC used by cksum. The default algorithm on FreeBSD and GNU implementations is the BSD checksum. Switching between the two algorithms is done via command line options. The two commonly used algorithms are as follows. The BSD sum, -r in GNU sum and -o1 in FreeBSD cksum:

Initialize checksum to 0 For each byte of the input stream Perform 16-bit bitwise right rotation by 1 bit on the checksum Add the byte to the checksum, and apply modulo 2 ^ 16 to the result, thereby keeping it within 16 bits The result is a 16-bit checksum The above algorithm appeared in Seventh Edition Unix. The System V sum, -s in GNU sum and -o2 in FreeBSD cksum:

checksum0 = sum of all bytes of the input stream modulo 2 ^ 32 checksum1 = checksum0 modulo 2 ^ 16 + checksum0 / 2 ^ 16 checksum = checksum1 modulo 2 ^16 + checksum1 / 2 ^ 16 The result is a 16-bit checksum calculated from the initial 32-bit plain byte sum

Syntax The sum utility is invoked from the command line according to the following syntax:

sum [OPTION]... [FILE]...

with the possible option parameters being:

-r use BSD checksum algorithm, use 1K blocks (defeats -s) -s, --sysv use SYSV checksum algorithm, use 512 bytes blocks --help display the help screen and exit --version output version information and exit When no file parameter is given, or when FILE is -, the standard input is used as input file. Example of use:

Example of -s use in GNU sum:

Example of using standard input, -r and printf to avoid newline:

See also GNU Core Utilities UnxUtils port to native Win32

References

External links sum in The Single UNIX ® Specification, Version 2, 1997, opengroup.org – does not specify checksum algorithm C.4 Utilities in The Open Group Base Specifications Issue 7, 2018 edition, opengroup.org – indicates sum as removed sum(1) – Version 7 Unix Programmer's Manual sum(1) – manual pages from GNU coreutils sum(1) – FreeBSD General Commands Manual – states the sum algorithms in options -o1 and -o2 to cksum sum(1) – Linux User Manual – User Commands from Manned.org sum(1) – Solaris 11.4 User Commands Reference Manual The Unix Tree, tuhs.org – the source code of old versions of Unix

Worked examples

Example 1 — a first encounter with Sum (Unix)

Start with the simplest possible case. Write down what Sum (Unix) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Sum (Unix) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Sum (Unix) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Sum (Unix)

In research
Sum (Unix) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Sum (Unix) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Sum (Unix) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Linux package management-related software, Linux security software, Unix package management-related software, so understanding it makes those chapters shorter.
In everyday life
Look for Sum (Unix) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Sum (Unix)” →

How to study Sum (Unix) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Sum (Unix) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Sum (Unix) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Sum (Unix) in simple terms?

sum is a legacy utility available on some Unix and Unix-like operating systems. This utility outputs a 16-bit checksum of each argument file, as well as the number of 1 KiB blocks, rounded up, that they occupy on the disk.

Why does Sum (Unix) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Sum (Unix)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Sum (Unix).

Tags

  • Linux package management-related software
  • Linux security software
  • Unix package management-related software
  • Unix security-related software

Keep exploring