Hello everyone! Today I’d like to share some of my favorite and most used bash commands. You will be a novice ninja once you learn these. Trust.
You can watch the video or scroll down below
TERMINAL COMMANDS
pwd
Our first terminal command is “pwd”. Caps are irrelevant. What “pwd” does is tell us where exactly we are located in our terminal. As you can see below, we in my home folder, which is the lowest level. Whenever you are lost after entering many different folders in your terminal just type “pwd” to see where you are.
Warning: I have my terminal prompt already set to the path whenever I enter folders. Most people do not have their prompt as I do so it will mirror pwd in these images but if you do not have the same feature as I, it will be different so you’d always have to type “pwd”.
LS
The next command is “ls”. “ls” means list, and gives us all of the files and folders in our current directory. These are the files in my home folder.
Clear:
Look toward the bottom of the first image below. Here, I’ve typed “clear”. We use clear whenever our terminal gets too messy or cluttered. The second image is the result. It’s a fresh start so we can use it every time we are nearing the end of our terminal. Try it if you’d like!
cd:
If we’d like to enter into a folder/directory we’d use the command “cd”. Below, I am “cd”ing into the directory “food”. It’s an empty folder I already had in my home. We also have the “pwd” command below. The result shows us that we are now in the food folder.
“cd” also has other commands. “cd ~” returns one back to their home folder. “cd ..” returns one back to the folder just before (you’ll eventually have folders inside of folders so you’ll be using this one a lot).
mkdir:
To make a folder we use “mkdir”. When you type “mkdir” followed by whatever name wed’d like to name our folder, we create a new one. Below, we’ve created a folder in my food folder named table. We use “ls” below to verify that we’ve created it.
mkdir -p
Now we “cd” into table (enter) and pwd (view location). We type “ls” to view the contents of our table directory but it is empty. Next, we use a really awesome command, “mkdir -p”. Mkdir -p allows us to create multiple folders within each other at once instead of having to “cd” into each folder to make a new one. You may find this useful at some point. After using this command and typing “ls” we see that the table directory has something folder in it. We “cd” again into something and “ls”. Now we see the about folder we created. “cd” again into that one and we have our you directory. Isn’t that the cooliest?
touch
To create a new file we use the “touch” command. Use “touch” followed by the name of a file you’d like to create. It could be a .txt, .py, .js, .html. It does not matter. You can also make more than one file at a time as portrayed below.
Atom file_name.txt
This next one is pretty cool. I wish I knew about it sooner. If we want to open up any file that we have in our current directory or a file that we’d like to create, we can just type “atom file_name.py (you decide the name)”, and our text editor will open up right there. If you have another text editor on your computer you can put the name of it as well and then the file.
Cat
Cat spills out the contents of a file into the terminal. In the image above, we wrote text into apple.txt in the Atom text editor. In the image below we type “cat apple.txt” and the contents spill onto the terminal. Como asi.
Less
Less is similar to cat in that it show us the contents of a file within the terminal. The output is different however, and shows on another screen in the terminal as exemplified in these images here. We can use either one.
CP
CP stands for copy. We can copy files and folders into other folders. In our example of apple.txt, we make a copy of apple.txt within the food folder, and into our table folder. Once we “cd” into table, we will see that apple.txt was copied there as well as its contents.
MV
We use “mv” to rename a file we’ve created. When using “mv” make sure to follow it up with the name of the file we would like to change first and then the new name after. For example: “mv original_file.txt new_file.txt”, now original_file.txt is renamed to new_file.txt. Check the examples below.
Rm
If you want to delete a file you’ve created, use “rm”. Like touch, you can delete a file one by one or several at a time.
Rmdir
We use “rmdir” to delete folders in the terminal. In the example below, we create two folders, “quilt” and “curtain”. Next, we “ls” to show they were created. Finally, we reach the moment we’ve been waiting for. We “rmdir quilt” and now quilt has been deleted.
*Note: We cannot delete folders with files in them with rmdir, we have to use a recursive function. Personally, I just delete directories with contents in them from the computer interface. I do not want to show you all any recursive deletion functions in this post as there are too many warnings when using them. Feel free to utilize Google for this gap.
Type
“Type” can be used for many things. If we have any aliases within our terminal we can use “type” followed by the alias to see what its true identity is. There will be a follow up post on Dot Files with aliases and functions coming soon.
man
Man Oh Man. So, “man” stand for manual in a terminal. If we are ever confused on what a particular command does we can just type “man” followed by the particular command. In the example below, we use the “clear” command and the result is its definition, etc.
Well, there you have it folks. Isn’t this great? I can’t believe I’m so late and just using these terminal commands. One of my tech goals is to be a security expert, so I need to know the terminal well. I’ll be digging deeper.
PEACE