Linux Command-Line for Absolute Beginners

Linux Command-Line for Absolute Beginners Featured Image - Prompt Symbol

If you are a beginner in Unix/Linux, you might have heard the term terminal or command prompt. We’ll use these terms interchangeably in this tutorial.

You may have experienced it yourself, a black screen with cursor beeping for you to enter some commands.

In my experience most people are uncomfortable with it. When I was younger and I first came in contact with this black screen, I was terrified. I always thought that hackers use this for hacking, so it can only be operated with experienced users.

In this article I’ll try to convince you why the command line isn’t that scary, and how to start getting comfortable with it by practicing some basic Linux commands.

In this article we’ll talk about the Linux command line, known as terminal or shell. Other command lines of Windows, Mac etc. are almost the same, some syntax or commands may differ.

Quick History of the Linux Command-Line

The black interface you see to interact with the operating system, is a text-based interface known as command-line, shell, or terminal, console, prompt etc.

The first-generation computers were not that smart like today, and most of them were mainframe, big giant computers. Moreover, the computing power and network speed was low, so text based was the only option for many users to work faster and simultaneously. The initial shell for Unix was The Thompson shell, written by Ken Thompson. Having its own limitation, replacement came from Stephen Bourne in 1979 known as the Bourne shell. In 1989, Brian Fox created the Bourne Again shell, in short “bash”, as a free software. This is the default shell for most Linux operating systems nowadays.

Don’t get bored. Let’s start to ease into using the command-line.

Starting the Linux Command-Line

If you’re using a computer without a graphical user interface (usually a server), then you’re already using the command line.

If you’re using Linux with a graphical user interface, such as a desktop computer, you should be able to launch it by pressing Ctrl+Alt+t or you can find it in your menu.

Linux has multiple desktop environments, and these menus vary. If you have the possibility to search through your installed apps, you can search terminal, command, prompt or shell and the black icon will appear.

In this example we’re using Red Hat Enterprise with the GNOME desktop environment. As you can see, in GNOME you can click on Activities and you should see a shortcut with an icon resembling a miniature terminal.

word image 67

If you click on it, a terminal will be opened and it will look like below.

word image 68

An empty terminal window provides you with three bits of information.

  • Current username, [ here xyz is the current user ]
  • The hostname, [ here the hostname is localhost]
  • Current directory (by default, your home folder, indicated by a ~).

The $ marks the end of the prompt. After this sign, you will be prompted to enter commands, and press Enter to execute your commands.

Let me now write any arbitrary text in the shell.

word image 69

The output shows that the command is not found.

So as you can probably tell, to execute something you have to know the correct text command. Your system won’t be damaged if you write random text. It can be damaged if you run certain commands, however. Like deleting files and folders or overwriting sensitive files.

Some Linux Basic Commands

Now, let’s practice some basic commands.

1. pwd (print current directory)

The pwd command stands for print current directory. It will print or show where you are right now in your directory hierarchy of your system.

As we can see, we are inside the /xyz directory which is inside /home.

pwd

word image 70

2. cd (change directory)

cd command stands for change directory. If you are in a directory and want to go to another, you have to use cd.

The syntax for the cd command is:

cd <path>

word image 71

As I want to change directory to Downloads, the command for that is:

cd /home/xyz/Downloads

Let me explain what we’ve done here.

First, we’ve checked where we are now using pwd.

We are in the xyz directory. Now we want to go to our directory Downloads.

I want to change my current directory to the Downloads directory. For this we have to write the path where we want to go, with cd in front.

You can again check whether you’ve landed in the right place or not. How? We’ve just learned about using pwd. We executed the pwd command again and our current directory is printed.

[powerkit_alert type=”info” dismissible=”false” multiline=”false”]
Tip 1: We can use Tab to autocomplete our typing. Like I want to go to Downloads, I will type D and press Tab. It will show all the options available, if there is only one then it will be auto completed.
[/powerkit_alert]

word image 72

Here I am shown three options, all of them start with D. So now I write Dow and press Tab, my type will auto complete with Downloads, as there is only one directory Downloads that starts with Dow.

[powerkit_alert type=”info” dismissible=”false” multiline=”false”]
Tip 2: Linux commands and hierarchy, all are case sensitive. So if I type d instead of D, it will start searching for directories starting with d. Again, if you write PWD or Pwd or anything other than pwd, error occurs.
[/powerkit_alert]

word image 73

3. echo (output something)

You could say the echo command is somewhat self-explanatory. Whatever you want to print, this command will echo it in the terminal. For example, I want to print hello world in the terminal. The command is:

echo "hello world"

word image 74

4. mkdir (make directory)

mkdir stands for make directory. Let’s create a folder.

To create a folder, the command is simple:

mkdir <foldername>

First let me check where I am. What command to use? Yes! pwd.

word image 75

I am in the /xyz directory. Here I will create a folder named my_folder.

So the command will be:

mkdir my_folder

word image 76

Congratulations! We’ve created our first folder via Linux command line.

[powerkit_alert type=”info” dismissible=”false” multiline=”false”]
Tip 3: You can just press the up arrow and previously executed commands will be displayed on the terminal.
[/powerkit_alert]

5. touch (create empty file)

Like folder creation, we can create files also. For file creation the command is touch. The full command will be:

touch <filename>

[powerkit_alert type=”info” dismissible=”false” multiline=”false”]
Note: The touch command is used for more than creating empty files, however this just happens to be a frequent use of it. You can find out more in our article on the touch command.
[/powerkit_alert]

Let us create a file in our previously created directory my_folder.

As we’ve learned earlier, we should check first what is our current directory using pwd. Then for changing directory what command to use? Yes! cd.

We will now change our current directory to my_folder. The command is:

cd my_folder

Let us again check if we are in the right place using pwd. Right, our current working directory is /home/xyz/my_folder.

word image 77

We will now create a file named myfile.txt and the command will be:

touch myfile.txt

word image 78

6. cat (output file contents)

As of now we’ve created a file, but it is empty. We can view the content of a file using cat command. cat here does not mean fluffy kitty, it means concatenation.

The command syntax:

cat <filename>

Let me view the content of myfile.txt. The command will be:

cat myfile.txt

word image 79

As the file is empty, nothing is shown on the terminal. Let’s write something in the file using echo and save it in myfile.txt. The command is

echo "something" > <filename>

word image 80

Now for viewing the content, again use cat.

word image 81

[powerkit_alert type=”info” dismissible=”false” multiline=”false”]
Tip 4: Use the man command. man stands for manual. If you come across any command you don’t know, just type man  to get yourself familiar with the command. For example, you may have heard the commands rm, sed, awk, ls, or others. Just go through the manual page of these commands.
[/powerkit_alert]

word image 82

word image 83

Press q to quit from the page and return into the terminal.

7. ls (list files and directories)

We have created files and folders via terminal. If we want to view what file and folders are in our current location, we will use the ls command. ls means list file and directory.

We are now in our user xyz’s home directory. How to check? Yes! “pwd.

word image 84

We can enter the ls command, and can see the files and folder in home location.

word image 85

Here we can see our own created directory my_folder. Let’s explore what file and folder it contains.

We will first change our directory to my_folder using cd. Then enter the command ls.

word image 86

Here we can see that it contains one file and it is our own created myfile.txt.

In short, I hope I can give you an idea of how the command line works. It’s not as scary as we initially think it is!

On a GUI (Graphical User Interface) based system, you are limited to what options the GUI provides. But the command line is like anan open world. Your options are unlimited here. And you can do much more than what we’ve shown you in our examples.

You can do wonders with using the command line. You can run one command or multiple commands together. You can do repetitive command tasks by simply writing a script containing all the commands and executing the scripts again and again. On some level, you have to SSH into another server or into a production server, where in the data center there is no GUI or monitor.

Now why are most people afraid of it? To simply put it, it’s the rigidness of ours to new things. We often fear to embrace new things – it’s pretty much fear of the unknown. It’s not what we are used to, so naturally we should be a little intimidated by it.

I am not saying that GUI is bad and I am not saying the command line is the best way of doing things all the time. Nowadays, most modern Linux distros are offering interactive GUI for users to ease their operation. But having a clear concept over the terminal will be hugely beneficial for you in the long run.

The best way to do that is to start using the terminal for everything. Then slowly you will get over your fear of the command line and start using it like a swiss army knife.

Conclusion

In this tutorial we covered some of the basics of the command line. We hope it helped you out, even if just a little. If you have any feedback or questions then please feel free to leave a comment and we’ll get back to you as soon as possible.

0 Shares:
Subscribe
Notify of
guest
Receive notifications when your comment receives a reply. (Optional)
Your username will link to your website. (Optional)

0 Comments
Inline Feedbacks
View all comments
You May Also Like
Bash Comments
Read More

Bash Comments

Comments are used in programming languages as well as in Bash script for writing descriptions. Often you want…