Linuxopsys Profile picture
Dec 28 16 tweets 3 min read Read on X
When it comes to creating backups, packaging software source code for distribution, and managing files in Linux, the tar command is no doubt one of the widely used archiving utilities.

Learn more in this guide: Image
Tar command which is abbreviated as tape archive is used to group files into archives called tarballs and also compress files using popular compression algorithms such as gzip, bzip2, and xz.
Common Options

The picture below lists the most common options you can use with the tar command to perform different operations. Image
tar Command Operations

Now let's look at some common operations you can do with the tar command:
1. Create

The -c option can be used to combine multiple files into an archive called a tarball. Here is an example of creating archives using the tar command:

$ tar -cf archive.tar file1 file2
2. Compress

Compressing is different from creating an archive in the sense that archiving uses the same amount of disk space as all the individual files and directories combined, whilst compression reduces the size.
The option for compressing files depends on the type of algorithm you want to use. To create and compress an archive using gzip use the -z option:

$ tar -czf archive.tar.gz file1 file2
Tar offers a good option, -a, that intelligently determines the compression algorithm from the specified archive suffix or extension. Compressing an archive using the xz compression algorithm, for example, you would use:

$ tar -caf archive.tar.xz file1 file2
3. Extract

The -x option can be used for extracting or uncompressing archives. Here is an example of extracting an archive in the current working directory:

$ tar -xf archive.tar
If you want to extract an archive to a specific directory use the -C option followed by the directory where you want the files to be extracted:

$ tar -xf archive.tar -C directory-path
4. Concatenate

If you have two or more archives you can concatenate or combine them using the -A option:

$ tar -Af archive.tar archive2.tar
Tar command gives you the ability to add more files to an already existing archive without having to extract and archive the files again. To append files to an archive use the -a option or -r option:

$ tar -rf archive.tar file_to_append
$ tar -af archive.tar file_to_append
5. List

The -T option can be used to list the contents of an archive. This option is very handy if you just want to have a peek at a large archive without extracting it:

tar -tf archive.tar
Summing up!

This thread demonstrated how to use the tar command with practical examples and some of its available options that can help you to perfom different operations.

If you get stuck with this command, feel free to refer to the man pages or the command help menu.
That’s all!

Hope you learn something new from this thread? If so, please let us know by replying in the comments.

If you're new here, do toss us a follow us (@linuxopsys) for more threads, tips and resources on Linux.
Also join 1000+ subscribers inside our newsletter "PenguinChronicles " and never miss any Linux, sysdmin and DevOps content:

linuxopsys.com/subscribe-news…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Linuxopsys

Linuxopsys Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @linuxopsys

Dec 29
In addition to UGO/RWX permissions and ACLs (Access Control Lists), Linux uses file and directory attributes to control the level of access that system programs and users have to files.

Let’s dive in! Image
File and directory attributes can be set and removed using different commands and utilities. Let's explore some commonly used attributes and how to manage them.
1. Immutable Attribute:

The immutable attribute prevents a file or directory from being modified, renamed, or deleted, even by the root user. It provides an extra layer of security to critical system files or sensitive data.
Read 23 tweets
Dec 20
pushd and popd are very underutilized commands, yet incredibly powerful.

These cmds give you the ability to manage your directory stack and easily switch between directories, making them a must-have tool for any Linux user looking to maximize their efficiency and productivity Image
In this thread, I'll show you how to use the pushd and popd commands to unlock the power of easy system directory navigation and streamline your workflow.
First let's understand what a Directory Stack is?

The Directory Stack is an ordered list of directories that have been accessed during navigation.

The contents of the Directory Stack can be viewed through the execution of the dirs command.
Read 29 tweets
Dec 18
If you want to learn Linux bash scripting for FREE, open this:

A collection of comprehensive bash scripting guides. Image
1. What is Shell in Linux

In this guide, let's learn about the shell which is an important part of the Linux operating system which interprets and passes the commands you provide on your keyboard to the operating system to perform some specific tasks

linuxopsys.com/topics/what-is…
Image
2. Bash variable assignment

A variable is a named storage location in a program's memory where a value can be stored, retrieved, and manipulated. Like any programming language, Variables are an essential component in the Bash scripts.

linuxopsys.com/topics/assign-…
Image
Read 56 tweets
Dec 14
If you want to learn Linux for FREE, open this (a thread of our Linux threads): Image
1. Permissions

The operating system controls file access in Linux by utilizing file permissions, attributes, and ownership. In Linux, file permissions, attributes, and ownership determine the level of access that system programs and users have to files.

2. paste command in Linux explained

(simple yet powerful way to merge and organize data from multiple text files):

Learn more about the paste command in this master guide:

Read 40 tweets
Nov 17
Most people who know Git think of it as a software project repository. It's actually more than that. It's useful for any type of file, but especially for config files that are updated regularly.

Git is a valuable tool not for only programmers, but also for sysadmins: Image
Using git can simplifies the administrator's life in a variety of ways.

Learn these 23 Git commands as you'll be using them 99% of the time as a system administrator:
1. git add

Used to add files to the staging area. Before a file is available to commit to a repository, the file needs to be added to the staging area also know as git index.

$ git add < file or directory>

To add all unstaged files use:

$ git add .
Read 30 tweets
Nov 2
12 Linux sed command practical examples🐧 Image
What is sed?

The Linux sed command is a stream editor that is used to process text file content like searching for patterns, finding and replacing, insertion, and deletion.
Now that you understand what sed is, let's look at some of the things you can do with it.
Read 20 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(