How To: String Commands Together In The Terminal

Today’s article is about how you can string commands together in the terminal. You can do so in a few different ways, for a few different reasons. This article will explain some of those to you, hopefully making your life easier.

There are a number of reasons why you’d want to string commands together. I find it easier to just run certain commands together. I also find it easier for some aliases. (Speaking of which, I really need to do an article about aliases!)

For example, you might want to run change to the Foo directory and then list the files inside it. Well, one way to write that command would be cd Foo && ls -la. In that case, you’d change the directory to Foo and then you’d list all the files within that directory. As I said, there are a number of ways to do this and a number of reasons why.

This article won’t be all that long – or even all that difficult. But, this is a pretty basic skill you’d want to have if you’re working in the terminal. It’s one of those tools you’ll (maybe) find yourself using more often once you’re used to it. I, for one, use it with some frequency. You can string commands together and then go make coffee!

String Commands Together:

Obviously, you’re going to need an open terminal. 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’ll want one of the following operators:

; run the next command no matter what.
&& run the next command only if the first one succeeds.
|| run the next command only if the first one failed to run.

The ; operator can be used something like this:

Them the && operator can be used something like this:

Finally, the || operator can be used something like this:

You could string them along something like:

See? It’s not all that complicated. You can also swap the ; operator for a single ampersand. It’ll do the same thing, run the following command regardless of the results of the first. So, cd Downloads ; touch foo and cd Downloads & touch foo are functionally the same.

Closure:

Yup, another article – said and done. This one is, as promised, not all that difficult or even all that long. Still, I hope you’ve learned something and know now how to string commands together in the terminal. It’s a pretty useful skill to have. Feel free to leave a comment explaining how you already use these operators to string commands together.

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.

How To: Mount An .iso In Linux

Today’s article will teach you how to mount an .iso in Linux, a task undertaken seldom but worth knowing. This isn’t something I use often but it’s something you may want. It promises to be a quick and easy article, so read on!

I’m pretty sure the ‘unmount’ is incorrect English and that it’d be ‘dismount’ if you had mounted something like a horse or gym equipment. But, when I look around the web I see ‘unmount’ used with greater frequency. So, I’ll be saying ‘unmount’, even though that seems wrong.

Why would you want to mount an .iso? Well, there’s software that’s meant to be run from CD/DVD. You could burn your .iso to optical media or you can just mount the .iso and use it from there. Rather than wasting time burning the disk, you might just as well mount it.

You might want to verify that the image works before you burn a copy or upload it to share it. You might want to make edits to an .iso image and mounting the .iso will help with that, as you’d obviously unmount the image between changes.

So, you have a few reasons as to why you might want to mount an .iso. This article will explain how. It might not be a skill you need to day, but it’s one you may want eventually. We might as well get it written down now.

Mount An .iso In Linux:

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.

The first command you need to run is to set up the mount’s directory:

With that done, you can navigate to the directory where your .iso is stored or just use the full path. Your command should look a little something like this:

When you’ve done that, the .iso should be mounted and remain mounted until you unmount it or reboot. This is not a permanent mount, so you’ll not have any permanent changes to your system because of this. For permanency, you’d need fstab.

By the way, just cd /mnt/iso to navigate to your newly mounted iso and that should work just fine. If you want to unmount the .iso on your own, you’d just use this command:

You can verify that you mounted and unmounted it with the lsblk. The output from that command should first show the .iso mounted and then show it when it’s unmounted.

Closure:

That’s about it. There’s not much more to say about how you mount an .iso in Linux. It’s a pretty simple activity and one easy to master. In my case, I just do it so infrequently that I never actually remember all the commands. So, it ended up in my notes – which means it turned into an 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.

‘sudo apt remove’ vs ‘sudo apt purge’

Today’s article is going to cover ‘sudo apt remove’ vs ‘sudo apt purge’ and will be in a different format than some articles. It’s a brief article meant to answer a specific question. It’s nothing more, and nothing less.

The question would be, “What’s the difference between sudo apt remove and sudo apt purge?” It’s a perfectly fine question, thanks. This article will answer it.

It does open up an idea. If you have any questions, you can always just “Ask KGIII” a question. For example, the question prompting this article might be, “What’s the difference between sudo apt autoremove vs sudo apt purge?” It’s a legitimate question, and a good example, of the kinds of questions I’d welcome.

So, for fun, we can pretend someone asked this question! 

If you don’t ask me any questions, I may just have to pretend you did and write my questions and answers all by myself! However, this is the kind of question I’d be looking for. Leave a comment with a question, thanks!

If you lie about your email address to ask a question, that’s fine – just don’t also opt to subscribe to responses. It results in some ‘spammy’ domain behavior and I’d like to avoid that. Use  @example.com, if you want. It should work but there is no example.com of note so bouncing emails won’t be a problem. On the other hand, others can attest to the fact that I’ve sent zero spam messages.

‘sudo apt remove’ vs ‘sudo apt purge’:

In this case, both of these commands are used to remove software from your system. These commands are valid in distros like Debian or Ubuntu, systems that use APT as the package management system. If you want to remove software, the commands would look like one of the following:

With both of these commands, you’ll remove the software. It will not only remove the software, it’ll mark the software as uninstalled in your database of installed applications. This means you can opt to install the software again.

But, there is a difference. When you use, you just remove the software itself. When you use sudo apt purge <package_name>, it not only removes the package, it also removes the configuration files.

In theory, you can do ‘apt remove’ and then re-install the application at a later date while keeping the pre-existing, pre-removal configuration. The regular ‘apt remove’ doesn’t touch configuration files, it only removes those things that were listed as files in the packages manifest and created during the installation process.

So, when you run ‘apt remove’ you’re removing it from your system. When you run ‘apt purge’ you’re making sure (ideally) no traces of it remain. I say “ideally” because it’s not as cut and dry as one might think. Package management isn’t all that smart and things like MySQL will leave behind a user, and other package installs will do similar. 

As a bonus, if you’ve seriously messed up an application’s configuration then you can purge it and have a clean slate, with (ideally) no previous configuration files left over. Of course, if you just use ‘apt remove’ then your configuration files may still exist. If you want to maybe install the application again, and you were happy with the way it was configured, you should use ‘apt remove’. Otherwise, use ‘apt purge’.

If you, like me, are curious as to how the purge command works (it’s not all that intelligent) then click here to learn how the purge command works. The answer is well-written and, more importantly, is correct (inasmuch as I understand). It’s well worth reading, for a better understanding. As I mentioned elsewhere, the package manager isn’t all that intelligent – but it is what it is and it’s much easier than doing it all yourself!

Closure:

And there you have it. You have another article! This one is kinda like a pretend person asked a question and I answered the question in the form of an article. I’d like to do that sort of thing every couple of weeks, but it’d require someone to ask me questions.

I don’t mind if they’re questions I have to research. I think it’d be an interesting new aspect to the site. We can call it ‘Reader Questions’ and maybe give out a prize of some type if your question is chosen. I mean, you shouldn’t need a prize but it might motivate a few of you. Leave a ‘Reader Question’ as a comment on this post and we’ll see how it goes! If it looks like it might work, I’ll add it as a new category.

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: Determine Your Desktop Environment

Today’s article will help you determine your desktop environment. Often abbreviated as “DE”, your desktop can be any number of choices – including none at all. This should be a relatively short and easy article. If you don’t know, the desktop environment is a bunch of software that provides the GUI system you use to navigate, load files, and manage your computer.

Once in a while, an article should get back to the basics. This is one of those articles. When someone poses a question and you need to know their desktop environment, you can just tell them that you need that information and link to an article like this one.

As such, it’s not exhaustive nor is it expected to be all that deep. There are a number of ways to get your desktop information. For a more universal approach, these ways will all be through the terminal. In most other situations, you can use the GUI and figure it out. For example, you might use HardInfo and get the data that way. Not everyone will have that installed, so we can just do it though the terminal.

Determine Your Desktop Environment:

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.

Now that you have your terminal open, you can try either ‘neofetch‘ or ‘screenfetch‘. Both of them will happily spit out the information you need. The screenfetch may be better here, as it also gives the version of your desktop environment – from what I can tell. Both are easy to install and may already be installed.

Here’s an example of the relevant output from running screenfetch in the terminal:

screenfetch displaying desktop environment information
See? It’s right there! Easy enough!

You can also do the same thing with running neofetch in your terminal. Once again, it looks something like this:

neofetch showing desktop environment
Once again, it’s nice and easy! Tada!

Now, there’s some chance you just want to determine your desktop environment and don’t need or want any additional information. You can do that. It’s not hard, it’s not hard at all. In fact, both are environment variables that you can easily get to echo as stdout.

You can also use:

Both of those will tell you the desktop environment that you’re using. See:

using echo to view the desktop environment
See? You can use either one effectively and efficiently.

As suggested by @wizardfromoz, of Linux.org fame, I completely forgot to include my beloved inxi. The inxi system information tool is increasingly installed by default, but the link will show you how to install it. It’s a great tool, providing a ton of information, that’s used frequently for support questions.

To use inxi to determine your desktop environment, you can just run:

That’s an uppercase S and it’ll look something like this:

inxi showing the desktop environment
See? It’s even included in the inxi output! inxi does it all!

And there you have it, a few different ways to determine your desktop environment from the terminal. You should probably just know this information, but newer users may not know and may need help in finding this information. 

Closure:

So, there’s another one… Yet another article, said and done. This one is pretty easy and aimed at rank beginners, but it’s not without use. It may even save some time as people might actually search before asking questions! Well, they could… 

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.

How To: Find The File Type In The Linux Terminal

There are many file types in Linux, and we’ll learn to find the file type in the Linux terminal in this article. It’s not terribly difficult and is a good basic article, with a command not that widely discussed. It’s a good time to learn.

Let’s start at the beginning… As many of my readers are new, there’s some stuff you ought to know.

First things first, everything in Linux is a file. I realize that that may confuse some folks new to Unix/Linux, but it’s true. If you don’t know how this works, click this link. That should explain it well enough.

Linux also uses the whole Magic Bytes thing. You can click here and learn about Magic Bytes. To explain it a bit differently than Wikipedia – it’s why you can make a text file without an extension and still have it open with a text editor when you click on it. The system sets Magic Bytes that mark the file as being of a certain type.

Well, there’s a tool that you can use in the terminal to find a file type. Amazingly enough, that tool is called ‘file’. The man page for which is clear:

file — determine file type

Yup, that’s the tool and that’s what it does. It’s pretty accurate and works with a number of file types. It checks things like whether the file is an empty file, what response it sends when queried, if it has Magic Bytes, and the language used in the file. It’s pretty comprehensive.

Find The File Type:

Obviously, this requires an open terminal. After all, we’re finding the file type in the terminal. That kinda needs an open terminal! Just press CTRL + ALT + T and your default terminal should open. Tada!

Now, with your terminal open, and enter the following command. I’m pretty sure this will work on any desktop Linux!

It’ll happily spit out that you have a data file on your hands.

But, here, let’s see if we can fool it. Grab an image and call it image.png (or whatever extension) and run file <filename.extension> to see the output. Now, rename the file to just plain ‘image’ and run the command again (sans extension). What does it tell you? It should look something like this:

file command in action
See? It still knows that it’s an image file. Images use the Magic Bytes.

Go ahead and try to fool it. Rename it image.txt and try it again. Pretty neat, huh?

I don’t need to patronize, by now you get the idea. You see what it can do. Well, there’s a bit more. You can create a text file with a list of files in it (with their path if in different directory) and the run file on that file you created – just make sure it’s a plain text file that you created. It’ll happily output the types of all the files listed inside.

You can also use the whole wildcard thing. You can get all the file types in a directory with this command:

If you want all the files starting with the letter I, you’d do this:

If you want, you can even use it on compressed files. For that, there’s the -z flag. It looks something like this:

It’ll spit out some information, perhaps letting you know the minimum version of your archive manager needed to open it. It doesn’t give you information about the compressed files, however. To do that, you’d have to extract the files first.

Closure:

And there you have it. You have yet another article! This one shows you how to find the file type in the terminal, and is a handy tool indeed. I normally take the entirety of January off, but I can’t do that this year. This year, I must ensure there are articles. Maybe next year! The good news is I can author these things with a wee bit o’ the wine in me. 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 own 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.