Count Word Frequency In A Text File

Have you ever wanted to count the word frequency in a text file? Have you ever wanted to know how many times you used a word in a document? Well, with just two simple commands (grep and wc) we’re going to learn how to do just that.

As a writer, I try to avoid using the same words over and over again. It’s not just bad form, using the same words repeatedly actually makes the document more difficult to comprehend. The brain needs variety (and key concept repetition) or else it just kinda checks out and doesn’t pay much attention.

There are other times when you may want to count the number of words used in a document, perhaps as a reference. “Your honor, the document in question contained my client’s name 245 times – and none of the uses were factual!” I’m sure you can concoct a scenario where you may want this information. You can probably come up with one that doesn’t even involve a judge!

You can also use it a little more broadly, and we’ll cover that. For now, let’s make sure we’re all working on the same page. Press CTRL + ALT + T and open up your terminal, and then enter the following commands:

There. Now that we’re on the same page (you have the text file in your downloads folder) we can all work with the same list of random numbers – instead of random words. (All we care about is that there are characters.)

Count Word Frequency:

Well, you already have the terminal open and you’ve already downloaded my random numbers file. We’ll substitute numbers for words – as words are just a string of characters. So, seeing as you’re prepared…

Trust me, it won’t make a difference that we’re using numbers. By the time I’m done explaining this, you’ll understand and apply it to words (or other characters) all on your own. It’s pretty straightforward and easy to understand.

Let’s say we wanted to count the instances of 62829. The command would look like this:

If you run that command, you’ll see that that string of characters occurs just once. That’s expected and correct.

You can also do things like finding all the instances of 1 (or any single character) in the list with this command:

You can be even more complicated and find all the times a 7 immediately follows a 2. That command would look like this:

(There are three instances of 27.)

So, what’s going on? Well, you are using grep (to search) the contents of the file. You are then piping the output to wc where the number of lines (instances) are being counted.

You can probably be pretty fancy with this, but I just wanted to give a quick overview. Mostly, I figured it’s a good excuse to dig out grep and wc – and who doesn’t like panning for nuggets in text?

Closure:

Yup… This one isn’t a very long (or complicated) article. That’s okay. I like articles of all shapes and sizes. This article will help you count word frequency, something we all may need at one point or another. Sure enough, Linux makes this a pretty simple task.

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.

Time A Command To See How Long It Takes To Run

Have you ever wanted to time a command? Well, you can! Linux includes the ability to time a command, so that you can know how long it took for a command to be processed. 

Today, we’ll be using the ‘time‘ command. Time is simply (and accurately) described in the man page as:

time – run programs and summarize system resource usage

The time command is a pretty nifty tool and the output will tell you the real time that it took, as well as the system time, to run the command you’re timing. There’s really not a whole lot more to say about the time command. It does what it says on the tin. It times stuff!

This is going to just be a quick article and should be easy to follow. There’s not a whole lot to explain and it’s pretty straightforward. If you’re looking to get your feet wet playing in the terminal, this is probably a good article to start with.

Time A Command:

Just like oh so many of these articles, you’ll need an open terminal. So, let’s crack open your default terminal by pressing CTRL + ALT + T on your keyboard.

Now, let’s take the simple command to list everything in a directory:

To find out how long it took to list all the files and folders in a directory, you could use:

The output of that command tells you how long it took to list all the items in a directory beneath the results. It should not have taken long. If you want to try something bigger, something that lasts longer, you can take a look at this command:

That should take a just a little more time to run in your terminal, but how much longer? Well, you can can actually see how long it really took by adding ‘time’ in front of it. Obviously, it’d look something like this:

The output at the end is something like this:

real 0m0.566s
user 0m0.423s
sys 0m0.143s

The ‘real‘ is how much time it really took. The ‘user‘ is how much time it took for the user. The ‘sys‘ is how much time it took for the system – the amount of time that the kernel actually devoted to running that command.

You can time all sorts of stuff. Like, here’s an example output from me updating my system with time sudo apt update (not all of us have big, fat pipes from the ISP):

When I purged Krita (from a previous article), the output from time sudo apt purge krita looks like:

Have fun with it, if you want. Find out how long those tasks actually are, so that you can get a reasonable estimate of where you’re spending your time in the terminal. You can even use it like time nano <file_name> and see how long it took you to edit a file in the terminal!

Like I said, have fun with it. You might find some of those tasks that seem to go slow really don’t take all that much time. Maybe you’ll find out that the reverse is true? One thing is pretty certain, however. If you didn’t have it before, you now have ‘time’ as a new tool in your Linux toolbox.

Closure:

Well, there’s another article. This one has taught you how to time a command in the Linux terminal. It’s a little tool, probably not all that useful, but it’s one that’s there. If you happen to use the time command on a regular basis, please leave a comment letting us know why. I’m sure there’s some real-world uses, but other than looking for bottlenecks or real-time optimizations I can’t really think of any.

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 Install Krita In Ubuntu

Krita is an image authoring application. Some people compare Krita with GIMP. While the two programs have overlaps, the two programs are not the same and really shouldn’t be compared. Where GIMP is meant for image manipulation, Krita is more aimed at people who want to create images from scratch.

GIMP and Krita probably shouldn’t even be compared with each other. In fact, to save some time, you can read an article from the good folks at GIMP Tutorials for a good description of the benefits from either as well as why the two applications, GIMP and Krita, should not be compared with each other.

If you want to create digital art, Krita may be the software you’re looking for. When you’ve got a pointing device and plan on using the software like you’re painting, then Krita is the kind of software you’re looking for. Should you plan on creating from the ground up, not modifying memes or photoshopping dicks on pictures of previous politicians, you probably want Krita.

As luck would have it, this article will teach you how to install Krita on your Ubuntu-based system. It should also work for Debian, the official Ubuntu flavors, and Ubuntu derivatives like Mint or ElementaryOS. However, I tested in exactly none of those other systems. If you it doesn’t work, don’t say I didn’t tell you.

This process will have you installing it through your package manager. If you don’t want to do so, then there are an AppImage and Snap package that you can grab by going here. The way we will be installing Krita is a bit more ‘traditional’, so to speak.

Install Krita:

This article requires an open terminal. If you don’t know how to open the terminal, you can do so with your keyboard. Press CTRL + ALT + T and your default terminal should open up like magic.

The first thing we need to do is add the PPA. That’s a Personal Package Archive that adds itself to your regular repositories. A PPA is meant for software that’s not in the default repos. It’s meant for personal use – but we’ve bastardized the use to make it a way to easily install 3rd party software. That’s not important right now. What is important is that you then use this command:

When asked, you can finish adding the repository by pressing ENTER. That should then trigger apt, making it check for new software. If it doesn’t, you can run:

After that finishes, you can go right ahead and just install Krita from the terminal. (It’d also appear in your software manager, but we’re in the terminal so we might as well just finish in the terminal.)

Krita is a pretty large and complicated bit of software, so it’s a sizable download. Once downloaded and installed, you can bring out your inner Leonardo da Vinci! It’s really as simple as that, and nothing more.

Installing Krita this way will keep Krita up to date as the repository is updates. You do have a Flatpak and an AppImage available if either of those is your preference. If not, you can go right ahead and install it the old fashioned way.

Closure:

DING! There’s another article done and done. This one just was a passing fancy, pulled more or less randomly from my notes. It’s a great way to install Krita, for those looking to do so. It’s pretty painless and it’s a solid piece of software.

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.

Let’s Install ‘gedit’ With All The Fixin’s In Ubuntu

This article is going to tell you how to install gedit along with a bunch of plugins. There are many text editors out there, but gedit is a popular choice. Many plugins exist to extend gedit, and this is an easy way to install a bunch at once.

Notes: This will only install the plugins in the default repositories. This article covers just Ubuntu, but will likely work with derivatives and even Debian.

gedit, the default editor for the Gnome desktop environment, is a part of the GNOME Core Applications and is available in almost every distro, at least every major distro. The gedit text editor doesn’t need a lot of additional dependencies, which helps make it useful on almost any desktop environment.

You can use gedit for anything – from programming, to writing markup for your website. You can use it just like you would any other plain text editor. There are many ways to extend it, to add functionality not included by default, and that is with plugins.

There are plugins to highlight syntax, to auto-complete words, to auto-close brackets, etc. You can make gedit do all sorts of things you’d not expect from a plain text editor. 

Disk space is absurdly cheap these days, so I don’t see any reason to not install as many plugins as I can, and no reason to not do it all at once. I may not use them all, but I’ll use many of them and I can just not enable those that I don’t want to use. I may have a reason to use them later on. You never know!

Well, this article will help you install gedit and all the plugins your system can find!

Install gedit With Plugins:

Like always, you need an open terminal and you can do that with your keyboard by pressing CTRL + ALT + T and enter the following:

What’s going on with that command? You can string together requests with apt, and this is installing gedit first, then a pack of common plugins, and then every other plugin that uses the ‘gedit-plugin-*’ format. It checks for all software with that naming pattern and installs them if they’re not already installed and have satisfied dependencies.

By the way, the asterisk is known as a wildcard. A wildcard basically means, “any character.” So, foo* is anything from fool to foolish, and foob* is anything from foobar to foob-gibberish or whatever. 

It should be noted that this only installs the plugins. You still can’t use them until after you enable them. To enable them, you need to open ‘gedit’ (which will almost certainly be called “Text Editor” in your menu) and click on preferences, where you can navigate to the right-most tab and enable them as needed. It looks like this:

gedit preferences
Select plugins ’til you’re satisfied!

Anyhow, if you did this properly,  you will now have a bunch of plugins enabled. Is this a bit of overkill? Perhaps, but disk space is cheap and the entire thing takes up less than 19 additional MB on my system. You might as well do it all at once. 

Closure:

And there you have it. You now have gedit installed along with a bunch of gedit plugins. It’s really not all that difficult and there’s no real huge hit on performance or resources. Heck, it doesn’t even take all that long!

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.

Change Your Hostname In Linux

This article will tell you how to change your hostname in Linux. It’ll give you a couple of options to use. Both methods are pretty easy, and both are approachable by your Linux newbie. Read on for more information!

If you don’t know what your hostname is, or why you have one, you can take a look at this article. Basically, it’s a handy computer name that you use when you’re using things like SSH or FTP. (The first of those three links would be the best page to learn more about your hostname, but it’s basically just a name for your computer.)

Your hostname is probably something you set during the installation process and seldom thought about again. Unless you’re working with your devices remotely, perhaps with the terminal, it’s not really something that you think about all that often. Well, this article is how about you can change your hostname to something else. 

Why would you want to change it?

Well, you could have duplicated it on another device it by mistake. You may have added more devices and need a new device-naming convention. You may have picked something silly and now want to make it more serious. Your device may be moved to a new network where the name isn’t allowed or already belongs to an existing device. There are any number of reasons why you might want to change your hostname. The key point here being that you can change your hostname.

Onto the article!

Change Your Hostname:

This article, like many, requires an open terminal. You can open the terminal with your keyboard – just press CTRL + ALT + T and your default terminal should open. I’ll start with the easiest of the two ways (that I know) to change your hostname.

Method #1:

The first tool we’ll use to change the hostname is the aptly named ‘hostnamectl’ and to use it, you’d use a command like this:

After that, you’ll need to reboot the system for the changes to take effect. Seeing as you’re already in the terminal, you can actually just reboot the system with this command:

This is the very easy way, and it’s the way I’m going to recommend – even if you’re an advanced user. Alas… There’s another way, albeit a bit more messy, to accomplish this.

Method #2

You can edit ‘/etc/hosts’ and ‘/etc/hostname’, changing the hostname manually. This is also handy if you don’t have hostnamectl as an option. Like above, you’ll need to have a terminal open.

Your first command will be editing the hosts file, and we’ll use ‘nano’ for this. Simply enter the following:

There, you’ll see your hostname (which may also be your username, and often is your username). Just delete that and replace it with your desired new hostname.

When you’re done editing, and seeing as we’re using nano, you can save and exit the editor. Just press CTRL + X, then Y, and then ENTER. (It’s seemingly a little complicated, but not too bad.)

Next, you need to edit the hostname file. The command is similar to the one above, just with a different filename. Enter this:

Find the line that begins with ‘127.0.0.1’ and ends with your current hostname. Erase just the hostname and change it to your desired hostname. To make it more clear, here’s a picture:

change the hostname
Just erase the existing hostname and make it your new hostname. Pretty easy, huh?

Once you’re done with that, just like before, you need to save it. Again, you just press CTRL + X, then Y, and then just hit ENTER. That should save your new hosts file and you’re pretty much done changing your username.

There’s one final step. These changes won’t take effect until after you reboot the system. To change your hostname, you will need to reboot the system after changing these files. That’s usually a painless process and you should be able to use the new hostname after the system is rebooted.

Closure:

Well, it’s another article. If I’m paying enough attention (and if you’re curious about milestones), this marks the 100th article posted on this site. This time, the article tells you how to change your hostname. It’s not something you should have to do often, but these are a couple of ways to change 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.

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