Linux 101: How to compress a folder from the command line with tar – TechRepublic

Register for your free TechRepublic membership or if you are already a member, sign in using your preferred method below.
We recently updated our Terms and Conditions for TechRepublic Premium. By clicking continue, you agree to these updated terms.
Invalid email/username and password combination supplied.
An email has been sent to you with instructions on how to reset your password.
By registering, you agree to the Terms of Use and acknowledge the data practices outlined in the Privacy Policy.
You will also receive a complimentary subscription to TechRepublic’s News and Special Offers newsletter and the Top Story of the Day newsletter. You may unsubscribe from these newsletters at any time.
Username must be unique. Password must be a minimum of 6 characters and have any 3 of the 4 items: a number (0 through 9), a special character (such as !, $, #, %), an uppercase character (A through Z) or a lowercase (a through z) character (no spaces).
Linux 101: How to compress a folder from the command line with tar
Your email has been sent
At some point in your Linux journey, you’ll need to be able to compress and decompress a folder from the command line. Jack Wallen shows you how.
The Linux command line is an incredibly powerful tool. From the CLI there’s next to nothing you can’t do. And although a GUI might make some of the tasks a bit easier, the simplicity of doing your work in a terminal window is about as elegant a solution as you’ll find.
SEE: 5 Linux server distributions you should be using (TechRepublic Premium)
Take, for instance, the task of compressing a folder. Sure, you could open a file manager, right-click a folder, and select Compress. But what if you’re on a headless server? A Linux without a GUI isn’t going to offer you a point-and-click affair. So what do you do?
You turn to the tar command, which makes short shrift of converting folders into compressed files.
Let me show you how this is done. Let’s say you have a folder named TEST and you want to compress it into a single file so you can more easily send it to someone or save it as a backup. To do this, log into your Linux machine and change into the directory housing the TEST folder.
SEE: Rust: What developers need to know about this programming language (free PDF) (TechRepublic)
The command we’ll run is tar -zcvf TEST.tar.gz TEST.
The options we used are z (for compress), c (for create), v (for verbose output), and f (for force).
After running the command, you’ll find the newly created TEST.tar.gz. The tar portion of the extension means the file is a tar archive and the gz indicates it’s been compressed.
You could then decompress that new file with the command tar -xvzf TEST.tar.gz.
If you wanted to view the files within that archive (without decompressing and extracting), you could issue the common tar -ztvf TEST.tar.gz and tar would list out the contents for you.
And that’s pretty much all you have to do to compress a folder from the command line with tar.

Image: Jack Wallen

You don’t want to miss our tips, tutorials, and commentary on the Linux OS and open source applications.
Linux 101: How to compress a folder from the command line with tar
Your email has been sent
Your message has been sent
TechRepublic Premium content helps you solve your toughest IT issues and jump-start your career or next project.
These 11 cloud-to-cloud solutions back up your organization’s data so you’ll be covered in the event of deletions, malware or outages. Compare the best online cloud backup services now.
You can use a mobile device to speak with another person directly through the Teams app. Lance Whitney shows you how to use this handy feature.
A phishing technique called Browser in the Browser (BITB) has emerged, and it’s already aiming at government entities, including Ukraine. Find out how to protect against this new threat.
With so many project management software options to choose from, it can seem daunting to find the right one for your projects or company. We’ve narrowed them down to these nine.
Start-ups, DARPA and Accenture Ventures announce research partnerships, new hardware and strategic investments.
Procuring software packages for an organization is a complicated process that involves more than just technological knowledge. There are financial and support aspects to consider, proof of concepts to evaluate and vendor negotiations to handle. Navigating through the details of an RFP alone can be challenging, so use TechRepublic Premium’s Software Procurement Policy to establish …
Recruiting a Security Analyst with the right combination of technical expertise and experience will require a comprehensive screening process. This hiring kit from TechRepublic Premium includes a job description, sample interview questions and a basic want ad that you can customize for your business to find, interview, recruit and hire the best candidates for a …
Recruiting a DevOps engineer with the right combination of technical expertise and experience will require a comprehensive screening process. This hiring kit from TechRepublic Premium includes a job description, sample interview questions and a basic want ad that you can customize for your business to find, interview, recruit and hire the best candidates for a …
Video game writing jobs are in demand. Recruiting a video game/quest writer with the right combination of technical expertise and experience will require a comprehensive screening process. This hiring kit from TechRepublic Premium includes a job description, sample interview questions and a basic want ad that you can customize for your business to find, interview, …

source

We will be happy to hear your thoughts

Leave a reply

LINXGO
Logo
Compare items
  • Total (0)
Compare