Efficient Directory Management in Bash

Windows

Let's say we want to make a couple of directories. my cool folder two and my cool folder three. We could just type mkdir my cool folder two and then type again mkdir my cool folder three. But instead we're going to use another cool Bash feature called history. ๐Ÿ•ฐ๏ธ

Utilizing Bash History ๐Ÿ—„๏ธ

Each and every time you enter in a command, it gets saved into memory and add it to a special file. You can go through the previous commands you used with the history command. I'm now showing a list of commands that I entered earlier. This information alone isn't very useful. Instead, there's a better use of the history that lets us quickly scroll through these commands and use them again. ๐Ÿ”

We can scroll through these commands with the up or down keys on our keyboard. I'm going to go up to my previous command and I should see that I had mkdir my cool folder. Instead of typing the whole thing to make a new folder, I'm just going to append the number two to my command. Boom, a new file was created without having to type everything over again. Cool, right? ๐Ÿ˜Ž

You can even search through your previously used commands using the history shortcut, Ctrl-R. From here, you can start typing bits and pieces of the command you want to look for and I'll show you matches. Let's search for the word folder. I should see the mkdir commands I was using before. Pretty neat. ๐Ÿง 

If you're using an older version of Bash, it may not have the Ctrl-R feature. If that's the case, you can type the # symbol followed by some part of your old command and then use tab completion to cycle through the items in your history. ๐Ÿ”

The history feature along with tab completion and get-help will be your best friends while you work in Bash. Keep them close to you and get to know them super well. ๐Ÿค

Clearing the Terminal ๐Ÿงน

Our shell is looking a little cluttered. It's kind of hard to see where I'm at. So let's clean up our shell a little bit. We can do that with the clear command. This doesn't wipe your history, it just clears the output on your screen. It looks a little better. ๐Ÿงน

Linux Bash History and Clearing the Terminal ๐Ÿค–

Bash History ๐Ÿ“œ

The exact same history command that's used in Windows is used in Linux. From here, we can use our up and down keys and even search through our history with Ctrl-R. ๐Ÿ”

Clearing the Terminal ๐Ÿงน

To clear your terminal up, what do you think you do? ๐Ÿค”

That's right. The clear command. ๐Ÿ’ป

Last updated