- .tar: archiving (putting files together into 1 folder) in Unix
- .gz: compression in Unix
- .tar.gz: archiving + compression in Unix
- .zip: archiving + compression in Windows
To compress a directory:
tar -cvf <archive_name>.tar <directory_to_compress>
e.g.
tar -cvf test.tar tar-experiment
To combine multiple files and/or directories into a single file, use the following command:
tar -cvf <archive_name>.tar <file_1> <file_2> <to> <file_n>
e.g.
tar -cvf test.tar test1.txt test2.txt test3.txt
To extract the file:
tar -xvf archive_name.tar
e.g.
tar -xvf test.tar
Compress a file:
gzip -c <file_name>.txt > <file_name>.txt.gz
e.g.
gzip -c test.txt > test.txt.gz
Deflate/ Extract a file:
gzip -d <file_name>.gz>
e.g.
gzip -d file.gz
To archive and compress a directory:
tar -zcvf <archive_name>.tar.gz <directory_to_compress>
e.g.
tar -zcvf test.tar.gz test.txt
To decompress and extract the file:
tar -zxvf <archive_name>.tar.gz
e.g.
tar -zcvf test.tar.gz test.txt
zgrep: grep gzipped files zcat: cat gzipped files
zgrep <pattern> <file_name>.gz
e.g.
zgrep Tomy test.txt.gz
zcat <file_name>.gz | more
zcat -f <file_name> | more
- Add the below Maven Dependency
<dependency>
<groupId>log4j</groupId>
<artifactId>apache-log4j-extras</artifactId>
<version>1.2.17</version>
</dependency>
- Use the sample log4j.xml below (Feel free to copy paste):
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<appender name="default.file" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="ActiveFileName" value="./logs/HomeyFood.log" />
<param name="FileNamePattern" value="./logs/HomeyFood.log.%d{yyyyMMdd}.gz" />
</rollingPolicy>
<param name="append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1} - %m%n" />
</layout>
</appender>
<appender name="async" class="org.apache.log4j.AsyncAppender">
<param name="BufferSize" value="5000" />
<appender-ref ref="default.file" />
</appender>
<root>
<level value="info" />
<appender-ref ref="async" />
</root>
</log4j:configuration>
- http://unix.stackexchange.com/questions/46786/how-to-tell-gzip-to-keep-original-file
- http://www.cyberciti.biz/faq/linux-unix-bsd-extract-targz-file/
- http://www.simplehelp.net/2008/12/15/how-to-create-and-extract-zip-tar-targz-and-tarbz2-files-in-linux/
- http://askubuntu.com/questions/122141/whats-the-difference-between-tar-gz-and-gz-or-tar-7z-and-7z
- http://stackoverflow.com/questions/11534918/are-tar-gz-and-tgz-the-same-thing