Skip to main content

FILE COMPRESSION WITH 'tar' COMMAND | LINUX SERIES


File Compression with 'tar' command:

Common Options

-c --create                   
Create a new archive.

-x --extract                 
Extract files from an archive.

-t --list                         
List the contents of an archive.

-f --file=ARCHIVE   
Use archive file or dir ARCHIVE.

-v --verbose                
Verbosely list files processed.

Compression Options -

-a --auto-compress        
Use archive suffix to determine the compression program.

-j --bzip2                       
Filter the archive through bzip2.

-J --xz --lzma                
Filter the archive through xz.

-z --gzip                        
Filter the archive through gzip.

Compress a folder

This creates a simple archive of a folder :
tar -cf ./my-archive.tar ./my-folder/

Verbose output shows which files and directories are added to the archive, use the -v option:
tar -cvf ./my-archive.tar ./my-folder/

For archiving a folder compressed 'gzip', you have to use the -z option :
tar -czf ./my-archive.tar.gz ./my-folder/

You can instead compress the archive with 'bzip2', by using the -j option:
tar -cjf ./my-archive.tar.bz2 ./my-folder/

Or compress with 'xz', by using the -J option:
tar -cJf ./my-archive.tar.xz ./my-folder/

Extract a folder from an archive

There is an example for extract a folder from an archive in the current location :
tar -xf archive-name.tar

If you want to extract a folder from an archive to a specfic destination :
tar -xf archive-name.tar -C ./directory/destination

List contents of an archive

List the contents of an archive file without extracting it:
tar -tf archive.tar.gz
Folder-In-Archive/
Folder-In-Archive/file1
Folder-In-Archive/Another-Folder/
Folder-In-Archive/Another-Folder/file2

List archive content

There is an example of listing content :
tar -tvf archive.tar

The option -t is used for the listing. For listing the content of a tar.gz archive, you have to use the -z option anymore :
tar -tzvf archive.tar.gz

Compress and exclude one or multiple folder

If you want to extract a folder, but you want to exclude one or several folders during the extraction, you can use the
--exclude option.

tar -cf archive.tar ./my-folder/ --exclude="my-folder/sub1" --exclude="my-folder/sub3"

With this folder tree :
my-folder/
sub1/
sub2/
sub3/

The result will be :

./archive.tar
my-folder/
sub2/

Strip leading components

To strip any number of leading components, use the --strip-components option:

--strip-components=NUMBER
strip NUMBER leading components from file names on extraction

For example to strip the leading folder, use:
tar -xf --strip-components=1 archive-name.tar

Peace Out.
@suhaibbinyounis

Comments

Popular posts from this blog

Make money with Quora Partner Program | Explained

Earning money ain't it...
I know we all have some time wondered if it is possible to earn money online and believe me there are many ways to do that and it is all amazing.
In this post I will specifically talk about Quora Partner Program, QPP.

Quora came out with this amazing program that allows anyone in world to make a living out of writing. But speaking the truth it is not that much. It quite a hard work and less pay job.
Bascially, all you do is ask questions and then these questions will receive Ad impressions for which you get paid.

But here is the deal, you can monetize a question only for 1 year only. After that Quora owns the question.


So, how do you get started?

As of now there is no direct way of joining the QPP. The only way for you to join is if you receive a email from Quora itself which is quite random and obviously how active you are on quora will play a part.


So, how much can i earn?
Well, there is no limit on how much you can earn. Generally the money is way too low but t…

RESOLVING NETWORK ISSUES ON LINUX | LINUX SERIES

Dealing with networking issues can be a very challenging task. A packet sent from a client to a server (or vice versa) might be dropped in various locations and for various reasons. Some of the most common cases are -
1. A firewall that is blocking the packet. It can be a firewall on the server side, on the client side or any firewall along the way between the server and the client. The blocking may be based on an ip (source and/or destination), ports (in case of tcp/udp) or any other layer 3,4 criteria.

2. Lack of layer 2 connectivity.

3. Routing configurations that are not set properly.

Fortunately, Linux command line tools supply significant information that might help us narrow down the problem. From my experience those are my top 8 tools that will help you overcome networking issues.
 ping
This is the most fundamental command when troubleshooting a networking issue. The ping command will test the network connectivity between your host and the server. This is definitely the first comman…

Magic SysRq key | Linux Rescue | Frozen Linux | LINUX SERIES

The magic SysRq key is a key combination which allows the user to perform various low-level commands regardless of the system's state. If your Linux machine freezes or you want to reboot your Linux machine without corrupting the filesystem you can use this magic SysRq key combination. This key combination provides access to powerful features and thus needs some knowledge to use it. Please do not proceed without knowing about these combinations as you may put your system in a critical state. Please note that this magic SysRq key cannot work under certain conditions, such as a kernel panic or a hardware failure preventing the kernel from running properly.
Commads:The key combination consists of Alt+SysRq and another key, which controls the command issued. SysRq may be released before pressing the command key, as long as Alt remains held down.
These combinations always assume the QWERTY keyboard layout.
1. Immediately reboot the system, without unmounting or syncing filesystems - b 2. Perfor…