Linux

Basic Linux Commands For Beginners: With Examples [Visual Guide]

Hello friend, and welcome to the Basic Linux Commands Tutorial For Beginners.

In this post, you are going to learn the fundamentals of Linux command line that will help you do get your hands wet in the Linux world.

With that said I’m also going to make sure not to overwhelm you with unnecessary information or any in-depth working of a command, but at the same time making your understanding clear.

I’ll be showing you the syntax of a command and giving an example with it so that you can try them on your own Linux machine and understand a command better.

This is a complete practical tutorial and you must implement these commands, in order to get hold of it properly.

You can either try these commands on your personal Linux machine or you can just go to linuxcontainers and you will be provided with a free Linux server session where you can practice these basic Linux commands.

So…

Without any further ado, Let’s do this…

Basic Linux Commands For Beginners With Examples:

What is Command?

A command is nothing but a set of instructions that are predefined for a specific word. In other words, a command is a program. It is a program that has been assigned specific a word.

What is Linux Terminal?

Basically, the terminal is a medium through which you can tell your Linux Operating System to perform a specific task.

The Linux Terminal is also referred to as Shell. You can control each and every aspect of your Linux Operating System from the Shell itself, which makes it a very powerful utility to have on any Linux-based Operating System.

Did You Know?
Linux Operating System is case sensitive i.e. lower case alphabets are different from uppercase alphabets. For example, ABC is different from abc.

So keep this thing in mind while creating files and directories.

Basic Linux Commands With Examples:

First of all, open the run dialog box by pressing ALT+F2.

The run dialog box will be opened and then type gnome-terminal and hit enter.

linux commands basics

Your terminal will be opened. If not, then you can manually search for the terminal in your Linux distribution.

 

  • pwd

This command stands for print which directory, and this does exactly the same thing i.e. to print the name of the directory in which you are currently working in.

Just type pwd and hit Enter.

 

  • ls

The next command I’m going to tell you about is the ls command.

This command simply lists the files and directories inside your current working directory.

Now, Linux also offers us various options which are used with a command. These options are also known as switches.

So, let us take a look at the –l switch which is used with the ls command. The ls –l is used for listing the files with its details.

Type ls –l in the terminal and hit enter.

Now you can see that the output has returned some additional information about the files and directories.

 

  • cd

The cd command stands for change directory and it does exactly what its name suggests.

This command is used to navigate to a  different directory.

The syntax for cd is: cd <directory_name>

Example: cd Documents

 

  • touch

This command is generally used for updating the time stamp of a file when it was last modified.

But we can also use this command for creating a new file. Just type touch <filename> and hit Enter.

Example: touch newfile

 

  • nano

The nano is a simple text editor in the Linux based Operating Systems, and it comes preinstalled with almost all of the Linux distributions.

The nano is very simple to use and is very beginner friendly.

To launch nano editor just type: nano <filename>

Example: nano newfile

You will be presented with a new screen which looks like this:

Notice, that nano editor also displays some shortcuts at the bottom. The caret (^) symbol stands for CTRL.

When you are done editing your file, Just hit CTRL X.

Then it will ask, whether to save your file or not. Hit y for yes or n for no.

At last, it will show you the file name, you can either modify it or simply hit Enter to save the file with the existing name.

 

  • cat

The cat command is used to display content of a text file.

The syntax for cat command is: cat <filename>

Example: cat newfile

 

  • mkdir

At this point, you know how to create a new file, then display the content of that file and how to edit that file.

Now let’s create a folder/directory where you can store all your files or subdirectories.

The mkdir command which stands for make directory is used for creating new directories.

For creating a directory use this command: mkdir <directory_name>

Example: mkdir new

Let us discuss a very useful switch of the mkdir command i.e., -p

So suppose, you want to create a new directory inside of another new directory and so on. You can use the mkdir command with –p switch to handle your situation.

Example: mkdir –p new/new1

If you don’t use the –p switch you can’t create a new directory inside a new directory.

Take a note on how I used the (last) ls command with the directory name for displaying content inside it.

 

  • rmdir

So, now you know how to create a directory. Let’s take a look at the command which helps us to remove a directory.

The rmdir command which stands for remove directory is used for deleting/removing directories.

The syntax for rmdir command is: rmdir <directory_name>

Example: rmdir new

Just make sure that the directory you are removing has no content inside it. In other words, you can only delete an empty directory using the rmdir command.

To know how to delete a directory having content inside it, just keep reading.

 

  • rm

The rm command stands for remove. The remove command is generally used to remove/delete files.

We can use the switch –r with the rm command to remove a directory which is not empty.

The syntax of rm command is: rm <filename>

Example: rm newfile

To remove a directory having content inside it just use –r switch with the rm command.

Example: rm –r new

 

  • mv

Now let’s look at some other basic operations which we can perform using the Terminal/Shell.

The mv command. This stands for the move. The mv command helps you to move one file from one location/directory to another location/directory.

The syntax for mv command is: mv <source> <destination>

The source is the file or directory which you want to move and the destination is the location where you want to move your file of the directory.

Example: mv new.txt new

You can have multiple source files separated with space but a single destination directory.

Example: mv new1 new2 new3 dir

Here, new1 new2 and new3 are the source files and dir is the destination.

 

  • cp

As you might have already guessed, this command stands for copy and helps us to copy files from one location to another location.

The syntax for cp command is: cp <source> <destination>

Example: cp newfile new

 

Some Tips!
  • There is a lot more, that you can do with these commands by using different switches available for each command.
  • You can always look for switches available for a specific command by using the man command. Like: man cd or man ls and so on.
  • Use the Tab button for auto-completion.
  • Suppose you are typing this command in the home directory: cd Doc after you hit Tab button this will be autocompleted to cd Documents.

Rundown: Basic Linux Commands For Beginners With Examples

So, this was all about basic Linux commands for beginners. Now you know how to perform basic tasks using Linux shell.

By knowing this basic Linux commands you have laid down the foundation of becoming an expert in Linux.

But in order to become a Linux power user, you must have a solid understanding of the Linux Shell. And I’m going to walk you through your journey, from a basic linux commands user to a Linux power user.

The Linux shell is much more powerful than just performing these simple tasks. We will be covering more about this in the Linux commands for  Intermediate and the Linux commands for Advanced users tutorial.

So stay tuned and subscribe to get the updates notifications. And if you like this post, please do share it with your friends and do comment if you have any problem, query or a suggestion.

Leave a Reply

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