Find Out What A File Is

Today we’ll have a simple article, one that shouldn’t take too long, as we learn one way to find out what a file is. It’s a handy command, but it won’t take all that long to explain. So, we’ve got that going for us!

The command we’re going to use is one that you almost certainly have installed by default. That command is the ‘file’ command. The man page describes file as:

file — determine file type

Linux pretty much treats everything like a file, pretty much. Files also contain a ‘magic number‘ – which is why you can rename an mp3 file as a gif file and it’ll still open in your media player. Basically, the magic number is the opening two bytes of a file that tell your system what kind of file you should be expecting. 

If you change the file extension it won’t fool the ‘file’ command. You can rename it with any extension you want and ‘file’ will know what the file is. Of course, it might be a text file, a compressed file, a Debian installer, etc… There are all sorts of file types out there. There are hundreds of file types just for image files.

So, yeah… We’ll be using the file command in this exercise. Let’s get to it!

Find Out What A File Is:

Like oh so many other articles, this one requires an open terminal. We do a great deal in the terminal. You can press CTRL + ALT + T and your default terminal should open.

With your terminal open, you’re probably in your home directory. So, the vast majority of you should be able to run the following command:

That file contains a bunch of the settings you see affected in the terminal. As you can see from the output, it’s an ASCII file, meaning you’d edit it with an ASCII (plain text) editor.

If you want, you can navigate to your Downloads directory and use ls to list the files. From there, you can run the file command on files you’ve downloaded. For example, I could run:

The output from that command would look like this:

The file command knows what the file is. It’s pretty accurate. It doesn’t matter if I change the .deb to .gif. 

See? Renaming the file didn’t fool the system. However, it might fool some applications. For example, if you click on that “.gif” file, your system might try to open it as an image and throw some sort of error. The file command can be pretty handy in those situations, where you’re not sure what the file type is and how you should approach it.

Closure:

Well, if you ever wanted to find out what a file is, you now know how. Over your computing journey, you may very well find you need to rely on the file command to know what the file type is. It’s a pretty handy command for when you need it. Of course, you could go so far as to edit the magic numbers to fool the command, but you’d probably know if you did that.

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 site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Install .DEB Files In Ubuntu

Today’s article is only useful for a subset of my readers, that is those who need to know how to install .deb files in Ubuntu. That’s a bit cheeky of a headline, but there’s a character limit to adhere to. So, if you want to install .deb files in Ubuntu, this article is for you…

What are .deb files?

The .deb file extension means that it is a package meant to be installed in Debian. So, this article will be valid for all Debian users – even those downstream, like Ubuntu or Linux Mint.

Quite a few Linux distros use .deb files, not just Ubuntu. I happen to be an Ubuntu member and many of my readers use distros based on Ubuntu (which is, of course, based on Debian). To keep things short, we’re not going to type all that out over and over again.

Many new users start with Ubuntu or Mint, and Debian itself of course. You might be a new user and have reached the point where you’re comfortable installing software from the graphical installer built into your operating system of choice.

Well, this is Linux… There are all sorts of ways to do things! Assuming you’re safe, or unsafe if you want – it’s your choice, you can find software that’s not available in the graphical installer, or newer versions than what you’ll find in the graphical installer. You’ll often find this software available in .deb format and this article will show you a few ways to install those .deb files.

How To: Install .DEB files in Ubuntu:

The first way we’re going to cover will be in your terminal. You’ll likely need an open terminal for the rest of the methods, so you might as well open your terminal now. You can just smash the CTRL + ALT + T and your default terminal application should pop open.

The first method is pretty easy. You’re simply using ‘apt’ in the terminal, much like you’d do if you wanted to update from the terminal. The command would look something like this:

You’ll usually have downloaded the file to your Downloads directory, so you can either navigate to Downloads using the cd command or you can just include the folder in your path to the file, kind of like this:

Of course, you’ll use the actual file name and you’ll be asked for your password (unless you’ve changed that). Enter your password and let apt do its thing. Using apt is great because it will do its best to resolve any dependency issues you might have.

Now onto some GUI ways to install .deb files in Ubuntu!

Install .DEB Files With GDebi:

You followed the directions above and have an open terminal, right? Good, because GDebi doesn’t always come installed by default. I’ve previously written an article about GDebi, but it’s actually on the old site. I won’t bother linking it.

GDebi is a great GUI, that is a graphical, way to install .deb files. In fact, on the man page, it is described as:

gdebi – Simple tool to install deb files

To install .deb files with GDebi you first need to install it. You can do that right there in the terminal. To install GDebi, just run this command:

Once you have GDebi installed, you just use it from the right-click menu. Use your file manager to navigate to the download’s directory. Then you just right-click on the .deb file and choose to install it. The first time around, you might need to do some sort of ‘open with’ exercise, but then it should appear as something like “Open with GDebi package installer” or you will pick it from a list.

I’m positive you can figure it out from there. The great thing about using this GUI method to install software in Ubuntu is that it too will attempt to deal with any dependency issues automatically.

Install .DEB Files With QApt:

Do you still have that terminal open? Good! We have one final graphical method to install .deb files in Ubuntu. This one is a fairly new application and it’s a Qt application. However, it installs with very few dependencies and takes up very little space. Functionally, it’s very similar to GDebi.

So then, let’s start with getting QApt properly installed. The name is quite a bit longer, but it’s still easy to install QApt. To install the software, try this:

It’s a nice and light way to graphically install .deb files. For the life of me, I can’t figure out the correct man page incantation to make it work. No amount of trying the various words results in a man page opening. I do not know why, but I do know that it works. If you search to install QApt, it describes itself as:

qapt-deb-installer – tool for installing deb files

That’s plenty accurate. That’s what it is and that’s what it does. While I can’t find a man page for QApt, that’s an adequate description.

This QApt is a bit different. Like with GDebi, you’ll use your file manager to navigate to the directory that contains your .deb file (usually the Downloads directory) and right-click on the .deb file you wish to install. You’ll then pick “Open With” and click on the “QApt Package Installer”. With QApt now open, you’ll just click the obvious install button and wait patiently for it to do its thing.

Closure:

So, there you have it… You have another article and this one has you learning how to install .deb files in Ubuntu. There are a few ways and you can pick the one that works best for you. Much of the time, I already have a terminal open and already navigated to the ~/Downloads directory. Because of this, I’ll often just do the installation right there in the terminal, using the apt command. But, it’s up to you. You have choices!

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 site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Not Save A Command To Bash History

Today’s article is another short-form article, where the subject is how to not save a command to bash history. It’s trivially easy and something everyone can learn. So, read on and learn how to not save a command to Bash history.

The vast majority of my readers are going to default to using Bash. 

bash – GNU Bourne-Again SHell

You’ll access Bash through your terminal and, again as the default, will save x-amount of past commands to a file known as ~/.bash_history. Anything you enter as a command (though not passwords entered at the password prompt, as that’d just be silly) will be saved to that file.

If you’re like me, you use the terminal a great deal. Again, if you’re like me, you value the Bash history aspect but you don’t want it full of trivial or experimental nonsense. You can prevent a terminal input from being saved in your ~/.bash_history – and it’s trivial to do so.

Do Not Save A Command To Bash History:

Seeing as I’ve been doing short-form articles for the past couple, this one seemed like a lovely tip to share with my readers, as I’m sure some will not know this. 

Of course, you’ll need an open terminal for this. Press CTRL + ALT + T and your default terminal should open.

With your terminal now open, we’ll use the ‘ls’ command to list the contents of your present working directory. Ready?

Now, that’ll be saved to your Bash history file. What if you don’t want it saved to that file? Just add a space in front of it, like so:

I don’t know how well that will show up, but trust me when I say there’s a space there. By adding that space, I’ve effectively told the terminal to not save that entry into the history file.

See? Pretty darned simple!

Closure:

So, yeah… I’ve been doing a few short articles and this seemed like the perfect article to do in that format. It’s something not everyone knows, isn’t made immediately obvious, and will likely be of importance to someone. If you’ve ever wanted to not save a command to bash history, that’d be how you do it.

I could have added a few more bash tricks and turned this into a longer article, but I’m having fun with this shorter stuff right now. If you prefer the longer articles, don’t worry. They’ll be back soon enough. These short articles are fun and easy, and they have the added benefit of keeping me interested in writing these silly things.

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 site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment. 

How To: List Open Files

Today’s article might seem unimportant and that’s okay because we’re just going to examine one way to list often files. So, in a way, it’s probably not all that important. If you are someone who wants to list open files, this would be the article for you!

For the most part, most of my readers aren’t going to want to know how to list open files because they just have no good reason to do so. It won’t be a very long article or anything. I did some long-format articles and they didn’t get much feedback. I’ll do more, but I don’t see them as needing to be all that immediate – or consistent. The shorter articles just seem to be what folks are looking for. I can live with that. (If you do like the longer articles, it’s not too late to mention that.)

Today’s tool will be one you may have never heard of. We’ll be using the right tool for the job, however. That tool will be the ‘lsof’ command. The ‘lsof’ command should be installed by default in any major distro and checking the man page will reveal that it describes itself like so:

lsof – list open files

Read that line and then look at the headline. See? I told you that it was the correct tool for the job. If you want to list open files, a tool that lists open files is the tool for the job. Imagine that?!?

List Open Files:

Of course, the lsof command is run in the terminal. As such, you’ll need an open terminal for this exercise. 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 open, you can just run the following command which will show every currently open file (it’s a lot):

You’ll notice some of the output will say something about “permission denied”. So, if you’re going to list all the open files, you probably should use sudo with the command. Like so:

Type in your password at the prompt and be prepared for the deluge of file names. It takes quite a bunch of open files for an operating system to work – and Linux treats everything like it’s a file.

So, what if you just want the output to tell you all the files opened by a specific user? The lsof command will help you out with that. Try this command:

For example:

That command will show you all the files opened by that user. It’s still a lot, but it’s an easier output to process. If you wanted to show the files opened by everyone except a specific user, you’d use this command:

That command would (assuming you removed the brackets) show you all the open files except those files opened by ‘username’. In any of these cases, if you see some permission denied errors you can just slap sudo on the front of it and be good to go.

Closure:

Well… If you’ve ever wanted to list open files you now know how to do so. I suppose it’d mostly be useful for things like auditing or troubleshooting performance issues. I have the command in my book of tricks, but I don’t recall ever needing to use it for much. I’ve played with lsof and it does list open files. So, there’s that.

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 site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Unzip All The Files In A Directory

Today’s article might seem like a strange one, but it’s all about how to unzip all the files in a directory. It’s something only a few folks will need to know and something you may not need all that often. However, those folks who need to know this, and those folks who need this often, will be grateful to learn this little tip.

I would think that this will be a short article, as I don’t see it taking up that many words. I’m not sure of the appeal, but I want to write it anyhow. So, if you want to know how to unzip all the files in a directory, this is the article for you!

For me, this is another article based on necessity. See, it’s I who frequently has to unzip a bunch of files all at once. They’re fortunately all in the same directory, making this just a pair of easy commands. Sometimes I have to unzip nested files, so I’ll include the command to do that along with the more simple command that I usually run.

Every month, I get a whole lot of documents from my accountant. For bandwidth’s sake, these get organized and compressed before they’re emailed to me. In theory, I’m supposed to go over them and verify them individually. At best, I open them all up and look at a few of them. I do a sanity check every few months. My accountant is an old lady and I’m pretty confident in her integrity. So, I’m pretty lax…

However, see, I’m supposed to check them… So, I kinda go through the motions and at least look at a few of the documents. That’s where this command comes in…

Unzip All The Files In A Directory:

For those following along, it has been a minute since you needed to open a terminal to follow one of these articles! Well, that wait is over! You know what to do. Otherwise, just press CTRL + ALT + T, and your default terminal should open.

With your terminal open, use the cd command to navigate to the directory that contains multiple .zip files. You should know how to do this, but it’s just: 

Once you have reached the directory you’ve chosen, you can just run this command to unzip all the files in a directory:

Now, sometimes there will be folders inside that directory and those folders will also contain .zip files. To unzip the files recursively you’d just want to use the following find command first, like so:

That lovely command will scour the directory you’re in for sub-directories, enter those directories, and then unzip any files it finds in those sub-directories. It’s not all that complicated, you’re just finding files with .zip in their name and then executing the unzip command on them.

As I said at the start, it’s not one of those things you’ll need often – but when you do need it, you need it. Well, your life is significantly improved by it. I suppose it’s not technically a necessity. You could unzip all the files one by one or even unzip them using a GUI. Still, it’s handy to have.

Closure:

And there you have it. Today’s article is back to a shorter format article, largely because this is what I was thinking about today. Because of that, you got an article explaining how to unzip all the files in a directory – and how to do so recursively – unzipping files nested in sub-directories. You’ll eventually need it! Maybe…

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 site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.