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

These are the command lines that are running on a terminal

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:

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:

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:

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โ€œ

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โ€

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)

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:

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:

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:

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:

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:

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"

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โ€ฆ

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โ€ฆ

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 Artificial Intelligence Courses for 2024 Top 10 Best Cybersecurity Courses for computer enthusiast Top 8 Btech colleges in Mumbai for 2024 Top 9 Best Mtech colleges in Bangalore for 2024 7 Best High paying Cyber Security Jobs in India
Top 7 Artificial Intelligence Courses for 2024 Top 10 Best Cybersecurity Courses for computer enthusiast Top 8 Btech colleges in Mumbai for 2024 Top 9 Best Mtech colleges in Bangalore for 2024