Habilelabs-Logo
Blog

13 Basic Linux Commands for Beginners to Know

August 4th, 2017 . 6 minutes read
Blog featured image

There are thousands of Linux commands. In this article, we will discuss 13 Basic Linux Commands for Beginners need to know.

Basic Linux Commands Beginners Should Know

Let’s discuss 13 commands one by one:

1. pwd command:

pwd is used to know that in which directory, we are working i.e. the full path of the current directory.

2. mkdir command:

It is used to create a directory.

Syntax:

e.g.-

3. cd Command:

It is used to change the directory path.
Syntax:

e.g.-

Note: cd command is also used to go one step back

4. ctrl-L command:

It is used to clean/clear the terminal.

5. touch command:

touch is a multipurpose command, first use is to create empty single/multiple files(s).
Syntax :

e.g.-

secondly, it is used to change file access and modification time, for this touch command has 5 options.

5.1: -a

It used to change the access time of the file.
e.g. –

The following command sets the current time and date in a file. If the demo file does not exist, it will create the new empty file with the name.

5.2: -c

Do not create a specified file if it does not exist.
e.g.-

For e.g., this command will not create a file called demo if it does not exists.

5.3: -m

Changes the modification time of file
e.g.-

5.4: -r

Used to use the corresponding time of the second file instead of current time.
e.g.-

In this example, file “demo” will use the timestamp of file “test” instead of the current time stamp.

5.5: -t

Used to create a file with specified time rather than current time
e.g.-

Field Explanation:

touch command with -t option will give the demo file timestamp of 10:30:40 a.m. on August 01, 2017.

(time Use the specified time instead of the current time. time will be a decimal number of the form:

[CC]YY]MMDDhhmm [.SS]

  • MM – The month of the year [01-12].
  • DD – The day of the month [01-31].
  • hh – The hour of the day [00-23].
  • mm – The minute of the hour [00-59].
  • CC – The first two digits of the year.
  • YY – The second two digits of the year.
  • SS – The second of the minute [00-61].)

6. -ls command:

It used to show the list of file.
Syntax :

Note: If you want comma separation between file names, then use ls -m instead of ls -a.

ls -1: to display one file per line
Syntax :

ls -l: to display total information about files/directories
Syntax :

Field Explanation
1) The first character displays the type of file.

  • “-” Normal file
  • “d” Directory
  • “l” link file

The next 9 lines specify the permissions. Each group of 3 lines corresponds to permissions. So, the first three lines stand for user permissions, the next 3 for the group, and further next 3 are for other permissions. Here ‘r’ stands for reading, ‘w’ for write, and ‘x’ for execute.
2) The second field specifies the number of links for that file.
3) The third field specifies the owner of the file. Here the owner is “user”.
4) The fourth field specifies the group of the file. Here, group “nitisha” belongs to the file.
5) The fifth field specifies the size of the file. Here file size for the file a.txt is 12 bytes.
6) The sixth field specifies the last modified date and time of the file. Here for file a.txt is July 1 23:11
7) Seventh Field specifies the name of the file/directory itself.

ls -a : to show hidden files
ls -t : to open last edited file

7. -cat command:

It used to display the content of the file.
Syntax :

e.g.,

Note: It will show the content of file “demo”
It is also used to display content of more than one file
Syntax :

e.g.,

cat command is also used to redirect output to another file, but with ‘>’ operator

We can also redirect the stdout to a new file with ‘>’ operator

Now if we check the content in demo.txt with

then, we’ll get the result –

It is also used to append some content in the file with ‘>>’ operator

7.1: -cat -n used to display content of the file with Line numbers

To find the exact number of filled lines we use ‘-b’ instead of ‘-n’.

7.2: cat -ns used to print repeated empty lines only once
7.3: cat -ne used to display end of every line

Syntax :

8. -man command:

It is used to get details of any command.
Syntax:

9. -whatis command:

It is used to get short details of any command
Syntax :

10. -whoami command:

it is used to know the current user name.

11. -rm command:

this command is used to remove the file.
Syntax :

11.1: rm -r : to remove directory

11.2: rm -f: to remove file forcefully

11.3: rm-rf : to remove directory forcefully

12. -cp command:

It is used to copy the content of one file to another.
Syntax :

13. -mv command:

used to move(cut-paste) the content of one file to another
Syntax :

This command is also used to rename the file
Syntax :

So if you are a beginner then you can use these “Basic Linux Commands for Beginners”.
These commands will help you out to start with Linux operating system. Visit this 100 Linux command tutorial for more info.

Habilelas is best web and mobile based development company. If you have anything to build, discuss with us.

If you have any queries then ask in the comment section.

Hope you found this post helpful, so don’t forget to share with friends on Facebook.

Author: nitisha
Share: