How To: Compress And Decompress .bz2 Files

In today’s article, we’re going to discuss how to compress and decompress .bz2 files. This is something you may eventually need to know, so I’ll cover it here. I’ll just cover the basics, as most folks won’t need to know anything more than the basics. This should actually be a fairly short and direct article. There’s not a whole lot to it.

If you don’t already know, .bz2 files are bzip2 files. You’ll find that bzip2 is an opensource compression program that gets some regular usage, and you’ll sometimes find downloaded files that are compressed with this format. You may also, for compatibility reasons, want to compress files with bzip2 to share with other users who are already set on using the .bz2 format.

For the curious, the bzip2 man pages define this particular application as (and, as always, I highly encourage folks to read the man pages themselves – this one being a bit more complicated than others):

bzip2, bunzip2 – a block-sorting file compressor

Again, we’re going to just cover how to compress and decompress .bz2 files in this article. That’s all we’re going to do. You don’t tend to come across too many files compressed with bzip2, but they do show up from time to time.

Because of that, we’re going to cover how to compress and decompress those files in this article. It’s gotta get covered eventually, so it might as well be now. Read on!

Compress And Decompress .bz2 Files:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

You might actually not have bzip2 installed. It’s not always installed by default. Fortunately, as far as I can tell, it shares the same name in every major distro, that is ‘bzip2‘. So, just go ahead and install it like you’d install any other software. For example, if you’re using Fedora, your command would look similar to:

See? I didn’t use Ubuntu as the default example! We’re mixing everything up today! (Use apt if you’re using a distro with apt, like Debian or Ubuntu and derivatives.)

At this point, you should probably have a .bz2 file to work on for the sake of the article. Seeing as I have no idea what you’ve already downloaded, we should probably start with you making one – just so you can see how to decompress it. 

To compress a file with bzip2, the command looks like (See the detailed warning below this command, do not use this command without reading the warning!):

That will create a file with the same filename but make a .bz2 file. However, this is a destructive act. If you use the above command, the original file will be deleted! If you wish to keep the original file, you need the -k (keep) flag. That looks like:

That command will not remove the original file, as would be the default. Obviously, the -z flag means ‘zip’.

If you want to decompress a file with bzip2, the command looks like:

This will extract the file(s) into the current directory. Of course, the -d means ‘decompress’. This is not a destructive operation. The original and extracted files will remain on your file system.

As you can see, it’s not all that difficult to compress and decompress .bz2 files. You might go years not seeing any files in that format, but you’re eventually going to bump into one and now you know  how to deal with it in the terminal – and how to respond in kind.

Closure:

And there you have it. You have yet another article. We’re getting close to 300 articles at this point, so it has been a long journey. If you feel like writing an article, let me know! Anyhow, you can now compress and decompress .bz2 files easily enough, and that was the point of the article.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Some Fun With Sorting The Output Of ‘ls’

Today’s article will be relatively short and easy, as we have some fun with sorting the output of ‘ls’. It’ll be a pretty short and simple article, but that doesn’t mean it’s not useful. Read on and learn about sorting the output of ‘ls’!

The last article I wrote was:

Some Fun With Formatting The Output From ‘ls’

This article will be remarkably similar, but isn’t about formatting the output of ‘ls’, it’s about sorting the output of ‘ls’. Yes, there is a difference! This is useful for a variety of reasons, but it’s mostly useful for viewing your files categorically. There are just a handful of sorting options, but we’ll cover them all.

Like always, it’s important to know that you should not to parse the output of ‘ls’. Parsing the output of ‘ls’ if full of risks, so you shouldn’t do it! The link explains it better than I can, and it tells you what to do instead of parsing the output of ‘ls’.

Obviously, and again, we’ll be using the ‘ls’ command. The ‘ls’ command defines itself fairly accurately as:

ls – list directory contents

So, just like the last article, there’s no real reason to make the intro longer than it needs to be. Let’s just jump right into the article.

Sorting The Output Of ‘ls’:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

With your terminal now open, you can stay right there in your /home directory, or you can ‘cd‘ into a directory of your choice – preferably one with a variety of files in it.

When you’re done picking a directory, you have the following choices:

See? I even alphabetized them for you! The list of what they do should be fairly obvious, with ls --sort=version being the most unusual and only applying to versioned files.  Also, while included, there’s not a whole lot of reason to use ls --sort=none, as that’s just the default output.

I find sorting by time to be pretty handy, as well as sorting by size. I don’t have much of a reason to use the rest, but they’re there if you need them. I figured I’d include ’em all, rather than just those that I find useful.

Closure:

There you have it, another short article! It’s also another article about the ‘ls’ command, but this time we’re sorting the output of ‘ls’. I figured I’d do this article right after the other one, mostly so that I’d remember to actually cover it. 

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Some Fun With Formatting The Output From ‘ls’

Today’s article will be a nice and simple one, in which we’ll have some fun with formatting the output from ‘ls’. It’s just a quick article today, as there’s no real reason to make this all that difficult. Read on, my dear readers!

While it’s true that you shouldn’t parse the output from the ‘ls’ command, you can format it to get an output that more suits your needs. You might want to do this to more easily understand the output from ‘ls’. There are a half dozen or so formatting options and we’ll show them all to you in this article. One (or more) of them might tickle your fancy.

Obviously, we’ll be using the ‘ls’ command. The ‘ls’ command describes itself like this:

ls – list directory contents

Which is exactly what it does. It’s not a very complicated command, as far as some commands go, but there are a lot of options. Like always, I highly suggest that you read the man page (man ls) to get more information than will be contained in this article.

Anyhow, I said this will be a short article, so I will just get right into the meat of the article instead of typing a bunch of additional fluff. You’re welcome!

Formatting The Output From ‘ls’:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

With your terminal now open, you can choose to view the output of ‘ls’ with a variety of formats. They’re more or less self-explanatory, so I’m just going to show them all to you. If you’re confused by any of them, try them in your terminal, which will should make it more clear.

I even made you an alphabetized list! See? I am helpful today!

So, for ls --format=across you’ll get the output spread across your screen (as much as possible). If you use ls --format=comma, the files will be separated by a comma.

Out of all of them, I tend to use ls --format=verbose more often than I use any of the other ways of formatting the output from ‘ls’. It gives me just enough information, from file modification date and time to the file’s permissions. So, out of all of them, that’s the one I’ll use most often. 

Feel free to flip through and try them all. You’re bound to find something interesting in there. The ‘ls’ command is surprisingly useful, and it’s harmless enough for you to explore it at length.

Closure:

See? I told you that it’d be a pretty short article today. I just showed you some ways of formatting the output from ‘ls’ and that’s all I’ve done. There’s no reason to make this longer than necessary. I think my readers are smart enough to take it from here, and figure out what they like most, or find the most useful.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Check System Information With uname

In today’s article, we’re going to show you how to check system information with uname. This is a pretty handy command to have in your toolbox, and it’s really simple to use.

Once again, I’ll probably not cover every option, but only show you the commands I think you’ll find most useful. This should be both quick and easy enough for anyone to understand. Even a rank beginner should be able to follow along.

If you’ve ever asked a question on a forum, you may have been asked to show the output of the ‘uname -a‘ command. That’s a fine generic command to run, but you don’t have to output all that information. This could come in handy when you’re scripting and only need some of the information.

We’ll be using the uname command, as you might have guessed. According to the man page, the command defines itself as:

uname – print system information

That’s a pretty accurate definition and, sure enough, matches the headline and the introductory paragraph. Like I said, we’ll be collecting system information with uname. There’s not much more to it, so let’s just jump into the article.

Check System Information with uname:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

In it’s basic usage, the uname command can be run without any modifiers at all. To do so, simply type the following to get the system’s name:

The output of that will almost certainly just say ‘Linux’. Handy! 

Ah, but the uname command can do so much more. Want to know if you’re using 32 or 64 bit, the architecture? Easy enough, just use:

Would you like to use uname to check your kernel version? Try this command:

If you want to know your kernel release, that is the specific release you’re using at the moment, you need the -r flag. Try this:

Want to know the name of the network? Amazingly enough, that would require you using the -n flag. So it looks like:

Finally, as I mentioned in the intro, there’s the granddaddy of uname commands, which will output all the information you really need. Sure enough,  it’s accomplished with the -a flag:

As you can see, the flags mostly make sense for this command. Because of this, they should be easy to remember when you need to recall system information with the uname command. To see the complete manual, use the man uname command.

Closure:

Well, that’s yet another article. I hope you liked reading it as much as I enjoy typing these silly things out. It’s probably time to do a meta article soon – as I’m really itching to do so. There have been some pretty good changes. So, that’ll be a fun article to write and I may do so soon.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Some Useful Ways To Use The Touch Command In Linux

In today’s article, we’re going to learn some useful ways to use the touch command. It’s not a complete listing of options, it’s just the commands that I think you’re most likely to find useful when using said touch command. This won’t be all that difficult to process, even for a new Linux user.

It pains me to not give this a witty, clickbait title. Though, it does remind me of a story. I think I’ll share it…

So, I was on the Interstate. At the time, my weekend was partially filled up by playing in a Top-40 band. That explains why I had pop radio on the FM radio we all used back then. I was driving along and on came this song for the first time, or at least my first time hearing it.

Yes, the Divinyls song, I Touch Myself. I laughed so hard that I had to pull off to the breakdown lane. I didn’t even notice the cop pull up until he flashed his lights and used his cruiser’s bullhorn thing to tell me that it was an emergency lane and to move on. He didn’t even check if I had an emergency, he just told me to move on. Maybe he too was listening to pop radio at the time?

So, I just want you to know how hard it was for me to *not* use a ‘witty’ article title. You’re welcome. As I often say, I’m pretty much just a giant 5 year old.

Anyhow, like I said in the beginning, this is going to be some useful ways to use the touch command in Linux. Read on!

The Touch Command:

The touch command is a terminal only thing, so you’ll need an open terminal to follow this article. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

As I said, this isn’t going to be a complete listing of touch commands, it’s just the most useful – or those I think you’ll find the most useful. If you want a complete list, just run man touch in your terminal and all shall be revealed.

So, you’re mostly going to use the touch command to create files. You can create files with touch by using the following:

Or create multiple files with:

I suspect many of you know about that, but there’s more to touch! Quite a bit more, actually. It’s a handy commend for other things, like mucking about with timestamps.

Want to create a file – but not make the file if the filename already exists (handy for scripting)? You can do that. The command would be:

Want to change a file’s modification and access time? You can do that with the -a flag, which will change both to the current date and time:

If you want to change just the modification time, use the -m flag.

Now, you can also specify a specific access and modification time, so that you’re not just setting it to the current date and time. It’s not too complicated. It looks like this:

That’s YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND. So, a fairly universal time and date format, something you may know from other commands.

You can also just tell touch to use the timestamp from another file. That’s done with:

In the above case, the command will set the timestamp of <file_1> to that of <file_2>. Pretty handy, huh? 

Again, there’s more to the touch command. To learn more, just type man touch into your terminal and you’ll see the various other options. These are just a few of the options that I’ve used, those that I think are the most useful. It’s a great way to expose newer users to some of the nifty terminal commands available in their Linux systems.

Closure:

And there you  have it. You now have an article that helps you learn how to use the touch command in Linux. It’s a handy command and it does more than just make files. We’ve actually used the touch command in exercises before, so it’s nice to see what other options are available. Also, as tempting as it was, I didn’t use any puns or innuendo in the article. You’re welcome!

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.