Navigate To The Start Or End Of The Line (In The Terminal)

Today is going to be another simple article, where you learn to navigate to the start or end of the line – in the terminal, of course. I’ve had some abdominal issues, so it seems like a good day for yet another accessible article.

Even though it’s an easy article, there will be many Linux users who don’t know this information. I’m not even sure how to describe it, thus the unwieldy article headline. So, if you want to navigate to the start or end of the line in the terminal, I’ll show you how.

This being Linux, there are so many ways to do this sort of stuff…

Imagine this:

You’re using Ubuntu and you want to update from within the terminal. So, you’ve typed the following:

Well, as you can see, the first instance of ‘sudo’ was spelled wrong – it’s missing a letter. You can reach over there and find the arrow buttons, navigate back to the start of the line, and fix it. Or, you can do the following:

Navigate To The Start Or End Of The Line:

As the title indicates, this is in the terminal. As such, you’ll need an open terminal to try this out. Just press CTRL + ALT + T and your default terminal should open.

With your terminal now open, why don’t we just use that line from above:

Of course, you could just look at your keyboard and (probably) use the HOME button to navigate to the start of the line. Of course, you could then use the END button to navigate to the end of the line. If you’re on a laptop, those keys can be placed most anywhere, though it’s far more standardized with a regular keyboard.

But, you don’t have to reach for those lines. Nope. That is not necessary. You can keep your eyes right on the screen. How so?

Well, it’s this easy:

To navigate to the start of the line, press CTRL + A.

To navigate to the end of the line, press CTRL + E.

Tada! You don’t have to root around for the home or end buttons. You don’t have to fuss with the arrow buttons. You can quickly and easily navigate to the start and end of the line with just those two keyboard shortcuts. I told you that it’d be quick and easy!

Closure:

There you have it, you have another article. This one is pretty simple but that’s okay. So long as it’s sharing some knowledge and I managed to get an article out on schedule, it’s all good by me. This time, you’ve learned how to navigate to the start of end of the line – in the terminal and without taking your eyes off the screen.

You might as well memorize the shortcuts as they appear to be pretty universal from my testing. They’ll likely be faster for you than any of the other methods, so they’re worth learning and adding to your growing toolbox of Linux tools. Ideally, my ailments will go away soon… I’m hopeful…

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.

Clear The Terminal

Today’s article will be a nice and easy article, where we learn how to clear the terminal. That is, we will clear any typed text and returned information from the terminal. This will be a nice and quick article.

I am feeling like garbage today and I still need to edit the last article. Ugh… But, the show must go on!

This is what I get for not having scheduled a few articles ahead. Fortunately, I have short articles in mind. Today is a good day for just that.

It should be noted that clearing the screen doesn’t delete your scrollback history. Someone could come along and use the up arrow to see your previously typed commands. If you’re at your workstation then I guess you could consider this a privacy measure – but it certainly shouldn’t be considered much of a security measure.

So, as I said, it’ll be a short article. Let’s just jump into it…

Clear The Terminal:

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, let’s generate some content… Run the following:

That should fill up your terminal with stuff. Now, let’s clear the terminal. Type the following command:

Tada!

But wait, there’s more!

Run those commands again. This time, and this appears to be pretty universal, just use your keyboard and press CTRL + L.

See? It does the same thing as you get when you type clear. Those are two ways for you to use when you want to clear the terminal.

Closure:

Yup… You’ve learned how to clear the terminal. I told you that it’d be a short article. It’s even an easy article. Now I’m going to lie down and hope for a nap. 

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.

Disable Specific Terminal Commands

In today’s article, we’re going to learn how to disable specific terminal commands. It’ll be an interesting article because we get to explore some different tools. It might get a bit verbose, but I’ll do my best! It’s going to be a long article, but I’ll try to keep it at under 1500 words.

It should be noted that this is for people using the bash shell. As I don’t sway too far in that direction, I can’t vouch for it working with something like ZSH or similar. I simply haven’t tested. Feel free to try. I know some of the shell alternatives are compatible so you can check.

Read on to learn how to disable specific terminal commands!

Let’s say you don’t want your computer users (or you yourself)  to run a command in the terminal. Well, you can stop that command from being run easily enough. To do this, we’ll explore some new concepts and tools. One of those topics is ‘aliases’. Let’s just start there…

About Bash Aliases:

In short, bash aliases are alternate ways to enter in a terminal command. You type one thing and the system interprets it as an alias for another command. Let me explain this bit further.

Let’s say you want to run the following command:

Well, if you wanted to, you could assign an alias for those commands. If you wanted, you could even change your aliases so that all you had to type is:

You’ll run the full command when you’ve entered the alias. Aliases are basically little shortcuts to other commands, often used when you want to enter the command quickly and it’s a longer command. You can more or less alias anything with anything if you put enough effort into it.

Getting Ready For Aliases

Still with me? Alright, now you 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 now open, let’s check to see if you already have the necessary file. I am aware that you can just add aliases to your ~/.bashrc file, but this way avoids clutter and is more easily portable.

So, we need to check to see if you have ~/.bash_aliases. You can run the following command (from your home directory) to see if you already have the file you need. Simply run:

Now, scan the output from that command. Do you see a .bash_aliases? If so, skip ahead. If not, you will need to create the file yourself. One way to do so is by using the following command:

That command will create a blank file (named .bash_aliases) in your ~/ directory. It is the only file we needed to create and will be the only file we need to edit. You’ll also use nano, which my readers should be familiar with already. Don’t close your terminal yet, we’re still going to need it in the following section.

With just a few tools, we’ll learn how to stop specific terminal commands.

So then…

Disable Specific Terminal Commands:

I had to write that giant intro just to get a newbie up to speed. I’ve been meaning to explain aliases for a while, but I suspect the topic will get its own dedicated article. It’s a pretty broad subject.

For this next session, we’ll use a harmless ‘uptime’ command. Let’s just run that in the terminal just once:

Now, for whatever reason, we will have to pretend that you have decided you want to disable specific terminal commands and uptime is one of those commands. To do that, you’ll start with the following, editing the file you just created:

You will want to start a new line and the command is formatted like so:

For example, you can have an alias like this one:

Save the file with nano. It’s not too daunting a task to save the file. To save a file in nano, all you need to do is press CTRL + X, then Y, and then ENTER

In the above example, if you were to type ‘myip’ into the terminal and run it, it’d almost run the command you told it to run.

You’re almost there. There’d be just another step.

You’ll have to reload the aliases before the system recognizes it as such. I’ll explain how to do that in a second.

Now, if you want to disable specific terminal commands all you need to do is fill the <command> section with a blank space or two. As it is our example, we don’t want the user running this uptime command, it’d look like this:

See? Not all that complicated and we’re almost reaching the end – just one step further and your new alias will work as you’d expect – or not work, as one would expect in this case.

Make Your Alias Permanent:

First, to make that alias stick around you need to have saved the updated ~/.bash_aliases file as was explained above. At this point, the alias will not work. The file you wrote isn’t loaded into memory. It takes a bit more than that.

From here, you could close all your open terminals, log out and back, or reboot – any of those will reload your bash aliases. Alternatively, you can run the following command, which will refresh your terminal’s list of aliases. Like so:

If you’ve done everything properly, you’ll find that this happens when you try to next run the uptime command:

the user is unable to run a specific command - in this case the uptime commnd
That’ll teach ’em from trying to run that pesky uptime command! Catastrophe averted!

But…

If you want to disable specific terminal commands, you might be wanting to do so for security reasons. The ~/.bash_aliases file is owned by the user, so the user can just edit the .bash_aliases file to remove your edit.

So, what can you do? You can make it permanent for everyone. You can add it to /etc/.bashrc, and a user with limited rights won’t be able to edit the file. If they can’t edit the file, they won’t be able to remove the alias. They won’t be able to use the terminal command(s) you’ve aliased to nothing. If you were to simply edit the /etc/bash.bashrc you’d just start a new line at the bottom and then insert the aliases using the same format. 

I haven’t tested it, but I’d wonder if /etc/.bash_aliases might also do the trick in preventing user edits to override your changes. Feel free to test and then let us know. It’d be interesting if you could do something with /etc/skel/ and changing the file permissions – effectively for new users created.

Closure:

There… I think I’ve covered everything. I’ve wanted to write about the bash aliases subject for a while, but it’s just a bit complicated to explain. So, I figured I’d write this article. It’s a long one, but there’s a whole lot to cover. This goes into it pretty heavily, but an aliases-specific article might be nice to have.

Either way, you can now disable specific terminal commands. You can probably temporarily lock yourself out of your own system, so be careful with what aliases you add as system-wide aliases.

If you do lock yourself out, you should be able to boot to a live Linux disk where you’ll mount the drive and just revert your changes. But, anyone with physical access to your computer owns your computer, which is worth keeping in mind.

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 Files Owned By A Specific User

In today’s article, we’re going to explore one way to find files owned by a specific user. We’ll be using the ‘find’ command for this exercise, which means it’s probably an article more for an intermediate user than a Linux beginner.

NOTE: This article is mostly a duplicate of an earlier article. I didn’t realize that until after I was done and hit the preview button. So, I saved it as an unpublished article, with the goal of just hitting the publish button (scheduling it, really) when I had a day where I was just otherwise occupied. Today is that day. After all, the “Big Game” starts in about 30 minutes.

But… I’ll do my best to make it one small bite that’s useful for beginners, but there’s no guarantee. I’ll see what I can do! So, if you want to play around with the ‘find’ command, read on!

The ‘find’ command does pretty much what you’d expect it to do, given the name. It’s used to find things – so you don’t have to stretch your imagination any to figure this command out based on the name.

You’ll find that ‘find’ describes itself succinctly, as this:

find – search for files in a directory hierarchy

See? Pretty much exactly as you’d expect. As you can also see, you’re probably gonna be asked to specify a directory. We can do that! Even you new Linux users can do that. I have faith in you!

So then, with that information freshly reviewed, there’s no reason to make the intro any longer. Let’s just jump into the article…

Find Files Owned By A Specific User:

If you’re a regular reader, you know what’s coming…

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.

Let’s start by finding files owned by you in the ‘Downloads’ directory. With the open terminal, enter the following:

Now, the ‘.’ is telling the ‘find’ command to search the current directory. You have to specify the username. For example, with me, it’d be:

You can also specify another user. Want to see if ‘root’ owns any of the files in your ‘Downloads’ directory? You can do that. Just change the username, like so:

Want to find all the files owned by root on the whole system? Well, you can do that – but it’s gonna be a whole lot of files and is going to take a while to run. You just specify the root directory (not to be confused with the root user). You do that like so:

In that command, you’ll notice we switched the path. We changed it to ‘/’ which is the root of the file system. You can be even find out if root owns any files in your user directory. Try this:

In my case, I’ve done things like compile and install software from my ~/Downloads directory, so I actually have files in there that are owned by root. If you’re a new user, you quite likely won’t have anything like that going on.

Play around with the ‘find’ command a bit, and it’ll become a bit more clear. Don’t forget to run man find to learn more about the command. There’s a lot more to it and it can be a pretty useful command.

Closure:

Anyhow, that’s a small bite of the ‘find’ command – but it’s a useful bite. The goal is to take a small bite and do what I can to make it approachable by even a new Linux user. Hopefully, I’ve done just that. Give me a yell if you think it worked – or if you think it didn’t work. 

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.

Rerun The Previous Terminal Command

Today’s article should be simple enough, where we’ll just be covering how to rerun the previous terminal command. This will be something many new Linux users won’t know about, and may come in handy. If you want to learn how to rerun the previous terminal command, read on!

This is another one of those short articles where I just try to share something basic in hopes of people seeing it. The more advanced Linux users are already aware of this command, but new users are unlikely to know unless they’ve been reading books or taking lessons online somewhere.

So, what we’ll be doing is running a terminal command – but we’re also going to show you how you can use this to modify a previous terminal command. I’ll try to give you an example of when you might want to do so.

It will not be complicated. It should also be remarkably short. I really don’t think I can fluff this out to be all that long… 

So then, let’s learn how to rerun the previous terminal command…

Rerun The Previous Terminal Command:

Obviously, this is going to require an open terminal. That’s easy enough. Just open your favorite terminal or just press CTRL + ALT + T and your default terminal should open.

With your terminal open, let’s check your uptime. To do that, you just run this command, like so:

If you wanted to run the command over again, there are a number of ways to do so. But, we’ll be using ‘!!’ to run it over again. To run uptime over again, just enter this command:

Sure enough, it runs the uptime command all over again. See? You’ve already learned how to rerun the previous terminal command. But, wait, there’s more!

Let’s say you wanted to check out your hardware and you ran this command:

If you pay attention to the output from that command, it suggests you run the program with elevated permissions, like with sudo. To rerun the previous terminal command as sudo, you can just run:

Pretty neat, huh? You can do alsost anything before rerunning the previous terminal command, like changing the directory, making a directory if you forgot to, or adding a command you forgot the first time.

Closure:

Well, there you have it. It’s another article! I couldn’t make this a longer article, try as I might. That’s okay, you’ve now learned how to rerun the previous terminal command and how to modify it. A short article is better than no article, which is nice!

NOTE: Yes, you can do it in reverse. If you type ‘sudo‘ and hit the enter button, you can then type ‘!! lshw‘ and run the command as ‘sudo lshw‘. It’s pretty neat and not something everyone is aware of. Well, now you know – and knowledge is power!

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.