Linux terminal for beginners - A quick guide
Aderibigbe Samuel
Posted on May 23, 2023
Do you know that there was a time when computers only display texts and the only input device to tell the computer what to do was the keyboard? Yeah, computers were used by the few who understood how to input commands and then interpret the text information displayed on the computer screen. Here was the workflow, users could only interact with the command line by typing text-based commands and an action is performed or a text information is displayed. Back then, users had to be very careful with typing commands because one wrong command can perform an unwanted action or delete a file or even close the command line program. So the use of computer was limited in a way until the invention of mouse in 1964 and Ivan Sutherland's invention of a computer program called sketchpad which was regarded as the first Graphical User Interface program. Graphical User Interface GUI makes use of graphical icons and audios to help users interact well with the computer.
when you want to open your browser, you would click on the browser icon with your mouse or trackpad on your pc, right? But you could do the same on your command line by typing some texts. let's say I want to open safari (a web browser) from the command line, I will type the following texts:
open -a safari
So, which is easier? clicking icon or typing texts? yeah, it's straight forward GUI is easier but not necessarily faster.
Shell while GUI and Command line interface(CLI) are the ways we can the interact with the computer, Shell is really the program responsible for helping the operating system understand the commands. you would hear words like Window shell and Bash (Bourne Again Shell). BASH Linux is very popular because it's open source and free. Windows operating system comes with it's own shell called windows shell but you can also install Linux on Windows, click here on how to install linux on windows
Now, let's learn how to perform some operations using Linux commands
Windows users: Open PowerShell or Windows Command Prompt
Mac Users: Open the Terminal app
Here are some of the frequently used commands:
• cd (change down a directory)
• mkdir (make directory)
• cd .. (change up a directory)
• ls (list files in your current directory)
• pwd (print working directory)
• touch (create a new file)
Making a directory mkdir :
I'm sure on your desktop you have some folders and inside those folders you have kept some files there. Making a directory is doing the same thing, so for the purpose of this tutorial think of making directories and creating folders (even though a directory is different from a folder). The first thing you would determine is the location to create your folder, maybe on desktop, downloads or even inside another folder. Let's say I want to create a directory(folder) on my desktop, so the desktop is the location I want to keep the folder. First thing is to navigate to the location by typing:
cd ~/desktop
So I have navigated into my desktop location, I can then create the directory, let's assume the directory name is "projects", I will use the mkdir command :
mkdir projects
if you correctly typed this command, you wouldn't see anything change but if you minimize your powershell or terminal and go to your desktop, you will see a folder called "projects" created.
Create Files inside a Folder:
Imagine you need to create a file in a folder, remember we've created directory called projects? now, let's create a file say "homepage.html" (the .html is the file extension for html documents). first navigate into the "projects" directory which is the location where you want to store your file:
cd projects
Now we've changed our directory from "desktop" to "projects", we can then create the file by using the touch command:
touch homepage.html
again, if you go on your desktop and open the "projets" folder, you will see a file named "homepage.html". Notice how we navigated from desktop → projects, usually if you are using a GUI you can easily see which location you are, be looking at some icons but if you want to know which current directory you are on the command line, you need to ask by using the pwd command:
pwd
you would see something like this:
(base) Savvies-MBP:desktop sammiesavvie$ cd projects
(base) Savvies-MBP:projects sammiesavvie$ pwd
/Users/sammiesavvie/desktop/projects
(base) Savvies-MBP:projects sammiesavvie$
/Users/sammiesavvie/desktop/projects is the path to the current directory I am working on and it also means that I am in the "projects" directory.
often times when your see paths like /sammiesavvie/desktop/projects, it means the destination is "projects" but "projects" folder is inside desktop directory while "desktop" is also inside "sammiesavvie" directory.
Now that I am in the "projects" directory, Let's imagine I want to go back to the desktop, desktop ← projects. In GUI, you would usually see a go back icon but on the command line you need to type this command:
cd ..
Now I have navigated back to my desktop directory
List all files in a directory:
To see all the files in a particular directory, make sure you have navigated into the directory and then type this command:
ls
You can see the files I have in my project folder is listed, there are some hidden files that is excluded tho. to include the hidden files use:
ls -a
Rename and Delete files:
If a file named homepage.html is inside my projects folder and the projects folder is inside the desktop directory, the path to the file will look like this ~/desktop/projects/homepage.html. To rename a file use mv . for example to rename homepage.html to about.html
~/desktop/projects/homepage.html ~/desktop/projects/about.html
This will rename the file. while this method works, it can also be tricky in that you need to be able to provide the correct path and the file name. usually I will just nagivate my way to the file from desktop → projects:
cd ~/desktop
note that you do not need this command if you are already on your desktop
cd projects
Now to rename the file:
mv homepage.html about.html
Now, I do not see any prompt that the file has been renamed but if I look at the "projects" folder, I will see that the file has been renamed, I can also do see this by using the ls command:
I now see the file renamed as "about.html"
Delete a file:
To delete a file i will use the rm command but be sure that you are in the right directory when the file is located:
rm about.html
so far, I have talked about:
- [x] cd -to change directory
- [X] mkdir -make directory
- [X] ls -list files
- [X] pwd -print working directory
- [X] touch -to create a new file
- [X] cd .. -change up directory
- [X] mv -to rename a file
- [X] rm -delete a file
This are most of the Linux commands for working with files.
In this article, You have learnt the two ways we interact with the computer and how you can use Linux commands to work with files using CLI. Although, Command Line interface may seems difficult and stressing but understanding it is important as it is very powerful and fast.
Posted on May 23, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024