×

Search anything:

11 Basic Linux commands

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

Are you a beginner who just has installed Linux in your system but have no idea how Linux works? Are you a developer who is trying to learn Linux? Or is this the first time you are seeing Linux and have no idea how Linux works? Then you have come to the right place to learn just enough Linux commands that will help you get started with Linux and its working.

Linux is an open-source operating system, which means you need not pay anything to use Linux or buy any license to work on Linux. It's free of cost operating system that you can use for your daily works, software development purposes, or as a server operating system to handle users requests.

This article will help you learn just enough Linux that will help you get familiar with its working and environment. You might have heard that Linux is controlled and operated using only commands, but that is not entirely true.

Linux has an excellent graphical user interface that can be easily operated using a keyboard and mouse also. You can control and change its functionality with easy clicks and buttons.

ubuntu-desktop

Then why do people use commands to operate Linux if it has a graphical interface like windows? When we use Linux as a server to host websites or projects, we generally get a virtual private server at a remote location.

To operate the server remotely, we only get the Linux terminal, not the server's graphical desktop, and commands are the only option to control our server.

Therefore, it's good if you learn some basic commands to run and operate Linux. It will help you get an idea of how the Linux terminal works, and also, you can control your whole system just by typing some commands in one place instead of searching for options or buttons in the GUI version.

linux-terminal

Here are some of the most commonly used and basic Linux commands which everyone should know to get started working on Linux. These are enough to develop familiarity with the operating system and perform all basic functions.

Note: a dollar sign ($) signifies where to begin writing your commands on the terminal. You need to press ENTER key after you type any command to execute it.

The 11 basic Linux commands are:

  • pwd
  • touch
  • cat
  • mkdir
  • cd
  • ls
  • mv
  • cp
  • rm
  • clear
  • using vi editor

1. pwd

This command is used to print the present working directory or the current directory you are working in.
pwd

tejan@DESKTOP:~$ pwd
/Home

2. touch

Touch command is used to create an empty file of any type or format.
touch new_file.txt

tejan@DESKTOP:~$ touch newfile.txt

Note: you need to write a file name and its format or extension with a dot(.) to create a particular type of file.

3. cat

cat command is used to display the content of any file on the terminal. All the content will be displayed on the terminal window only below your entered command. No new window is opened to reveal all your file content.
cat file_name.txt

tejan@DESKTOP:~$ cat newfile.txt
Hello World!

4. mkdir

This command is used to make a folder/directory in the current location.
mkdir folder_name

tejan@DESKTOP:~$ mkdir newfolder

5. cd

cd is used to move from one folder/directory to another.
cd folder_name

tejan@DESKTOP:~$ cd newfolder
tejan@DESKTOP:/newfolder $

You can use this command to move to a folder present in the current directory. The folder you want to move into must be present, then only you can move into it; otherwise, it will give you an error.

To get back to the previous folder, you can use the command:
cd ..

tejan@DESKTOP:~$ cd ..

It will move backward to the previous directory.

If you want to get back directly to the home directory, then in that case, you just type:
cd

tejan@DESKTOP:~$ cd

6. ls

This command is used to list all the files present in the current directory.
ls

tejan@DESKTOP:~$ ls
Home newfolder

7. mv

This command is used to move a file/directory to another folder present in the same directory.
mv file_to_move destination_directory

tejan@DESKTOP:~$ mv newfile.txt newfolder 

To move a directory to another directory
mv directory_to_move destination_directory

tejan@DESKTOP:~$ mv newfolder myfolder

mv command can also be used to rename a file/directory

To rename a file, use
mv old_file_name new_file_name

tejan@DESKTOP:~$ mv newfile.txt myfile.txt

To rename a directory, use
mv old_directory_name new_directory_name

tejan@DESKTOP:~$ mv myfolder tejan_folder

8. cp

This command is used to copy the content of a file to a new file.
cp file_to_copy new_file_name

tejan@DESKTOP:~$ cp myfile.txt newfile.txt

This command is used to copy the content of a folder to a new folder.
cp -r folder_to_copy new_folder_name

tejan@DESKTOP:~$ cp -r newfolder tejan_folder

note: if folder is present then it will copy the files or folders into that folder. If folder is not present then it will create a file or folder you specified in commands.

9. rm

This command is used to remove a file and folder from the current directory.

To remove a file, use:
rm file_To_remove

tejan@DESKTOP:~$ rm newfile.txt

To remove a directory, use:
rm -r directory_to_remove

tejan@DESKTOP:~$ rm -r myfolder

10. clear

Clear command is used to clear the terminal window. Use this to clear all your work and commands from the terminal when you feel you need to clear all the mess you created by firing many commands and starting fresh.
clear

tejan@DESKTOP:~$ clear

Note: you cannot undo the clear command. So, make sure you review all your work and information before clearing the terminal.

11. using vi editor

A vi editor is a default text editor that comes with all linux versions and distributions. So, we also need to learn how to edit files using vi editor.

To open a file in vi editor, just type
vi file_name

tejan@DESKTOP:~$ vi file.txt

output will look like this:

Hello World!
~
~
~

where ~ sign shows a new line. The file opens in the same terminal. You can make changes as you want. You need to press ENTER KEY to go to the new line. ARROW KEYS will help you navigate to different lines.

To edit the file, you need to press "I" KEY on keyboard to enter INSERT MODE. This will let to type in the file make changes.

Hello World!
Hey! there
~
~
-- INSERT --

To save changes, First exit the insert mode(edit file mode) by pressing ESC KEY on keyboard. It will automatically disable editing. Now, you will see your cursor blinking at end to the terminal.

Here you will type a small command :wq to save changes and press ENTER KEY to save file

Hello World!
Hey! there
~
~
:wq

Note: The mouse does not work inside the vi editor. All functions are performed using keyboard key only.

*Thanks for reading, I hope you learned something new.

11 Basic Linux commands
Share this