Basic Command lines of Linux Operating System | Basic Linux Commands

As, In our previous article we discussed the “Linux operating system”, In that article, I have told you about some basic Linux command names which are most important for using Linux. If you haven’t read that article yet, go ahead and read it.

To use the Linux Operating System, you need to understand some basic Linux commands which are very important for beginners in linux.

So, today we are going to discuss some basics commands which is important for a new Linux user.

So let’s get started…

Introduction

Linux is a Unix-based operating system with an open-source software that is freely available for use. To use this operating system you need to understand the terminal. This is because more than half of the work in Linux OS can be done only with the terminal. So you need to learn it, Now “What is Terminal”?.

The terminal is just a window which is open in a rectangular shape on the desktop in our system, In that terminal, we can run all those commands which we want to run on it like “whoami command”, “date command”, timedatectl Command” etc to get the output from the terminal.

This is the terminal of the Linux Operating System that I am using it. And this terminal is running on a UBUNTU OS

terminal min

These are the command lines that are running on a terminal

whoami
date min
timedatectl min

There are many other commands which we discuss in further…

So, let’s get started…

Basic Linux Commands

1) pwd Command

“pwd” stands for Present Working Directory, this command is used to display your directory location which you are currently in.

Let’s write the “pwd” command in the terminal and see how the terminal gives us an output.

Command:

$ pwd

Terminal Output:

pwd

As you can see the terminal shows my current directory location where I am currently in (/home/ankushk)

2) ls Command

“ls” is a Linux shell command which is used to list all the files and directories in our file system. When you write this command in your terminal then the terminal shows your all the files and directory from your current directory.

In a terminal, the home directory is selected by default, which means if your write ls command in the terminal then it’ll show your all the files and directories from your home directory

So, let’s check the “ls” command and see what it gives us an output

Command:

$ ls

Terminal Output:

ls command

After writing this command in the terminal, it shows all the files and directories from my home directory.

As you have seen in the terminal, there are many files and directories are there. What you seeing in the blue color text in the terminal they all are my “directories/folder” (Desktop, Documents, Downloads, Music, Pictures, Public, sanp, Templates, ubuntu, Vedios, ‘vs-code’) and in the white color text, they all are my “files”(ankush.txt, Bitcoin.txt, linux.txt, ‘ls command.txt’, signal-desktop-keyring.gpg).

3) cd Command

“cd” command stands for change directory which is used to change the current working directory.

This command helps us to enter in any directories by changing our current directories. Example: If my current directory is (/home/ankusk) and I want to enter in other directories like”Downloads”, then we have to write this command “cd Downloads” in the terminal then we can easily enter in the Downloads directory (/home/ankushk/Downloads)

So, let’s try it in the terminal…

Command:

$ cd "your directory name"

Terminal Output:

cd command min

As you can see I am in the Download directory (/home/ankushk/Downloads) by using the cd command

4) cat Command

“cat” command stands for”concatenate” which is one of the most frequently used command in the Linux System. This command is used for creating new files, Displaying and combining the text files.

i) To create a new text file in the terminal, So we have to write “cat> yourfilename.txt” in the terminal. So, let’s try it out…

Command:

$ cat> "yourfilename".txt

So, I am going to create newfile.txt

Terminal Output:

Creating “newfile.txt

Untitled design 4 min

As you can see the newfile.txt is created.

ii) Now, let see how to display any text file in the terminal. To do this we have to write a command “cat yourfilename”. Let’s try it out…

Command:

$ cd "yourfilename"

So, I am going to display my file. My file name is “linux.txt”

Terminal Output:

Displaying “linux.txt”

linux txt file min

As, you can see the terminal displays my text file “linux.txt”.

iii) Now, let’s see how to combine the text file in the terminal. To do this we have write a command “cat file1.txt secondfile.txt thirdfile.txt”. Let’s try it out…

I have three files whose name is “ankush.txt, Bitcoin.txt, and linux.txt”. So, I am going to combine these three files in the terminal. Let’s see…

Command:

~$cat "yourfile1.txt" "yourfile2.txt" "yourfile3.txt"

Terminal Output:

Combining three text files (ankush.txt, Bitcoin.txt, and linux.txt)

cat combine min 1

As you can see the content of my three files “ankush.txt, Bitcoin.txt and linux.txt are combine together.

5) mkdir Command

“mkdir” stands for make directory, This command is used to make a new directory/folder.

To create a new directory we have to write a command “mkdir newdirectoryname” in the terminal. let’s try it out…

Command:

$ mkdir "directoryname"

I am going to make a new directory with the name of “computerstudypoint”. let’s see…

Terminal Output:

Untitled design 1 min

As you can see there is a new directory with the name of “computerstudypoint” is created by using mkdir command.

6) rmdir directory

“rmdir” Command stands for remove directory, This command is used for removing the directory.

To remove any directory from the file system we have to write a command “rmdir directoryname” in the terminal. Let’s try it out..

Command:

$ rmdir "directoryname"

I am going to remove the computerstudypoint directory which was created by using mkdir but now I am going to remove it by using rmdir command. let’s see

Terminal Output:

Untitled design 2 min

As you can see the computerstudypoint directory has been removed.

7) cp Command

“cp” command stands for Copy, This command is used to copy any files and directories to another destination. So, let’s try it out…

Command:

$ cp "filename" "directoryname"

I am going to copy the “linux.txt” file and paste it into the “snap” folder. To do this we have to write “cp linux.txt snap” command in the terminal. let’s see…

Terminal Output:

Untitled design 3 min

As you can see by using “cp linux.txt snap” command in the terminal, It pasted the linux.txt file into the snap directory.

8) mv Command

“mv” command stands for move, This command is used for moving files and directories to another location of a file system. So, let’s try this command…

Command:

$ mv "filename" "directoryname"

I am going to move the “newfile.txt” file to the Desktop directory. To do this we have to write “mv newfile.txt Desktop” command in the terminal. let’s see…

Terminal Output:

Untitled design 6 min

As, you can see that the “newfile.txt” file is moved to Desktop directory from the home directory.

9) rm Command

“rm” command stands for remove. This command is used to remove the files and directory from the file system in Linux.

rm command is like a rmdir command but there have some differences:

The “rmdir’ command can only remove empty directories, it won’t work in non-empty directories. On the other hand, the “rm” command can remove any files of a file system and as well as non-empty directories. But it won’t work with an empty directory (for empty directories there is a specific command called “rmdir”)

Command:

$ rm "your-filename"

So let’s try this command by deleting some files. So, I am going to delete newfile.txt from my home directory. To remove this file we have to write “rm newfile.txt” in the terminal. Let’s see…

Terminal Output:

Untitled design 5 min

As you can see the newfile.txt has been removed.

10) head command

The “head” command is used to print the lines from the files. This command is similar to the cat command Because the cat command help us for displaying the full content of a file but on the other hand the head command also does to display the content of a file but the main difference is that the head command does not show us the full content of the file. It prints the line only from the beginning of the content. By default the head command prints the first 10 lines or a paragraph from the content of a file.

Let’s try this command…

Command:

$ head "your-filename"

First, I’m going to create a new file with the name of “head.txt” and in that file, I’ll write 15 lines of content in it. let’s do it…

For Creating new file use this command in the terminal.

$ cat> "your-filename"
Untitled design 7 min

As you can see the head.txt file has been created with 15 lines of a content. So, now let’s use the head command in the terminal…

head command min

Like I said the by default head command shows only the first 10 lines of the content, As you can see in the terminal. If you use the cat command then it’ll show your full content from the file.

11) tail Command

“tail” command is the opposite of the head command, In the head command, it print the files of the beginning of the content but in the tail command, it prints the last lines of the content. By default, it prints the last 10 lines of the content. So, let’s try this command…

Command:

$ tail "your-filename"

I am going to use this command to print my head.txt file. So, I am gonna write “tail head.txt” in the terminal. let’s see…

tail command min

As you can the tail command prints the last 10 lines from the “head.txt” file.

2 thoughts on “Basic Command lines of Linux Operating System | Basic Linux Commands”

  1. The content you provide is very good and easy to understand. I really like your work and appreciate you to continue this.
    Computer study point is very helpful for me that I cam prepare for my exam.
    ❤❤❤

    Reply
    • Glad to see, this article was helpful to you. 😊

      I am always here for helping you in computer related article. So, if have any specific topic which you want to learn then tell me in the comment section. I will try to provide that article for you.

      Reply

Leave a Comment

Top 7 Computer Science Engineering Courses with 100% Placement Record