'/bin/sh: 1: compress: not found

I'm very new in this world of bash scripting, so please be patient.

I'm following a basic guide to bash, repeating each script the guide shows.

This one:

#!/bin/bash
SRCD="/home/"
TGTD="/var/backups/"
OF=home-$(date +%Y%m%d).tgz
tar -cZf $TGTD$OF $SRCD

output THIS error:

/bin/sh: 1: compress: not found
tar: Child returned status 127
tar: Error is not recoverable: exiting now

Can someone explain to me what it means?



Solution 1:[1]

From the tar manual:

-Z, --compress, --uncompress
filter the archive through compress

… and the error message:

compress: not found

So you've told it to pass the output of tar through compress and it is telling you that compress isn't found (probably because you haven't installed it).

People generally use gzip this century though (or bzip2 which gives smaller files but is slower), not compress.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Quentin