• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to gzip all or specific files in Linux

by admin

The gzip (GNU zip) utility is older and less efficient than bzip2. Its flags and operation are very similar to those of bzip2. A file compressed by gzip is marked with a .gz filename extension. Linux stores manual pages in gzip format to save disk space; likewise, files you download from the Internet are frequently in gzip format.

To gzip all the files in current directory, we can use for command. The below example will gzip all the files from /var/log/audit directory.

gzip all the files

1. Change the directory to audit logs as follows:

# cd /var/log/audit

2. Execute the following command in the audit directory:

# pwd
/var/log/audit
# ls
audit.log  audit.log.1  audit.log.2  audit.log.3  audit.log.4
# for LOG in audit*
do 
    gzip $LOG
done

3. This will zip all the files in audit directory. Verify the gzipped log file in the /var/log/audit directory:

# ls
audit.log.1.gz  audit.log.2.gz  audit.log.3.gz  audit.log.4.gz  audit.log.gz

Unzip all files

1. To unzip all the files in one go, execute the following command:

# for LOG in audit*
do 
    gunzip $LOG
done

Verify the unzipped files in the directory:

# ls
audit.log  audit.log.1  audit.log.2  audit.log.3  audit.log.4

gzip specific files only

To gzip some specific files only, use the below gzip command:

# gzip -c file file1 test > gzip.gz

This will create the gzip.gz file in the current directory which includes the files specified with -c option.

Filed Under: Linux

Some more articles you might also be interested in …

  1. gcov: command not found
  2. How to disable the default apache “Welcome Page” in CentOS/RHEL 7
  3. How to disable timeout in ssh during login prompt (login session inactivity) in Linux
  4. getsebool Command in Linux
  5. sshpass Command: Non-interactive Password Authentication with SSH
  6. How to extend ASM disk from OS level in CentOS/RHEL
  7. shred Command Examples in Linux
  8. How to clean YUM cache in CentOS / RHEL
  9. arp Command Examples in Linux
  10. certbot: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright