Basic Linux Commands

Basic Linux Commands

In this article, I am going to discuss Basic Linux Commands. In the previous article, we discussed how to install Installing Guest Additions for Oracle Linux and how to create a shared folder.

Basic Linux Commands

Now we are going to discuss the basic Linux commands. These Linux commands are to the people who are not aware of Linux commands and need to learn oracle. There are a few commands which are most commonly used in our day-to-day life. In the previous session, we have seen terminal. The terminal is an application that is mostly referred to as a command line interface to control a Linux computer.

Below is the terminal picture. We will understand the meaning of [jaya@oracletest ~]$ in detail. Jaya -> username that you have connected and oracletest is the Linux machine name. The symbol ‘~’ is called Tilde which is referred to as the default directory for the user.

Basic Linux Commands

Now we will start with the basic command pwd. The full form of pwd is the present working directory. So, enter pwd and press enter. We got the output as /home/jaya.

Basic Linux Commands

Now for your verification, you can go to Files in Linux. Click on Activity and open files from there. Click on Other locations. After clicking you can see computer (means own Linux computer storage). Click on the computer. This is the base location. Go to home->jaya. Now the list of folders or files that you can see in the folder is the same files present in the terminal (i.e) we are in the same folder in the terminal and in the files application as well.

This is the interface for the files in Linux. The computer is the storage where all the files of Linux are present. The shared folder is the folder shared between the Linux machine and our computer.

Basic Linux Commands

Below is the list of files present in the home->jaya folder.

Basic Linux Commands

We want to list these files in the terminal we will use the command “ls” in the terminal as below.

Basic Linux Commands

Now, suppose if I need to go to the Desktop folder then simply cd Desktop (cd – change directory) and then press enter. You will be in the Desktop folder.

Basic Linux Commands

This indicates that user jaya connected to machine oracletest is in the Desktop folder. Now, let us create a folder name jaya in the Desktop folder.

Command: mkdir jaya (mkdir-make directory).

Command: mkdir jaya (mkdir-make directory)

Let us understand how to create a text file in Desktop or any other folder. Touch command just creates a file in Linux. There will not be any data or lines present in the file. Command: touch abc.txt

Command: mkdir jaya (mkdir-make directory)

We have two files on the Desktop. Jaya is a folder. Abc.txt is a text file. From the color itself, you can see that the Jaya folder is in blue color.

Let us understand about echo. Echo is a command that is used to display the output to the terminal. This can be used in many other different ways.

Example:

Basic Linux Commands

Let us create another text file named xyz.txt using the touch command (touch xyz.txt). Now the file has been created. We need to edit this xyz.txt file. We will use vi editors. VI is the default text editor. We will use vi xyz.txt. This Vi editor will take you to another empty page where you can enter your text.

Basic Linux Commands

To add data in the text file in vi editors we need to press the ESC button and ‘A’ so the Vi command interface will be changed to insert as you can see below. So, now you can enter any text or any number.

Basic Linux Commands

So, after entering the data we need to save the text file. We will use the same ESC button Shift button+ ‘:’ and wq (write and quit). There is another option (q!) quit and don’t save. So, we have created two files and a folder.

Basic Linux Commands

What if we need to see what are all the contents present in the file? There is a command to display all the data present in the file. Command: cat xyz.txt (Cat is referred to as concatenate which allows you to view the content of the file).

Basic Linux Commands

So, if we need to learn more about the cat command or any other commands present in Linux. There is an inbuilt manual for Linux. The name itself is manual we will use the

Command man.

Command man

For example, if we need to know about the cat command then we will be writing as man cat and press enter.

Command man

Now after entering the man cat, we can see all the details of the cat. The Generic command would be cat [option] [file]. The options are of various types. We will take an example from above. Let’s take ‘-n’. So, in the description, it shows the number of all the output lines. To exit from the manual just press q. No need to go with escape and shifts.

Let’s try the example that we have selected. Cat -n xyz.txt. It will give you the output content and also shows the line number.

Command man

We can use a manual for learning about the commands and learning new commands in Linux. So, let’s have some more fun by learning how to remove the file in Linux. So, the command to remove the file is rm file_name. rm command just deletes the files.

Command: rm xyz.txt

Basic Linux Commands

This will not give you any output saying the file is deleted. You can check the list of files after deleting them using the “ls” command. We understood how to remove a file. Let’s try to learn how to remove a folder. Before that let’s create a folder and then delete the folder. We are creating a folder with the name ‘newdirectory’—mkdir newdirectory.

Basic Linux Commands

The folder is created in the desktop folder. Let’s try to remove the folder. Let’s try to remove the directory through the rm command.

Command: rm newdirectory.

Command: rm newdirectory

We got an error because it is a directory. So, we cannot remove a directory with the only rm command. We need to add some other options to remove a directory.

Command: rm -r newdirectory (-r indicates recursive means remove all the files inside the directory)

Command: rm newdirectory

So now the terminal is full of commands.

Command: rm newdirectory

We will remove all the commands that we have worked on till now with a single command ‘clear’

Basic Linux Commands

The clear command will make the terminal screen empty. There will not be any data loss but the screen will clean.

Basic Linux Commands

Now let’s see the list of files present in the folder. We can see the list of files with ls and there are multiple options for this.

Command: ls -l

Command: ls -l

Here is the output. Now we are going to explain each and every component in this output.

Basic Linux Commands

Permissions:

The first three letters are the permission of the user owner. The user owner Jaya can rwx(read, write, execute). The next three-digit is the permission of the group owner. It has also rwx(read, write, execute). So, the group contains all the permissions. The users present in the group let’s take 10 users in the group who have all the permissions to the file. The last three digits in the permissions ‘r-x’. this is the permission for anyone i.e for any other users present inside the Linux.

Jaya is a folder name. How can we determine it as a folder? The last time we discussed that the color of the file is blue. But there is another option to it. The first digit of the output indicates ‘d’ d means directory. So you can check for the file abc.txt the first digit is ‘-‘. So ‘-‘ indicates it as a file.

What is the difference between the group owner and the user owner?

What is the difference between the group owner and user owner?

The user owner is the owner of this directory or the file.

Example: We have 9 users and a file called abc.txt. We need to provide read and write access to all the users (user1 to user9). The hardest way is to provide access individually to all the users. This will consume a lot of time and a lot of effort.

Let’s assume that all 9 users are working in an admin group. So, the permission of the people who are working in the same group will be the same. Let’s assign all the users to a single group called the Admin group. So, we can easily assign read and write access to the admin group.

The ownership of a user will be limited to a particular user and a particular file. But the ownership of the group will evolve to multiple users and multiple files under the assigned group.

Previously we have seen how to go to another directory but now let’s see how we can get back to the same directory(folder=directory)

. indicates the current directory.
.. indicates the previous directory.
To stay in the same folder we use “cd .”
To go back to the previous folder we use “cd ..”

Basic Linux Commands

Now I am going back to the Desktop folder because that is where the files are located that we are currently working on.

Let us understand how to copy the files in Linux. Generally, in windows, we select a file right click it, and copy the file. But in Linux, there is a command named cp(copy). Using this command, we can copy the files. Let’s take the abc.txt file from Desktop and copy the file to another file.

Command: cp abc.txt new.txt

Command: cp abc.txt new.txt

Move: Let’s have some more fun with these files. You may have listened to the word move. Let’s learn here more about the move. For example, let us move the newly created file (new.txt) to the folder jaya.

Command: mv new.txt jaya/

Command: mv new.txt jaya/

Whenever you are moving a file to the directory make sure to enter the forward slash(/).

Command: mv new.txt jaya/

So now the file is present inside the jaya folder, right? Let’s take the file back to the Desktop folder.

Command: mv Jaya/new.txt (move the file new.txt present in the jaya folder to the current directory) The current directory is Desktop.

With the move command, we can rename the files as well. Let’s take the file new.txt and try to rename the file to newfile.txt

Command: mv new.txt newfile.txt

Command: mv new.txt newfile.txt

Let us learn about creating a new user. For creating a new user, we need to connect as a root because the root has all the permissions of creating the user. Jaya user has administrative permissions but cannot create a user. Let’s go to the home directory for the root user (cd ~) using Tilde.

Command: mv new.txt newfile.txt

Let’s create a new user in Linux called happy. Command: useradd happy

Command: mv new.txt newfile.txt

Let’s assign a password for the user happy that we have created. Command: passwd happy

Basic Linux Commands

Now we have created a new user. Let us see where the information of the user is stored about the user in Linux.

Command: vi /etc/passwd.

Command: vi /etc/passwd

Here we can find all the users. These users are present in Linux for specific operations. If you go down to the bottom of the file (using the down arrow) you can be able to see the details of the user happy.

Command: vi /etc/passwd

Exit now from the file using the ESC button and Shift + ‘:’ q! (Quit and don’t save)

Command: vi /etc/passwd

Groups in Linux:

Let’s move a little further and know some information about the user that we have created. To find the information about the user below is the command. Here uid indicates userid. Gid indicates group id. Groups indicate all the groups that the user has been part of.

Command: id happy.

Groups in Linux

Whenever you create a user a group is created by default to the user. Let’s us add a new group and assign the user happy to the new group.

Command: groupadd hr

Command: groupadd hr

Now we have a group called hr and assign the user happy to the group hr.

Command: usermod -a -G hr happy.

Command: usermod -a -G hr happy

We have seen a similar type of command during shared folders. Let’s explain the command usermod- User modification, -a indicates add -G indicates the group to add hr is the group and happy is the user. (Link to Shared folder doc). Now let’s check the details of the user happy.

Command: id happy

Command: id happy

The user happy is now part of the group hr. So, if we grant any group access the user will get all the benefits of the group. There is a file where you can find information for all the groups present inside Linux.

Command: vi /etc/group.

Go to the bottom using the down arrow. The list you are seeing on the screen are some of the other users present inside the Linux for various purposes and programs.

Basic Linux Commands

Here you can see the details of the group hr. Exit now from the file using the ESC button and Shift + ‘:’ q! (Quit and don’t save). We have a shared folder created previously. Previously while accessing the shared folder, we have added a group vboxsf to the user jaya. Now let’s do the same thing and provide access to the user happy. To go to previous commands, you can press the upper arrow. By giving the upper arrow you can navigate to previous commands.

Command: usermod -a -G vboxsf happy

Command: usermod -a -G vboxsf happy

Any user who needs access to the shared folder needs to be inside the group called vboxsf. Let’s see the details of the user.

Command: usermod -a -G vboxsf happy

Logout from the user jaya and try to login from the user using the below steps.

Command: usermod -a -G vboxsf happy

You will get the login page below. Just log in with the user that we have created.

Command: usermod -a -G vboxsf happy

Select the happy user and log in with the password that you have provided for the user. After logging into the happy user. Go to my files and check for the shared folder. You will be able to access the shared folder now.

Basic Linux Commands

So, we can be able to access the shared folder through the user happy. This is the basic session of the Linux commands. We will be discussing more when we are installing the oracle database. There will be more and more commands but this is just a brief introduction of the Linux commands and how we can use them and where we can use them.

In the next article, I am going to discuss the Prerequisites Required for Installing Oracle Database. Here, in this article, I try to explain Basic Linux Commands and I hope you enjoy this Basic Linux Commands article.

Leave a Reply

Your email address will not be published. Required fields are marked *