Beginner's Guide To The GNU/Linux Terminal

William

Active Coder
Sep 7, 2019
178
32
38
Hey there.

Today, I'll be showing you the basics of the GNU/Linux Terminal that comes with every Installation of GNU/Linux [Distro]. You'll learn how to Navigate through Directories, how to create Directories, how to perform Updates via Terminal, how to create and remove Files and a couple of other stuff. Anyways, let's get started.

Note: This Tutorial is for Users of GNU/Linux Debian and any Debian-Based Distribution. On another Distribution such as Fedora or CentOS, you'll need to look elsewhere online. Sorry for the inconvenience.

First off, you're gonna want to open-up Terminal. Look for it in the Start-Menu of your Distribution. It will be in your Dock(GNOME) or your Panel(MATE/KDE). If you can't seem to find it then no worries. Overtime, you'll start using Shortcuts. These are Commands that can be used to quickly do something without having to Navigate through Files and Programs just to do it.

The Shortcut to open-up Terminal is: CTRL+ALT+T

That's the default for every Distribution but later on, you're free to change it.

Once we've opened up Terminal, you should see a Window, that contains your Username, the Name of your PC, a Dollar-Sign and a Blinking-Cursor. The Dollar-Sign just means that the Terminal is ready to accept Commands.

Let's start with the basics. Navigating through the System-Files. In GNU/Linux, to Navigate through the Directories using Terminal, we insert cd [Directory]. It works the same as on MS Windows. You insert the Command then the Directory that you want to go to.

Let's start off with: cd Documents
Your Terminal will now display this: [B][email protected]: [/B]~/Documents$
That means that the Terminal is saying to you: "You're in the Documents Directory" and the Dollar-Sign, again, means it's ready to accept another Command.

If you type in: cd, you'll be taken back to the Home-Directory. Now that I've showed you how to Navigate through your Directories, it's time that you learn how to create Files and Directories and how to remove them.

First off, go back to your Documents-Directory using the Command from earlier. You'll be taken back into your Documents in which we will start creating Files.There are several ways to create a File in Linux-Terminal but for this tutorial, we'll be using the cat > Command.

When you're back in your Documents-Directory, insert: cat > file.txt. Now when you do this, you won't get another Dollar-Sign. You'll instead be writing content to the new File. Just type in random stuff and then press: CTRL+C on your Keyboard. CTRL+C will quit whatever you're doing in Terminal. To check that the File has been created, insert: ls. What this Command does is that it lists every File and Folder in the Directory that you're in.

You can learn other Methods of making a File, here: https://linuxhandbook.com/create-file-linux/

Now that you know how to create a File, let's learn how to Remove a File. Let's remove that File that we just made. To remove a File, insert: rm file.txt. This will remove our File that we just created. To check that the File was deleted, use the ls Command to display a list of the Files in your Directory.

Side-Note: There is a common joke on the WorldWideWeb that people do. This joke is the sudo rm -rf / Command. What this Command does is that it destroys your entire GNU/Linux OS. If you see someone telling you to execute this Command, don't do it. You will wreck your entire GNU/Linux PC and will be forced to fix everything by yourself. You've been warned.

Anyways, let's learn how to create a Directory/Folder. To do this, insert: mkdir New_Directory. This will create a new Directory in Documents called, "New_Directory". Using the ls Command, we can check to see if it has been created. You can use cd to Navigate into the Directory if you want to but I'm not going to do that. Instead, I'm going to delete the Directory. If you did Navigate into the new Directory, just insert: cd Documents and you'll be taken back into your Documents-Directory, in which from here, we can delete this new Directory.

To delete the new Directory, insert: rm -r New_Directory. This will delete our new Directory and again, we can check that it has been deleted using ls.

Now that we know how to Navigate through the Directories and how to create and delete Files/Directories, it's time that you move onto something else. Welcome, the sudo Command. This Command gives us Administrator-Privileges inside of Terminal and so we can do almost anything with our System at this point.

Side-Note: Always be careful when using sudo and having Administrator-Priviliges. Again, this goes back to the sudo rm -rf / Command. If you mess around with Administrator-Priviliges then you're in for one hell of a time.

sudo can be used to change Privileges, install new Packages/Software and even update our System and the Packages on our System.

Let's start with Updating. First, go back to our Home-Directory. Read back to learn how to go back to the Home-Directory or just exit and start Terminal again.
Second, insert: sudo apt-get update. This will check for any Updates on your System and update the System-Repositiories. It is recommended to do this before you install any new Packages/Software.

Next, insert: sudo apt-get upgrade. This will display all of the new Packages for you to download. If there are any, insert, 'y'(For 'Yes'). If you wouldn't like to install the Packages just yet then insert, 'n'. When you insert, 'y', your System will start updating the new Packages. The good thing about GNU/Linux though is that you can continue working while it's Updating. So, no more 'Windows Updating: 10%'. Once the System has upgraded the Packages, make sure you reboot as soon as possible. It doesn't have to be right now but just to be on the safe-side of things. But you should always reboot when it's a Kernel-Update.

Next, is installing Packages. Again, we'll be using sudo for this Command. If you ever want to install a Package/Software then look around online and see what Packages are available. For this tutorial, we'll be installing EMACS, a Free-Software Text-Editor by the GNU Project. To install EMACS via Terminal, just insert: sudo apt-get install emacs. This will install both the GUI-Version and Terminal-Version of the EMACS Text-Editor. And when it's done, you now have a Text-Editor on your Computer.

But if you don't want to have EMACS then there are two ways to remove it:
  • sudo apt-get remove emacs - This gets rid of EMACS but it doesn't get rid of any Configuration-Files or special Files for it.
  • sudo apt-get purge emacs - This will delete EMACS but will also delete all of it's Configuration-Files and any other special Files for it.
If you want to just remove the Program, then use sudo apt-get remove [B][package[/B]] but if you want to get rid of both the Program and any special Files for it then use sudo apt-get purge [B][package][/B].

Well, that wraps it up for today's lesson on the GNU/Linux Terminal. I hope you learned something useful out of it.

Thanks for reading!
 
  • Like
Reactions: Malcolm