Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Compress Files on macOS Using Terminal

File compression is a crucial task for saving disk space, transferring files efficiently, and organizing data. On macOS, file compression can be easily achieved using the Terminal, which provides powerful command-line tools. This article will guide you through the process of compressing files and directories using Terminal on macOS. We will explore the zip and tar commands, which are commonly used for file compression in Unix-based systems like macOS.

Examples:

  1. Compressing Files Using zip Command:

    The zip command is used to create compressed files with a .zip extension. Here is how you can compress a single file and multiple files:

    • Compress a Single File:

      zip compressed_file.zip original_file.txt

      This command will compress original_file.txt into compressed_file.zip.

    • Compress Multiple Files:

      zip compressed_files.zip file1.txt file2.txt file3.txt

      This command will compress file1.txt, file2.txt, and file3.txt into compressed_files.zip.

    • Compress a Directory:

      zip -r compressed_directory.zip directory_name

      The -r option stands for "recursive," which means it will compress the entire directory and its contents into compressed_directory.zip.

  2. Compressing Files Using tar Command:

    The tar command is another powerful tool for creating compressed archives. It is often used in conjunction with gzip or bzip2 for compression.

    • Create a tar.gz Archive:

      tar -czvf compressed_archive.tar.gz directory_name

      The options used here are:

      • -c: Create a new archive
      • -z: Compress the archive using gzip
      • -v: Verbose mode (shows the progress in the Terminal)
      • -f: Specify the filename of the archive
    • Create a tar.bz2 Archive:

      tar -cjvf compressed_archive.tar.bz2 directory_name

      The -j option is used to compress the archive using bzip2.

    • Extracting tar.gz Archive:

      tar -xzvf compressed_archive.tar.gz

      This command will extract the contents of compressed_archive.tar.gz.

    • Extracting tar.bz2 Archive:

      tar -xjvf compressed_archive.tar.bz2

      This command will extract the contents of compressed_archive.tar.bz2.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.