Let’s Play Around With The Linux Shell.

Today’s article is a bit of a mystery, as I’m writing it and not sure how it’s going to end up – but it will be about the Linux shell. I’ll try to make it approachable, even for beginners. Let’s see where the article takes us!

I think I’d caution most beginners to stick with what came with their distro (most likely Bash), rather than straying into the world of different shells. Wait until you have a few more miles in your Linux shoes before running to try new shells. It’ll make support easier if you don’t have to compound things by using an alternative shell. Once you’re up to speed, there are some nifty choices.

This seemed like the perfect question to pose ChatGPT. I’ve found a way to make AI useful – or so it seems to me. I asked the AI to explain the Linux shell in two paragraphs. This is what they had to say:

A Linux shell is a command-line interface (CLI) program that allows users to interact with the Linux operating system by entering commands. It acts as an intermediary between the user and the kernel, which is the core of the operating system. The shell provides a text-based environment where users can execute various commands to perform tasks such as navigating the file system, running programs, managing processes, and configuring system settings.

The shell interprets the commands entered by the user and translates them into instructions that the kernel can understand and execute. It also provides features like command completion, history, and scripting capabilities, allowing users to automate tasks and create powerful scripts. There are different types of shells available in Linux, such as Bash (Bourne Again SHell), which is the default and most widely used shell in Linux distributions. Other popular shells include Zsh (Z Shell), Ksh (Korn Shell), and Csh (C Shell), each offering its own set of features and functionalities. Overall, the Linux shell is a fundamental component of the operating system, providing users with a flexible and efficient way to interact with the system.

That looks like a pretty good description to me. If you have any questions, you can certainly leave a comment. You know where to find me so that you can ask questions most anywhere.

Hmm… As I said, I’m not sure where this article is headed. We’ll have to see…

Some Stuff About The Linux Shell:

Pretty much every single one of the new folks reading this will have something in common with those who have used Linux for years. You’re almost certainly using Bash as your shell. Bash stands for Bourne Again Shell. Bash is the Linux equivalent of Bourne Shell that came with Unix back in ye olden days.

If you want, you can open a terminal at this point. Odds are that you have another shell or two available. You can list your shells with the following command:

If you don’t already know what shell you’re using, you can find out quickly enough. Just run this command to find out which shell you’re using:

Let’s pretend you’re using Ubuntu and want to install a new shell. Let’s pretend you are interested in ZSH. That is ‘Z Shell’ and is an alternative that you might consider. The first step would be to install ZSH and you’d do so like this:

Follow the prompts and when you next run cat /etc/shells again, you’ll see that ZSH is an option. Pay attention to the path. It will look like /usr/bin/zsh and you can change to that shell quickly enough. Just run the following command:

Or, for a better example:

You’ll then want to reboot your system. That’s easily done with:

That should do the trick for pretty much everyone, though you’ll need to use your package manager if you’re not using apt with Debian, Ubuntu, Mate, or similar. It’s easy enough to switch to a new Linux shell – but you should probably have a good reason for doing so.

By the way, feel free to leave a comment if you use a different shell, preferably explaining why you’ve chosen to do so. I’ve played with different shells and that was entirely my reason for doing so, I just wanted to play around with them. I stick with Bash pretty much exclusively, or whatever’s installed by default.

Again, I’d caution you newer users to skip this article and just use this pile of words to learn about shells in the first place. If you’ve been using Linux for a while and want to learn something new (or have a specific reason to do so) then you can change your shell as much as you’d like. It’s your computer, you can do anything you darned well want with it!

Closure:

So, I wasn’t sure what this article was going to look like. I just figured I’d do an article about the Linux shell. We all know at least one beginner is going to start mucking about with alternative shells, at least this way we can tell them that we suggested they wait to do so.

Then again, how often did we wait to do so? How often did we go mucking around with things best left untouched until we learned better? At the end of the day, Linux is an OS that suits those who like to tinker, but she can be a harsh mistress when you’re still learning. And, again, how many of us learned by breaking things? I reckon many of us did and that’s how we got here.

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: Change DNS Servers

Today’s article shouldn’t be all that difficult for even our newest users but is limited to those who want to change DNS servers to something other than the default. This is easy enough to do, but obscure enough to warrant an article of its own. 

First, let’s have some fun. I’m going to ask ChatGPT to tell you about DNS in just two paragraphs. So, let’s see what the AI has to say:

First, what is DNS?

DNS, or the Domain Name System, is a fundamental protocol used in computer networks to translate human-readable domain names into machine-readable IP addresses. It serves as a decentralized directory system that enables users to access websites, send emails, and perform various network activities using familiar domain names instead of numerical IP addresses. When a user enters a domain name in their web browser, the DNS resolver (typically provided by the Internet Service Provider or ISP) initiates a series of queries to locate the corresponding IP address. The resolver communicates with DNS servers, starting from the root servers, then the top-level domain servers, and finally the authoritative name servers associated with the requested domain. Through this hierarchical process, DNS ensures efficient and accurate resolution of domain names, facilitating seamless internet connectivity.

DNS operates through a distributed database system known as the DNS namespace. This namespace is organized hierarchically, with the root domain at the top, followed by top-level domains (TLDs) like .com, .org, or country-specific domains such as .us or .uk. Beneath the TLDs, there are second-level domains, and further subdivisions like subdomains. Each domain has authoritative name servers that store the IP addresses associated with the domain names they manage. DNS resolution occurs through recursive queries, where the resolver traverses the DNS hierarchy to find the authoritative name servers responsible for the domain. Once the IP address is obtained, the resolver caches it for future use, reducing the need for repetitive queries. DNS plays a crucial role in the functioning of the internet by providing a scalable and efficient method for translating domain names to IP addresses, enabling seamless communication and accessibility across the network.

Wow! That’s pretty accurate. I’d have just resorted to describing DNS as the telephone book of the internet. You look up the name you want to reach and DNS tells you the number. In this case, the number is the IP address.

All in all, I’d say ChatGPT did a pretty fine job.

Change DNS Servers:

There are a variety of reasons why someone would want to change DNS servers to something else. They may get updated more quickly, weed out junk domains, or even remove ads and things like that. Maybe you want to weed out inappropriate material because you have children. Perhaps you have some custom configurations needed to traverse your complex local network. There are all sorts of reasons why you might want to change DNS servers.

See, as alluded to above, it’s perfectly possible to run your own DNS server (see Pi-hole for one such example). You can also use DNS servers provided by various third parties. For example, CloudFlare and Google offer their own DNS servers that are free for you to use. There are other choices, but this isn’t an encyclopedia writ large, so I’m going to just include those two. You can use your favorite search engine to find more.

So, let’s say you don’t like using a DNS server provided by your ISP. Perhaps you do this because of privacy issues, though you can look into DNS over HTTPS if you’d like. Perhaps you just don’t find them updated quickly enough or you’ve found they contain errors. (They do sometimes have issues and have even been known to be exploited in the past.)

NOTE: We’ll be using ‘nano‘ for this exercise. We’ll also default to Google’s public DNS servers, but you can substitute with whatever you find available.

Well, the first step you’re going to take is opening your terminal. You can do that by just pressing CTRL + ALT + T. In most distros, that will open the default terminal emulator. If your distro doesn’t do so, start mucking about with the keybindings until it does!

The file we’ll be editing doesn’t actually exist on most distros. That’s not a problem, because we’ll be making that file with nano. With your terminal open, enter the following command:

That should be a perfectly blank file and you’ll want to enter the following (again, using Google’s public DNS servers) to change DNS servers:

Then, you’ll save the file with Nano. That’s pretty easy. To save this new resolv.conf file with nano, you just press CTRL + X, then Y, and then ENTER.

Next, you’ll need to reboot. I know this will pain some of you, but I’ve yet to have a sure way to effect these changes other than rebooting. So, you’ve gotta do that. Try this command:

Now that you’ve managed to change DNS servers, you should be able to browse around much as you normally would. Remember, the people in charge of the DNS servers are the ones that decide where you go when you enter an address into the address bar and smash that enter button.

Be sure to use a company you trust to provide those services and be sure to verify your internet is still working properly. If it’s not working, you can remove the file and reboot or you can edit it again and try rebooting again. It shouldn’t be a problem in reality, this isn’t anything all that complicated.

Closure:

So, there you have it. It’s yet another article. This time around we discussed how to change DNS servers – along with some reasons as to why you might want to. If you have a spare bit of hardware kicking about, you can make your own DNS server and point to that with the internal addresses you’d be using. It’s nothing too painful and I think even beginning Linux users can follow along easily enough.

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.

Let’s Count The Number Of Files In A Directory

Today’s article probably isn’t all that useful unless, of course, you want to count the number of files in a directory. This can be useful if you want to quickly see if all the files were copied over or the like. Maybe you’ve made a backup and want to ensure the number of files matches. Who knows? It’s your terminal, you do what you want!

This article comes from my notes. These notes were right next to the notes used for the last article, where we learned to count letters, words, and lines in a file. I did get some feedback about why some folks want to know that information, which is always good feedback as far as I’m concerned. It’s great to learn the ways you put these commands to work.

Seeing as I’m lazy and just using the next notes in line, we’ll be using the ‘wc’ command again. If you didn’t read yesterday’s article, or got here by way of a search engine result, then the wc command describes itself like this:

wc – print newline, word, and byte counts for each file

You can expect the wc command to be included in every distro. It is a fundamental application and small enough to be a default application. Even the tiniest desktop distros will likely have this application and you won’t need to install anything. You will need an open terminal.

Count The Number Of Files In A Directory:

As I said in the intro, you’re going to need to use the terminal. Regular readers will notice a trend. We use the terminal a great deal. Just press CTRL + ALT + T and you should be good to go. (Some distros don’t do that as a standard. I’m looking at you, Elementary OS.)

With your terminal now open, navigate to your favorite directory with:

For example:

Then, when you’re there, try the following command:

You can also specify the path, just like you would with the regular ls command. That’d be something like:

If you want to count all the files, including the hidden files, the command would be quite similar:

In case any of this is unclear, I’ve made an image showing how I can count the number of files in a directory with a few similar commands. It looks like this:

using the ls and wc commands together to count the number of files in a directory
See? If you want to count the number of files in a directory, you can do that!

As always, be sure to check the man page for both of these commands:

And:

So, have fun counting the number of files in a directory – while learning a bit about ls, wc, and the almighty pipe (which I’ve not yet written about in any great detail).

Closure:

Of course, I hope you have fun with this one. I’m not sure how many creative ways you can use this set of commands, but it’s nice to use the pipe in an article, even if it’s just one where we count the number of files in a directory. We did use it in a fun article about cowsay and fortune. It has also been used in a few other articles, but we should have an article all about 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 site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Count Letters, Words, and Lines

Today’s article isn’t going to be all that interesting unless you happen to want to know how to count letters, words, and lines in a file. If you’re worried about publication length, a student, or perhaps a journalist, this might be the article for you.

For everyone else? Well, you can read this as a curiosity. It’s one of the neat things you can do with your Linux terminal, but probably not the most interesting of things. Still, you can probably find a way to have fun counting letters (characters, really), words, and lines in the Linux terminal. Who doesn’t want to have fun in the terminal?!?

The tool we’ll be using is ‘wc’ and it will almost certainly be installed by default. The wc application will be installed by default on some of the smallest Linux distros. It’s a tool that does this:

wc – print newline, word, and byte counts for each file

That happily sums up why we’ll be using wc in this article’s exercise. It is the most appropriate tool for the job, installed by default, and remarkably easy to use. If you want to count a file’s letters, words, and lines, this is the tool for you. You can learn a lot about this very tool by checking the man page. To do that, just type:

If that doesn’t spit out some information, you don’t have wc installed and should install it. Assuming it does, and it should let’s get into the meat of the article…

Count Letters Words And Lines:

Oh yes… I mentioned the terminal in the intro. That means you’ll need an open terminal for this. It isn’t easy to word this differently in every article, but you can just press CTRL + ALT + T and your default terminal should open.

With your terminal now open,  you can first count the letters (characters) in a file. That’s nice and easy. It’s just this command:

For example, let’s use a file most of you will have:

See? Nice and simple…

Now, if you want to count the words in a file, that’s just this command:

Finally, if you want to count the number of lines in a file, you can do just that. The command is fairly obvious and looks like this:

Now, of course, there are other options with the wc command, but I’ve covered the few that you’re most likely to use. The intro had a command that will show you the man page and you should use that if you have any questions about what more the command can do.

Closure:

Yeah, this is a nice and simple article. It’s only useful for those folks who want to count letters, words, and lines. There’s a subset of users who will want to know this. For instance, I ran this on a computer I don’t use that often and discovered that I’d never set up an infinite bash history file on this computer.

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.

Let’s Password Protect A File

Today’s article is a fun one, where we’ll learn how to password protect a file using something called GPG. It’s not complicated. You can learn how to password protect a file in just a few minutes. You can then send these files out and other people can decrypt them – assuming you’ve shared the password with them.

We all have secrets. They’re not all digital, but they could be. We may also want to be able to share files that have private information in them, meaning you only want people with the password to open it. Though, I suppose, brute force is always an option – but you can at least make it difficult by using a complex password, preferably one that you didn’t generate yourself.

So, what is GPG? GPG stands for “GNU Privacy Guard”. It’s fairly standard and used quite a bit. There are other applications, like PGP, but I think all of you folks that use a ‘full’ distro will have GPG installed by default. It’s one of those tools that you might not use all that often, but it seems to be included by default in a lot of places. I suspect that’s because other things rely on GPG, but I’m way too lazy inept to look that up.

By the way, the GPG man page describes it as:

gpg – OpenPGP encryption and signing tool

That GPG is what we’re going to be using for this exercise. Trust me, it’s easier than you might think. 

Password Protect A File:

Do I have to mention it? Of course I do! It’s time for your favorite thing, an open terminal ready for your commands. You can open your default terminal by pressing CTRL + ALT + T.

With your terminal now open, the command to password protect a file would be:

The -c flag stands for encryption. It should then ask you for a password, that you’ll need to enter twice, and then it will make an encrypted copy of the file with a .gpg extension. The original file will still exist, so this isn’t encrypting that original file. It’s making an encrypted copy and you’ll want to safely delete the original file if that’s your intention.

Now, to open the new <file_name>.gpg file, you’ll need to use the following command:

Now, when I went to open that with the same computer and the same session it didn’t ask for a password. I shipped it to another computer and it did just that. I do not know why.

When you successfully open the password protected file, it will ask you if you want to overwrite the original. This shouldn’t happen when you ship it to someone else unless they happen to already have a file with that specific name. It also will let you say don’t want to overwrite the file and let you pick a new file name for the unencrypted content.

Closure:

You can actually do this with a folder if you’d prefer. It’s just specifying a folder instead of a file. The process is exactly the same. So, like I said in the start, it’s a really easy task to password protect a file. The terminal is useful for all sorts of stuff.

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.