Check Your Linux Kernel Log For Errors With ‘dmesg’

You can check your kernel logs for errors with dmesg, if you need to. I previously wrote an article about checking your error logs with KSystemLog and checking the error logs graphically is my preferred way to check for errors. KSystemLog also shows more than just kernel logs.

However, a GUI environment is not always an option and you can use ‘dmesg‘ in a pinch. This will only output the kernel ring buffer. There are other other error logs, so this is just one way. Future articles will cover ways to read other logs.

The ‘dmesg’ application stands for ‘diagnostic message’ and prints the ring buffer from the kernel. Run by itself, it’ll output  a ton of information, so this article will also help you try to make sense of the output.

If you’re curious, the man page defines dmesg as:

dmesg – print or control the kernel ring buffer

And, well, that’s what it does. It does what it says on the tin. The buffer it’s reading is full of information, messages the kernel has left. Not all that information is about errors, but in those messages are error notifications.

Running dmesg by itself is likely a bit overwhelming. Feel free to try it out right now. Crack open your terminal, just press CTRL + ALT + T, and enter the following:

The output is way more information than you probably want to wade through – especially while being frustrated. So, let’s see if we can make this data more useful.

Read Error Messages With ‘dmesg’:

I hope you opened your terminal in the entry section. If you didn’t, you should do so now. Go ahead and open it, I’ll wait here until you’re back…

We already know that running dmesg by itself throws a ton of output. It’s the data in the kernel ring buffer and it’d be exhausting to go through it line by line.

So, first, if you’re checking the logs then there’s likely a reason. That reason will help you with this next command. You’ll need a pipe and grep so that you can process the output more easily. Let’s say you’re having monitor issues, which would lead you to try:

You can grep for other things, such as “Audio” or even “Mouse”. Go ahead and give those a try. You may have errors you don’t even know about.

Most of the time, dmesg is pretty uninteresting. You can actually filter it further, often to just a few lines – by just showing the lines that contain errors. To do that, just try:

If you want to clear out the logged data, you can do that easily enough. You will need to use sudo, and the command is:

Those are really the most important aspects of checking your logs for errors with dmesg. You can run man dmesg to learn about a few more options. As far as my experience goes, you won’t really have a need for the other flags.

Again, I wrote an article about KSystemLog and that will graphically show you your logs – including the kernel’s buffer. If you have a choice, you might as well use a GUI for this sort of thing.

Closure:

Yup… There’s another article. It’s one more step towards reaching my goal. Before we know it, that year will have passed and I’ll need to make some decisions. Until then, let’s keep the party rocking.

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: Write Text To A File From The Terminal with “>” and “>>”

The title of this article probably should have been, “How To: Write Text To A File From The Terminal With The Redirection Operators “>” and “>>””, but that’s just too long. With that length would also come some ugly formatting. WordPress has its benefits, but customizing that sort of stuff on a per-post basis is not one of them.

There are many redirection operators in Bash. That link will take you to some dense information regarding these redirection operators. Also, that’s the formal name – they’re a ‘redirection operator’, both > and >>. It took me a minute to even recall that they had a formal name, so you should probably mark that in your notes just in case there’s a quiz!

The only two operators we’ll cover in this article. We’ll learn to write text to a file from the terminal – or, more accurately, we’ll learn to redirect text to a file from the terminal. It’ll be easy and is very much a beginner-level skill to have in Linux.

Entirely off-topic: But you can download a free book (PDF) called The Linux Command Line by William Shotts. It is in its 5th edition at the time of writing and is worth downloading and reading.

Write Text To A File:

Obviously, you’ll need an open terminal for this. 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. Once you have an open terminal, you can change to your Documents directory (avoiding making a mess in you ~/ directory) with:

Now, with your terminal open, you can try the following:

Now, you can verify that you’ve echoed foo to a file named ‘temp.txt’ with the following command:

As you can see, it wrote ‘foo’ to the file. You may not think that all that interesting, but it can be useful. If you go back to my article about “How To: Generate a List of Installed Applications in Linux”, you’ll see it used there. Like, if you wanted to create a list of installed applications and save it to a text file, your command would look something like this:

It’s also useful for things like generating a list of your files and/or directories. You could just as easily run:

Now, if you run any of these commands back-to-back,  you’ll notice that the >> operator appends the data at the end of the file. So, if you ran the first command (echo “foo”) twice, your text document would say:

If you want to overwrite the data, you are looking for the > operator. If you use just the > then it will overwrite the existing data, so use with care.

You can test this by using the ls command above with the same output file name as the command where you echo foo and you’ll see that just the last command’s output was written to the file. So, try the following, where your final results will be ‘foo’:

You can actually use both > and >> to create a new file with zero bytes. It’s not like recommended or anything, it’s just something interesting that you can do with it. Just use the following:

Sure enough, you have a new file and now you know how to write text to a file from the terminal in Linux.

Closure:

And there you have it, another article. This article explained how to write text to a file. The redirection operators are handy tools to have in your toolbox. They’re useful tools when you want to work with large amounts of text. They’re useful tools when you want to keep track of a command’s output over time. You’ll find a use for it, I have faith in you!

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.

Automatically Logout Of Your Shell

For security reasons, you’ll possibly automatically logout of your user sessions. If you didn’t know, you can actually do that with your shell, in the terminal. There’s already a variable (TMOUT) just for this reason, should you want to add it as a layer of security.

Basically, for today, we’re going to set it up so that it automatically logs inactive users out of their shell session. It doesn’t log you out of your complete user session, it just logs you out of your shell – after a set period of activity. It even closes the open terminal windows when it does so.

So, depending on the interval you use, you can set it up to log you out of your shell instances after just a few minutes of inactivity. If you have nosy neighbors, like people physically near your computer, it can be a nice way to make sure things are all locked before you head off to the bathroom.

It’s useful for that sort of stuff. It’s just an added layer of security. I think that it is a pretty handy feature. I’ll explain how to enable it on a user-by-user basis and how to make it system-wide, giving you a choice. It’s actually pretty easy, so read on!

Automatically Logout Of Your Shell:

Like most good things in the Linux world, you’ll need an open terminal to take advantage of 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.

Both of these ways are pretty simple, in each case you add some text (using nano) to a profile file. The text in either case is the same. If you want to do it for just one user, the user you’re currently using, then run the following:

Add the following:

So, if you wanted it to be 10 minutes of inactivity before being logged out, you’d use TMOUT=600, because 600 seconds is 10 minutes. As you’re using nano, you can press CTRL + X, then Y, and then ENTER to save the file.

You’ll then force the profile to load, the command taking effect immediately, with this:

If you want to do it with the full system, the online guides will tell you to edit /etc/profile and that it’ll work if you do. My experiences are different and this is tested across multiple systems. You’ll be editing /etc/bash.bashrc, just like you did above but with sudo. (Using /etc/profile has not worked for me.)

Again, you add ‘TMOUT=600″ or however many seconds you want to wait. Personally? I scrolled to the bottom of the file, made a new line, and added the text that way. You could be all professional and add a comment indicating when and why you were there. I did nothing of the sort.

Unlike the first command, you’ll not be able to reload the second method (system-wide configuration) with ‘source ~/…’. As near as I can tell, you’ll have to restart the system for the changes to take place. If someone has a way to load it without rebooting, I’ll update the article. Please leave a comment if you do know of a way!

Closure:

There you have it, another article! This one tells you how to automatically logout from your shell. I’m not sure if it works for all shells, so feel free to test and see what sort of results you get. I’m pretty sure the 2nd option could be reloaded without rebooting, but I can’t think of which command. Which service would need restarting? I dunno?

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.

Find Your Username In Linux

Today’s article is going to be fairly brief and easy, as it just covers how to find your username in Linux. For this exercise, we’ll be using a terminal and some basic commands. It shouldn’t be too stressful or difficult. In fact, it should be just the opposite.

When you open your terminal, you’re usually greeted with some information. In that information is typically your username. However, it’s possibly that this is no longer true. You could have it display anything you wanted, plus there’s a chance you’re logged in remotely and just can’t remember which terminal window is connected to which device.

So, there are some reasons why these commands exist. I mean, you should probably know your username. That’s not the kind of thing I forget, but I am getting older. Still, the commands exist and must exist for a reason.

My motto is that they wouldn’t have provided a path if they didn’t want you to get to the destination. (That’s not really my motto.) So, if there’s a command that’ll help you find your username in Linux, you might as well know it and know how to use it.

Find Your Username 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.

With that terminal open, let’s try echoing the $USER variable. It’s nice and easy, and it looks like this:

You can also use who and whoami as commands:

And:

There’s also w, which shows logged in users – so you may be able to deduce your username from that list. It just looks like a:

The ‘w’ command nice and handy, and has a bit more information about the user. It would look similar to this:

w command's output showing username
See? It’s pretty easy to see that there’s a user logged in – and more!

As you can see, there are a number of ways. I’m sure that I’m missing some. Feel free to chime in and add to the list. Basically, if you want to share it with the world, leave a comment. Otherwise, many readers know where to find me.

Closure:

And now you have another article. This one isn’t fancy, nor is it something you’re going to need all the time. However, it’s still a very basic and useful tool to add to your Linux toolbox. Things like these are the fundamentals. How to find your username in Linux is an absolute beginner move and a move that leads you forward to more knowledge.

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.

Use A GUI To Manage Debian’s Software Repositories

You can manage Debian’s software repositories through the terminal, even by just editing some files. It’s not terribly hard, but there’s an “easier” way, and that’s to do so graphically. It may require some prep work, but it’s remarkably easy after you’ve taken care of that.

People sometimes ask if we prefer the GUI or a terminal, and that’s a complex answer. This is one of those times when it’s split up the middle, at least for me. For example, it’s absurdly easy to add repositories in the terminal, but it’s slightly more complex if you want to then remove those repositories. You need to remember things like the repo’s name – when you can just look in a GUI application and quickly see which repositories you want to remove.

If you’re new to Linux, Debian is a Linux-based operating system that is quite popular to build off. There are tons of derivatives, and even some derivatives of derivatives. Debian was released in 1993 and is the parent of popular distros like Ubuntu, and the grandparent of the many distros based on Ubuntu.

You know, I suspect more people use Debian derivatives than directly use Debian itself.

GUI Manage Debian’s Software Repositories:

I’m going to assume two things:

  1. You have a brand new copy of Debian freshly installed. 
  2. You only downloaded the first .iso and it is no longer mounted. 

Some folks can possibly skip ahead to Step 2.

Step 1: Remove CDROM from your sources

The first thing you’re going to need to do is get rid of the cdrom entries in your apt sources. If you try to install (or update) and have cdrom listed in your sources then you’ll bump into some errors. So, let’s take care of that.

Start your terminal with the trusty CTRL + ALT + T.

To fix that cdrom thing we’re going to need to edit your ‘sources.list’ file. To do that, we enter this in the terminal:

Find the line that starts with ‘cdrom’ and put a # in front of the line to comment it out. It should look a bit like this:

edit debian's sources list
That’s opened after editing. Your version may look different.

Next, save it. Seeing as we’re using nano, you do that pressing CTRL + X, then Y, and then ENTER.

At this point, we need to make sure the system knows we made that change. So, we’re going to update the lists of software available with this command:

That shouldn’t take all that long, especially if it’s a new installation. It takes even less time if you grabbed updates during the installation process. 

Step #2: Install software-properties-gtk

Seeing as you already have your terminal open, you needn’t open a new one. We can do the rest of this in just a single command. It’s actually really easy to do the rest, to set it up to graphically manage Debian’s repositories. Just enter the following command:

Press the ENTER key, type your password if asked, and press on the ENTER key again after entering the ‘y’ response if/when asked.

That’s it. You’re done. When you look in your menu, you should see a new entry called “Software & Updates”. Root around in the tabs and revel in your new tool to manage repos and a few other things.

Software & Updates on Debian
See? Mission accomplished and it wasn’t even all that painful! Congratulations!

You manage the main repositories on the first tab and can manage other repositories with the second tab. You can graphically manage Debian’s repositories without a whole lot of extra work. The hardest part was in removing the cdrom from the software sources. There are some other tools included, but those are the two main tools – or the two main tools that this article focuses upon.

Closure:

And there you have it! You have a new article. This one told you how to graphically manage Debian’s repositories. All in all, I’d say it’s pretty easy and something a fairly new user should be able to do on their own. Good luck and ask questions if you get stuck.

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.