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