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.

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: Find Your Timezone In The Terminal

This article is about your system time, specifically how to find your timezone in the terminal. It shouldn’t be a very long article and it should be relatively easy and suitable for new Linux users.

Why would you want to find your timezone in the terminal? Well, for starters you may not have the proper time set and need to verify it. You may also be working with servers scattered across the globe and knowing the timezone may be important.

As you may need things synchronized, knowing the timezone could be important. Seeing as you’re not always able to access a GUI desktop, you might want to find your timezone in the terminal. So, to those end, this article will share a few ways to do so.

Find Your Timezone In The Terminal:

Obviously, this article requires 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. If you’re operating remotely, you probably already have a terminal open.

Anyhow, there are multiple ways to do this. For starters, you can just use the date command. It looks like this:

The output will have your timezone in it. For example, the output of that command on one of my boxes looks like:

As you can see, the timezone is at the end. In my case, it’s “EDT” and that’s probably the easiest way to get the timezone information.

You can also use ‘timedatectl’ which looks like this:

That’ll give you the timezone and even tell you the adjustment from GMT. If you want, you can use grep with it.

That will, of course, just output the line containing your timezone. Also, I have no idea why it’s two words. I know it as one word, but here we are and I suppose it’s just not that important.

I have one more way to find your timezone in the terminal and it’ll output your timezone in text. It’s just:

The output from that would look a little like this:

So, there are a few ways. There are surely other ways, so feel free to leave a comment sharing them.

Closure:

And there you have it, another article. This one shares how to find your timezone in the terminal. It’s a relatively easy article to follow and not really a tool I expect most users to need. Still, it’s there if you need it and this article stands as a reference to 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.

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.