0

I often need to compress archives in Linux. is there a simpler way instead of always building such complicated commands?

tar zcvf /tmp/mybackup.tar.gz /home/important
Gill-Bates
  • 585
  • 2
  • 8
  • 23

1 Answers1

2

An alias would mean you don't have to remember the zcvf options. You can name the alias whatever you want as long as it is one word.

Create the alias in your terminal with

alias archive='tar zcvf'

and then your command becomes

archive /tmp/mybackup.tar.gz /home/important

If you like this alias, make it permanent by adding it to your ~/.bashrc. (Or whatever config file is sourced by the shell you are using.) Then every new terminal you open will have the alias already configured and ready to use.

localarrow
  • 36
  • 1
  • 1
    A suggestion: use `acvpf` flags instead, so tar will determine a stream compressor from the file extension, and also to preserve permissions. The same alias would work for any archive type: `archive backup.tar.xz /files /to /backup` will commress with `xz`, while `archive anotherbackup.tar.zst /different /files` will use `zstd`. `gzip`, `bzip2`, `lzo` — all of them will work. – Nikita Kipriyanov Nov 03 '22 at 13:19
  • Good idea @NikitaKipriyanov! – localarrow Nov 04 '22 at 19:03